Changeset 484

Show
Ignore:
Timestamp:
2007-05-06 13:32:14 (2 years ago)
Author:
gaspard
Message:

[tests] units and helpers ok : 699 tests 2140 assertions !

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/helpers/application_helper.rb

    r481 r484  
    356356  # the format is used as the image class. Example : 
    357357  #   img_tag(@node, :mode=>'pv')  => <img src='/sites/test.host/data/jpg/20/bird_pv.jpg' height='80' width='80' alt='bird' class='pv'/> 
    358   def img_tag(obj, opts={}) 
     358  def img_tag(obj, options={}) 
    359359    return "" unless obj.kind_of?(Document) 
    360     mode    = opts[:mode] 
     360    opts    = options.dup 
     361     
     362    mode    = opts.delete(:mode) 
     363    klass   = opts.delete(:class) 
     364    alt     = opts.delete(:alt) 
     365    img_id  = opts.delete(:id) 
     366     
    361367    content = obj.v_content 
    362     ext     = content[:ext] 
     368    ext     = content.ext 
    363369    opts    = opts.merge(:format => ext) 
    364      
    365     alt       = opts[:alt] 
    366     img_id    = opts[:id] 
    367370     
    368371    src = width = height = img_class = nil 
     
    373376      src       = zen_path(obj, opts.merge(:mode => (mode == 'full' ? nil : mode))) 
    374377       
    375       img_class = opts[:class] || mode 
     378      img_class = klass || mode 
    376379      if mode == 'full' 
    377380        # full size (format = nil) 
     
    387390      alt   ||= "#{content.ext} document" 
    388391       
    389       img_class = opts[:class] || 'doc' 
     392      img_class = klass || 'doc' 
    390393      unless File.exist?("#{RAILS_ROOT}/public/images/ext/#{ext}.png") 
    391394        ext = 'other' 
     
    452455  def show_comments(opts={}) 
    453456    node = opts[:node] || @node 
    454     render_to_string(:partial=>'comment/list', :locals=>{:node=>node}) 
     457    render_to_string(:partial=>'comments/list', :locals=>{:node=>node}) 
    455458  end 
    456459   
  • trunk/app/models/skin.rb

    r455 r484  
    44  before_save :need_skin_name_update 
    55  after_save  :update_skin_name 
    6    
    7   def template_url_for_name(template_name, helper) 
    8     raise Exception.new('helper should not be nil!') unless (helper || ENV["RAILS_ENV"] == "test") 
    9     if template_name == 'any' 
    10       template = self 
    11       zafu_url = "/#{self[:name]}/any" 
    12     else 
    13       template = secure(Template) { Template.find(:first, :conditions=>["parent_id = ? AND name = ?", self[:id], template_name])} 
    14       zafu_url = "/#{self[:name]}/#{template_name}" 
    15     end 
    16     tmpl_name = "#{template_name}_#{visitor.lang}" 
    17     tmpl_dir = "/templates/compiled/#{self[:name]}" 
    18     FileUtils::mkpath("#{RAILS_ROOT}/app/views#{tmpl_dir}") 
    19     # render for the current lang 
    20     res = ZafuParser.new_with_url(zafu_url, :helper=>helper).render 
    21     File.open("#{RAILS_ROOT}/app/views#{tmpl_dir}/#{tmpl_name}.rhtml", "wb") { |f| f.syswrite(res) } 
    22     return "#{tmpl_dir}/#{tmpl_name}" 
    23   rescue ActiveRecord::RecordNotFound 
    24     nil 
    25   end 
    26    
    27   def template_for_path(path) 
    28     asset_for_path(path, Template) 
    29   end 
    30    
    31    
    32   def asset_for_path(path, klass=Node) 
    33     current = self 
    34     if path == 'any' 
    35       return current 
    36     else   
    37       path = path.split('/') 
    38       while path != [] 
    39         template_name = path.shift 
    40         current = secure(klass) { klass.find(:first, :conditions=>["parent_id = ? AND name = ?", current[:id], template_name])} 
    41       end 
    42       current 
    43     end 
    44   rescue ActiveRecord::RecordNotFound 
    45     nil 
    46   end 
    476   
    487  private 
  • trunk/app/models/tag.rb

    r375 r484  
    88  def pages(opts={}) 
    99    return super if opts[:in] 
    10     options = opts.merge(:conditions=>"kpath NOT LIKE 'NPD%'", :or=>["parent_id = ?", self[:id]]) 
    11     @pages ||= tag_for(options) 
     10    options = opts.merge(:conditions=>"kpath LIKE 'NP%' AND kpath NOT LIKE 'NPD%'", :or=>["parent_id = ?", self[:id]]) 
     11    tag_for(options) 
    1212  end 
    1313   
    1414  def documents(opts={}) 
    1515    return super if opts[:in] 
    16     options = opts.merge(:conditions=>"kpath LIKE 'NPD%'", :or=>["parent_id = ?", self[:id]]) 
    17     @documents ||= tag_for(options) 
     16    options = opts.merge(:conditions=>"kpath LIKE 'NP%' AND kpath LIKE 'NPD%'", :or=>["parent_id = ?", self[:id]]) 
     17    tag_for(options) 
    1818  end 
    1919   
     
    2323    return super if opts[:in] 
    2424    options = opts.merge(:conditions=>"kpath LIKE 'NPD%' AND NOT LIKE 'NPDI%'", :or=>["parent_id = ?", self[:id]]) 
    25     @doconly ||= tag_for(options) 
     25    tag_for(options) 
    2626  end 
    2727   
     
    3131    return super if opts[:in] 
    3232    options = opts.merge(:conditions=>"kpath LIKE 'NPDI%'", :or=>["parent_id = ?", self[:id]]) 
    33     @images ||= tag_for(options) 
     33    tag_for(options) 
    3434  end 
    3535end 
  • trunk/app/models/template_version.rb

    r471 r484  
    99  validates_presence_of       :content 
    1010   
    11   # Return the content for the version. Can it's 'own' content or the same as the version this one was copied from. 
     11  # TODO: test 
    1212  def content 
    1313    return @content if @content 
     
    2424  end 
    2525   
     26  # TODO: test 
    2627  def redaction_content 
    2728    content 
    2829  end 
    2930   
     31  # TODO: test 
    3032  def content_class 
    3133    TemplateContent 
  • trunk/app/models/version.rb

    r481 r484  
    2626class Version < ActiveRecord::Base 
    2727  belongs_to            :node 
    28   belongs_to            :user, :foreign_key=>'user_id' # FIXME: can we remove this 
     28  belongs_to            :user 
    2929  before_validation     :version_before_validation 
    3030  validates_presence_of :node 
     
    129129    # Set version number and site_id before validation tests. 
    130130    def version_before_validation 
    131       return false unless node 
     131      unless node 
     132        errors.add('base', 'node missing') 
     133        return false 
     134      end 
    132135      self[:site_id] = node[:site_id] 
    133136     
  • trunk/config/routes.rb

    r480 r484  
    3030                                 :link    => :any } 
    3131                                  
    32     nodes.resources :discussions 
     32    # nodes.resources :discussions do |discussions| 
     33    #   discussions.resources :comments, 
     34    #                 :name_prefix => nil, 
     35    #                 :member => { :reply_to => :post } 
     36    # end 
    3337  end 
    3438   
    3539  map.resources :documents, :member => { :crop_form => :get, :file_form => :get } 
    36    
    3740  # map.resources :trans_phrases do |phrases| 
    3841  #   phrases.resources :trans_values 
     
    7881   
    7982  # temporary routes... 
     83  map.connect 'comments/:action/:id', :controller => 'comments' 
    8084  map.connect 'z/trans/:action', :controller => 'trans' 
    8185  map.connect 'z/calendar/:action', :controller => 'calendar' 
  • trunk/lib/parser/test/testhelp.rb

    r340 r484  
    1414        strings = {} 
    1515        test_methods = [] 
    16         YAML::load_documents( File.open( "#{file}.yml" ) ) do |doc| 
     16        YAML::load_documents( File.open( File.join(File.dirname(__FILE__), "#{file}.yml") ) ) do |doc| 
    1717          doc.each do |elem| 
    1818            test_methods << elem[0] 
  • trunk/lib/tasks/zena.rake

    r462 r484  
    175175       rdoc.options << '--line-numbers' << '--inline-source' 
    176176  end 
     177  Rake::Task['zena:rdoc'].comment = "Create the rdoc documentation" 
     178   
     179  Rake::TestTask.new(:test => "db:test:prepare") do |t| 
     180    t.libs << "test" 
     181    t.pattern = ['test/helpers/**/*_test.rb','test/unit/**/*_test.rb', 'lib/parser/test/*_test.rb'] 
     182    t.verbose = true 
     183  end 
     184  Rake::Task['zena:test'].comment = "Run the tests in test/helpers and test/unit" 
    177185end 
    178186 
     187namespace :test do 
     188   
     189  Rake::TestTask.new(:helpers => "db:test:prepare") do |t| 
     190    t.libs << "test" 
     191    t.pattern = 'test/helpers/**/*_test.rb' 
     192    t.verbose = true 
     193  end 
     194  Rake::Task['test:helpers'].comment = "Run the tests in test/helpers" 
     195end 
     196 
  • trunk/test/helpers/basic.yml

    r483 r484  
    166166  src: "<h1 class='title' do='title' status='true' actions='all'>dummy</h1>" 
    167167  tem: "<h1 class='title'><div class='s<%= @node.version.status %>'><%= show_title(:node=>@node) + node_actions(:node=>@node, :actions=>\"all\")%></div></h1>" 
    168   res: "/<h1 class='title'><div class='s50'><span id='v_title22.1'>status title</span><span class='actions'><a.*\/nodes\/22\/versions\/1\/edit.*\/images\/page_edit.png'.*/><\/a>.*<\/span><\/div><\/h1>/" 
     168  res: "/<h1 class='title'><div class='s50'><span id='v_title22.1'>status title</span><span class='actions'><a.*/nodes/22/versions/1/edit.*/images/page_edit.png'.*/></a>.*</span></div></h1>/" 
    169169 
    170170show_c_width: 
     
    190190  src: "<div id='path' do='show_path'><ul><li><a href='#'>first</a></li> / <li><a href='#'>second</a></li> / <li><a href='#' class='current'>here</a></li></ul></div>" 
    191191  tem: "<div id='path'><%= show_path(:node=>@node) %></div>" 
    192   res: "/<div id='path'><ul class='path'><li>.*zena.*<li>.*oo\/page18.html.*<li><.*\/projects\/cleanWater.*cleanWater<\/a>.*\/oo\/projects\/cleanWater\/page22.html.*class='current'>status<\/a>/" 
     192  res: "/<div id='path'><ul class='path'><li>.*zena.*<li>.*oo/page18.html.*<li><.*/projects/cleanWater.*cleanWater</a>.*/oo/projects/cleanWater/page22.html.*class='current'>status</a>/" 
    193193 
    194194uses_calendar: 
     
    268268edit_not_each: 
    269269  src: "<li class='blah'>this is a post <z:edit>edit post</z:edit></li>" 
    270   tem: "/<li class='blah'>this is a post <\/li>/" 
     270  tem: "/<li class='blah'>this is a post </li>/" 
    271271 
    272272edit_each_no_form: 
     
    278278    node: 'wiki' 
    279279  src: "<z:children><z:each><li do='show' attr='name'>blah</li>\n</z:each><z:add><li>add new</li></z:add><z:form><li><form>this is the form</form></li></z:form></z:children>" 
    280   res: "/<li>bird.*<li>flower.*<li.*toggle.*Node_add.*Node_form.*<li .*Node_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value='/each/add/with/root_Node'/" 
     280  res: "/<li>bird.*<li>flower.*<li.*list_add.*list_form.*toggle.*<li .*list_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value='/each/add/with/form/list'/" 
    281281   
    282282each_edit_with_form: 
     
    284284    node: 'wiki' 
    285285  src: "<z:children><z:each><li><z:show attr='name'>blah</z:show> <z:edit>edit</z:edit></li>\n</z:each><z:form><li><form>this is the form</form></li></z:form></z:children>" 
    286   res: "/<li id='_each_edit_with_root_Node20'>bird <a href='#' onclick=\"new Ajax.Request\('\/z\/zafu\/ajax_edit\/20\?template_url=%2Feach%2Fedit%2Fwith%2Froot_Node'.*flower <a href=\"#\" onclick=\"new Ajax.Request\('\/z\/zafu\/ajax_edit\/21\?template_url=%2Feach%2Fedit%2Fwith%2Froot_Node.*edit</a></li>\n/" 
     286  res: "/<li id='/each/edit/with/form/list30'>bird <a href=\"#\" onclick=\"new Ajax.Request\('/nodes/30/edit\?template_url=%2Feach%2Fedit%2Fwith%2Fform%2Flist/" 
    287287 
    288288set_attribute: 
    289289  src: "<div class='machin' do='void' set_class='node[id]'/><z:void set_class='s[v_status]i[id]'/>" 
    290   res: "<div class='node22'/><div class='s50i22'></div>" 
     290  res: "<div class='node22'></div><div class='s50i22'></div>" 
    291291 
    292292set_attribute_with_inner: 
  • trunk/test/unit/page_test.rb

    r455 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    2 require 'document' # this is needed to load the document model. 
    3 require 'tag' 
    4 require 'project' 
    5 require 'tracker' 
    6 require 'contact' 
    72 
    83class PageTest < ZenaTestUnit 
    94   
    105  def test_select_classes 
    11     assert_equal ["Page", "Project", "Section", "Tag", "Tracker"], Page.select_classes 
     6    # preload models 
     7    Project 
     8    Skin 
     9    Tag 
     10    Tracker 
     11    assert_equal ["Page", "Project", "Section", "Skin", "Tag", "Tracker"], Page.select_classes 
    1212  end 
    1313   
  • trunk/test/unit/skin_test.rb

    r455 r484  
    33class SkinTest < ZenaTestUnit 
    44 
    5   def test_template_url_for_name 
    6     without_files('app/views/templates/compiled') do 
    7       skin = secure(Skin) { Skin.find_by_name('wiki')} 
    8       assert_kind_of Skin, skin 
    9       path = File.join(RAILS_ROOT, 'app', 'views', 'templates', 'compiled', 'wiki', 'any_en.rhtml') 
    10       assert !File.exist?(path), "File does not exist" 
    11       assert_equal "/templates/compiled/wiki/any_en", skin.template_url_for_name('any', nil) 
    12       assert File.exist?(path), "File exists" 
    13       path = File.join(RAILS_ROOT, 'app', 'views', 'templates', 'compiled', 'wiki', 'layout_en.rhtml') 
    14       assert !File.exist?(path), "File does not exist" 
    15       assert_equal "/templates/compiled/wiki/layout_en", skin.template_url_for_name('layout', nil) 
    16       assert File.exist?(path), "File exists" 
    17       assert_equal nil, skin.template_url_for_name('bad', nil) 
    18     end 
    19   end 
    20    
    21   def test_template_for_path 
    22     skin = secure(Skin) { Skin.find_by_name('wiki')} 
    23     assert_kind_of Skin, skin 
    24     tmpl = skin.template_for_path('any') 
    25     assert_equal tmpl, skin 
    26     tmpl = skin.template_for_path('layout') 
    27     assert_equal nodes_id(:layout), tmpl[:id] 
    28     tmpl = skin.template_for_path('bad') 
    29     assert_nil tmpl 
    30   end 
    31    
    325  def test_name_change 
    336    login(:lion) 
    347    skin = secure(Node) { nodes(:wiki_skin) } 
    35     tmpt = secure(Node) { nodes(:layout)    } 
     8    tmpt = secure(Node) { nodes(:wiki_node) } 
     9    assert_kind_of Template, tmpt 
    3610    assert_equal 'wiki', skin.name 
    3711    assert_equal 'wiki', tmpt.c_skin_name 
    3812    skin.name = 'fun' 
    3913    assert skin.save, "Can save skin." 
    40     tmpt = secure(Node) { nodes(:layout)    } # reload 
     14    tmpt = secure(Node) { nodes(:wiki_node) } # reload 
    4115    assert_equal 'fun', tmpt.c_skin_name 
    4216    assert_equal 'fun', secure(Node) { nodes(:wiki_page_changes) }.c_skin_name 
  • trunk/test/unit/tag_test.rb

    r352 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22 
    3 class CollectorTest < ZenaTestUnit 
     3class TagTest < ZenaTestUnit 
    44   
    55  def test_pages 
     
    77    tag = secure(Node) { nodes(:art) } 
    88    pages = tag.pages 
    9     assert_equal 2, pages.size 
     9    assert_equal 1, pages.size 
    1010    assert_equal 'cleanWater', pages[0].name 
    1111    child = secure(Page) { Page.create(:parent_id=>tag[:id], :name=>'a_child') } 
     
    1313    tag = secure(Node) { nodes(:art) } 
    1414    pages = tag.pages 
    15     assert_equal 3, pages.size 
    16     assert_equal 'a_child', pages[0].name 
     15    assert_equal 2, pages.size 
     16    assert_equal 'a_child', pages[1].name 
    1717  end 
    1818   
     
    2323    assert doc.save, "Can save" 
    2424    tag = secure(Node) { nodes(:art) } 
    25     assert_equal 2, tag.pages.size 
     25    assert_equal 1, tag.pages.size 
    2626    assert_equal 1, tag.documents.size 
    2727    assert_equal 'water', tag.documents[0].name 
  • trunk/test/unit/template_version_test.rb

    r455 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22 
    3 class TemplateVersionTest < Test::Unit::TestCase 
    4   fixtures :template_versions 
    5  
    6   # Replace this with your real tests. 
     3class TemplateVersionTest < ZenaTestUnit 
    74  def test_truth 
    85    assert true 
  • trunk/test/unit/text_document_content_test.rb

    r266 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22 
    3 class TextDocumentContentTest < Test::Unit::TestCase 
    4   fixtures :text_document_contents 
     3class TextDocumentContentTest < ZenaTestUnit 
    54 
    6   # Replace this with your real tests. 
    75  def test_truth 
    86    assert true 
  • trunk/test/unit/trans_key_test.rb

    r133 r484  
    99    assert_equal 'lundi', key['fr'] 
    1010    assert_equal 'lundi', TransPhrase['Monday']['fr'] 
    11   end 
    12    
    13   def test_create_new_key 
    14     assert_nil TransPhrase.find_by_key('yoba') 
    15     key = TransPhrase['yoba'] 
    16     assert_not_nil TransPhrase.find_by_key('yoba') 
    1711  end 
    1812   
  • trunk/test/unit/trans_value_test.rb

    r66 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22 
    3 class TransValueTest < Test::Unit::TestCase 
    4    
     3class TransValueTest < ZenaTestUnit 
    54  def test_nothing 
    65    assert true, 'nothing to test' 
  • trunk/test/unit/user_test.rb

    r455 r484  
    11require File.dirname(__FILE__) + '/../test_helper' 
    2 ApplicationController # need to load to test caching 
     2 
    33class UserTest < ZenaTestUnit 
    44 
  • trunk/test/unit/version_test.rb

    r472 r484  
    9696    node = secure(Node) { Node.new(:parent_id=>1, :name=>'bob') } 
    9797    assert node.save 
    98     vers = Version.new 
     98    vers = secure(Version) { Version.new } 
    9999    assert !vers.save 
    100     assert_equal "can't be blank", vers.errors[:node] 
    101     assert_equal "can't be blank", vers.errors[:user] 
     100    assert_equal "node missing", vers.errors[:base] 
    102101  end 
    103102   
  • trunk/vendor/bricks/20070122-172926.txt

    r251 r484  
    7171copy;app/views/comment/_li.rhtml;app/views/comment/_li.rhtml 
    7272copy;app/views/comment/_li_simple.rhtml;app/views/comment/_li_simple.rhtml 
    73 copy;app/views/comment/_list.rhtml;app/views/comment/_list.rhtml 
     73copy;app/views/comments/_list.rhtml;app/views/comments/_list.rhtml 
    7474copy;app/views/comment/create.rjs;app/views/comment/create.rjs 
    7575copy;app/views/comment/edit.rjs;app/views/comment/edit.rjs