Changeset 1180

Show
Ignore:
Timestamp:
2008-09-22 16:51:56 (4 months ago)
Author:
gaspard
Message:

commit 8b187aa00e9d71e9ae8c329effd5468717938c6d
Author: Gaspard Bucher <gaspard@teti.ch>

Fixed date usage in pseudo sql, fixed empty mode on template state:resolved.
All tests are passing. Reached 1'300 tests !

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/application.rb

    r1179 r1180  
    804804      if thedate.kind_of?(Time) 
    805805        adate = tz.utc_to_local(thedate) 
     806      elsif thedate.kind_of?(String) 
     807        begin 
     808          adate = Date.parse(thedate) 
     809        rescue 
     810          return "<span class='parser_error'>invalid date #{thedate.inspect}</span>" 
     811        end 
    806812      else 
    807813        adate = thedate 
  • trunk/app/models/template.rb

    r1031 r1180  
    2929   
    3030  def filter_attributes(attributes) 
    31     ['c_klass','c_mode','c_format'].each do |sym| 
    32       attributes.delete(sym) if attributes[sym] == '' 
    33     end 
    3431    content    = version.content 
    3532    new_name   = attributes['name'] || (new_record? ? attributes['v_title'] : nil) # only set name from version title on creation 
     
    10097      opts[:klass ]  ||= version.content.klass 
    10198      format = opts[:format] == 'html' ? '' : "-#{opts[:format]}" 
    102       mode   = (opts[:mode] || format != '') ? "-#{opts[:mode]}" : ''  
     99      mode   = (!opts[:mode].blank? || format != '') ? "-#{opts[:mode]}" : ''  
    103100      "#{opts[:klass]}#{mode}#{format}" 
    104101    end 
  • trunk/lib/parser/lib/rules/zena.rb

    r1179 r1180  
    16331633      else 
    16341634        if select =~ /^\d{4}-\d{1,2}-\d{1,2}$/ 
    1635           expand_with(:date=>select) 
    1636         elsif date = find_stored(Date, select) 
    16371635          begin 
    16381636            d = Date.parse(select) 
    1639             expand_with(:date=>select
     1637            expand_with(:date=>select.inspect
    16401638          rescue 
    16411639            parser_error("invalid date '#{select}' should be 'YYYY-MM-DD'") 
     1640          end 
     1641        elsif date = find_stored(Date, select) 
     1642          if date[0..0] == '"' 
     1643            begin 
     1644              d = Date.parse(date[1..-2]) 
     1645              expand_with(:date=>date) 
     1646            rescue 
     1647              parser_error("invalid date #{select} (#{date}) should be 'YYYY-MM-DD'") 
     1648            end 
     1649          else 
     1650            expand_with(:date=>select) 
    16421651          end 
    16431652        elsif select =~ /^\[(.*)\]$/ 
     
    32063215        if date_cond == 'today' || ref_date == 'today' 
    32073216          ref_date = 'now()' 
    3208         elsif ref_date =~ /^\d{4}-\d{1,2}-\d{1,2}( \d{1,2}:\d{1,2}(:\d{1,2})?)?$
    3209           ref_date = "'#{ref_date}'" 
     3217        elsif ref_date =~ /(\d{4}-\d{1,2}-\d{1,2}( \d{1,2}:\d{1,2}(:\d{1,2})?)?)
     3218          ref_date = "'#{$1}'" 
    32103219        else 
    32113220          ref_date = "'\#{#{ref_date}.strftime('%Y-%m-%d %H:%M:%S')}'" 
  • trunk/test/helpers/application_helper_test.rb

    r1130 r1180  
    317317   
    318318  def test_node_actions_wiki_public 
    319     @node = secure!(Node) { nodes(:wiki) }  
     319    Participation.connection.execute "UPDATE participations SET status = #{User::Status[:user]} WHERE site_id = #{sites_id(:zena)} AND user_id=#{users_id(:anon)}" 
     320    @node = secure!(Node) { nodes(:wiki) } 
    320321    assert @node.can_edit?, "Node can be edited by the public" 
    321322    res = node_actions(:actions=>:all) 
  • trunk/test/helpers/zena_parser/basic.yml

    r1179 r1180  
    10821082  src: "<r:show date='created_at' format='%a' lang='en'/>" 
    10831083  res: "Fri" 
     1084 
     1085date_context: 
     1086  src: "<r:date select='2008-03-02'><r:show date='current_date' format='%A %d.%m.%Y'/></r:date>" 
     1087  tem: "<%= format_date(\"2008-03-02\", \"%A %d.%m.%Y\") %>" 
     1088  res: "Sunday 02.03.2008" 
  • trunk/test/sites/zena/discussions.yml

    r1016 r1180  
    2222  inside:          yes 
    2323  lang:            fr 
     24 
     25private_discussion_on_myLife: 
     26  created_at:      2008-09-20 20:00 
     27  updated_at:      2008-09-20 20:00 
     28  node:            myLife 
     29  inside:          yes 
     30  lang:            fr 
  • trunk/test/unit/template_test.rb

    r1098 r1180  
    115115    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :name=>'Project-collab-xml.zafu')} 
    116116    assert_kind_of Template, doc 
    117     err doc 
    118117    assert !doc.new_record?, "Saved" 
    119118    assert doc.update_attributes(:name => "Page-super") 
     
    123122    assert_equal 'Page', doc.c_klass 
    124123    assert_equal 'Page-super', doc.name 
     124  end 
     125   
     126  def test_update_name_blank_mode 
     127    login(:tiger) 
     128    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :name=>'Project-collab-xml.zafu')} 
     129    assert_kind_of Template, doc 
     130    assert !doc.new_record?, "Saved" 
     131    assert doc.update_attributes(:name => "Page--xml", :v_title=> "Project-collab-xml") 
     132    assert_nil doc.c_mode 
     133    assert_equal 'xml', doc.c_format 
     134    assert_equal 'Page', doc.c_klass 
     135    assert_equal 'Page--xml', doc.name 
     136    assert_equal 'Page--xml', doc.v_title 
     137  end 
     138   
     139  def test_update_blank_mode 
     140    login(:tiger) 
     141    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :name=>'Project-collab-xml.zafu')} 
     142    assert_kind_of Template, doc 
     143    assert !doc.new_record?, "Saved" 
     144    assert_equal 'collab', doc.c_mode 
     145    assert doc.update_attributes(:c_mode => "", :name => "Project-collab-xml") 
     146    assert_nil doc.c_mode 
     147    assert_equal 'xml', doc.c_format 
     148    assert_equal 'Project', doc.c_klass 
     149    assert_equal 'Project--xml', doc.name 
     150    assert_equal 'Project--xml', doc.v_title 
    125151  end 
    126152 
     
    142168    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), :name=>'Project-collab')} 
    143169    assert_kind_of Template, doc 
    144     err doc 
    145170    assert !doc.new_record?, "Saved" 
    146171    assert_equal 'Project-collab', doc.name 
     
    198223   
    199224  def test_update_format_updates_name 
     225    login(:lion) 
    200226    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'c_mode' => '', 'c_klass' => 'Contact', 'name' => '', 'c_format' => 'vcard')} 
    201227    assert_kind_of Template, doc 
     
    215241   
    216242  def test_update_text 
     243    login(:lion) 
    217244    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'v_text'=>"hey", 'c_mode' => '', 'c_klass' => 'Contact', 'name' => '')} 
    218245    assert_kind_of Template, doc 
     
    223250   
    224251  def test_default_text 
     252    login(:lion) 
    225253    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'c_klass' => 'Contact', 'name' => '')} 
    226254    assert_kind_of Template, doc 
     
    230258   
    231259  def test_default_text_Node 
     260    login(:lion) 
    232261    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'c_klass' => 'Node', 'name' => '')} 
    233262    assert_kind_of Template, doc 
     
    237266   
    238267  def test_default_text_other_format 
     268    login(:lion) 
    239269    doc = secure!(Template) { Template.create(:parent_id=>nodes_id(:default), 'c_format' => 'vcard', 'c_klass' => 'Node', 'name' => '')} 
    240270    assert_kind_of Template, doc 
  • trunk/test/unit/user_test.rb

    r1016 r1180  
    227227    login(:tiger) 
    228228    ant = secure!(User) { users(:ant) } 
    229     assert_equal participations_id(:ant_in_zena), ant.site_participation[:id] 
     229    assert_equal participations_id(:ant), ant.site_participation[:id] 
    230230    assert_equal 50, ant.status 
    231231  end 
     
    259259     
    260260    # make lion an admin in ocean 
    261     Group.connection.execute "UPDATE participations SET status = 60 WHERE site_id = #{sites_id(:ocean)} AND user_id=#{users_id(:lion)}" 
     261    Participation.connection.execute "UPDATE participations SET status = #{User::Status[:admin]} WHERE site_id = #{sites_id(:ocean)} AND user_id=#{users_id(:lion)}" 
    262262     
    263263    login(:lion)