Class Test::Unit::TestCase
In: test/test_helper.rb
Parent: Object

Methods

External Aliases

path -> local_path

Public Instance methods

[Source]

     # File test/test_helper.rb, line 139
139:   def assert_enhanced_file(path)
140:     html = IO.readlines(path).join
141:     assert [true, true, true], [html.include?("<!-- epfwiki head start -->"), html.include?("onload"), html.include?("<!-- epfwiki head end -->")]
142:   end

[Source]

     # File test/test_helper.rb, line 104
104:   def assert_errors(object = nil)
105:     if object
106:       object.errors.full_messages.each do |message|
107:         assert_tag :content => message
108:       end
109:     else
110:       assert_tag error_message_field      
111:     end
112:   end

[Source]

    # File test/test_helper.rb, line 78
78:   def assert_field(name)
79:     assert_tag :tag => "input", :attributes => {:id => name}
80:   end

[Source]

     # File test/test_helper.rb, line 164
164:   def assert_illegal_get
165:     assert_redirected_to :controller => 'other', :action => 'error'
166:     assert ::FLASH_USE_POST_NOT_GET, flash['error']
167:   end

[Source]

     # File test/test_helper.rb, line 114
114:   def assert_no_errors(object = nil)
115:     if object
116:       object.errors.full_messages.each do |message|
117:         assert_no_tag :content => message 
118:       end
119:     else
120:       assert_no_tag error_message_field
121:     end
122:   end

[Source]

    # File test/test_helper.rb, line 82
82:   def assert_no_field(name)
83:     assert_no_tag :tag => "input", :attributes => {:id => name}
84:   end

[Source]

     # File test/test_helper.rb, line 124
124:   def assert_pattern(pat, html, result)
125:     html =~ pat
126:     assert_equal result, $&
127:   end

[Source]

     # File test/test_helper.rb, line 133
133:   def assert_save(object)
134:     if !object.save
135:       assert_equal '', object.errors.full_messages.join(", ")      
136:     end
137:   end

[Source]

     # File test/test_helper.rb, line 150
150:   def assert_tologin
151:     #assert_equal  ::MSG_LOGIN, flash['notice']
152:     assert_equal @request.request_uri, session["return_to"]
153:     assert_redirected_to :controller => 'login'
154:   end

[Source]

     # File test/test_helper.rb, line 155
155:   def assert_unot_admin_message
156:     assert_equal LoginController::FLASH_UNOT_ADMIN, flash['error']
157:     assert_redirected_to :controller => "other", :action => "error"
158:   end

[Source]

     # File test/test_helper.rb, line 159
159:   def assert_unot_cadmin_message
160:     assert_equal LoginController::FLASH_UNOT_CADMIN, flash['error']
161:     assert_redirected_to :controller => "other", :action => "error"
162:   end

[Source]

     # File test/test_helper.rb, line 144
144:   def assert_version_file(path)
145:     html = IO.readlines(path).join
146:     logger.debug('html: ' + html)
147:     assert_equal [path, false,true, true], [path, html.include?('<!-- epfwiki head start -->'), html.include?('<body>'), html.include?('<!-- treebrowser tag -->')]
148:   end

[Source]

     # File test/test_helper.rb, line 86
 86:   def assert_wiki_menu(wiki, page, html, action)
 87:     result_expected = []
 88:     result_expected << ["", '/' + wiki.rel_path + '/' + page.rel_path, "View"]
 89:     result_expected << ["", "/#{wiki.site_folder}/#{page.id}/discussion", "Discussion"]
 90:     result_expected << ["", "/#{wiki.site_folder}/#{page.id}/edit", "Edit"]
 91:     result_expected << ["", "/#{wiki.site_folder}/#{page.id}/new", "New"]
 92:     result_expected << ["", "/#{wiki.site_folder}/#{page.id}/info", "Info"]
 93:     result_expected << ["", "/", "Home"]
 94:     result_expected.each do |r|
 95:       r[0] = " class=\"current\"" if r[2] == action
 96:     end
 97:     result = html.scan(/<a href="(.*?)".*?<span>(.*?)<\/span>/)    
 98:     assert result_expected, result
 99:     if action == 'edit'
100:       # TODO implement functional test for confirm message
101:     end
102:   end

[Source]

     # File test/test_helper.rb, line 180
180:   def copyright_files(path)
181:     paths = Array.new
182:      (Dir.entries(path) - [".", ".."]).each do |entry| 
183:       new_path = File.expand_path(entry, path)
184:       if FileTest.directory?(new_path)   
185:         paths = paths + copyright_files(new_path)
186:       else
187:         if entry =~ /\.rb\z/i
188:           paths << new_path 
189:         end
190:       end
191:     end
192:     return paths
193:   end

Method create_some_data creates some test records for a page (Comment, Checkout, Upload, New Page)

[Source]

    # File test/test_helper.rb, line 60
60:   def create_some_data(p, u = @andy)
61:     for i in 0..15
62:       c= Comment.new(:text => "Text of comment #{i} by user tony", :user => u, :version => p.current_version, :page => p, :site => p.site)
63:       assert c.save
64:       co = Checkout.new(:user => u, :page => p, :site => p.site, :note => "Checkout #{i} by Andy")
65:       assert co.save
66:       co.checkin(u)
67:       upl = Upload.new(:filename => 'filename.html', :upload_type => 'Image', 
68:         :content_type => 'Content type', :description => 'Description of upload', 
69:         :user_id => u.id, :rel_path => 'x/y/z.html')
70:       assert upl.save
71:       new_page2, new_co2 = WikiPage.new_using_template(:presentation_name => 'New Page Using Another Page as a Template', :source_version => p.current_version, :user => u, :site => p.site)  
72:       assert_no_errors(new_page2)
73:       assert_no_errors(new_co2)
74:       new_co2.checkin(u)
75:     end
76:   end

[Source]

     # File test/test_helper.rb, line 129
129:   def error_message_field
130:     {:tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }}
131:   end

Add more helper methods to be used by all tests here…

[Source]

    # File test/test_helper.rb, line 46
46:   def logger
47:     RAILS_DEFAULT_LOGGER
48:   end

[Source]

    # File test/test_helper.rb, line 50
50:   def login(who)
51:     logger.debug("Login: #{who.inspect}")
52:     open_session do |sess|
53:       logger.debug("Opening session")
54:       sess.post "login/login", :user => {:email => who.email, :password => who.password }
55:       assert_not_nil sess.assigns(:logged_in_user)
56:     end
57:   end

[Source]

     # File test/test_helper.rb, line 169
169:   def upload_file(path, content_type="application/octet-stream")
170:     file = Tempfile.new(File.basename(path))
171:     FileUtils.copy_file(path, file.path)
172:     (class << file; self; end;).class_eval do
173:       alias local_path path
174:       define_method(:original_filename) { File.basename(path)}
175:       define_method(:content_type) { content_type }
176:     end
177:     return file
178:   end

[Validate]