3 class DiaryEntryControllerTest < ActionController::TestCase
4 fixtures :users, :user_roles, :languages, :friends
6 include ActionView::Helpers::NumberHelper
9 # test all routes which lead to this controller
12 { :path => "/diary", :method => :get },
13 { :controller => "diary_entry", :action => "list" }
16 { :path => "/diary/language", :method => :get },
17 { :controller => "diary_entry", :action => "list", :language => "language" }
20 { :path => "/user/username/diary", :method => :get },
21 { :controller => "diary_entry", :action => "list", :display_name => "username" }
24 { :path => "/diary/friends", :method => :get },
25 { :controller => "diary_entry", :action => "list", :friends => true }
28 { :path => "/diary/nearby", :method => :get },
29 { :controller => "diary_entry", :action => "list", :nearby => true }
33 { :path => "/diary/rss", :method => :get },
34 { :controller => "diary_entry", :action => "rss", :format => :rss }
37 { :path => "/diary/language/rss", :method => :get },
38 { :controller => "diary_entry", :action => "rss", :language => "language", :format => :rss }
41 { :path => "/user/username/diary/rss", :method => :get },
42 { :controller => "diary_entry", :action => "rss", :display_name => "username", :format => :rss }
46 { :path => "/user/username/diary/comments", :method => :get },
47 { :controller => "diary_entry", :action => "comments", :display_name => "username" }
50 { :path => "/user/username/diary/comments/1", :method => :get },
51 { :controller => "diary_entry", :action => "comments", :display_name => "username", :page => "1" }
55 { :path => "/diary/new", :method => :get },
56 { :controller => "diary_entry", :action => "new" }
59 { :path => "/diary/new", :method => :post },
60 { :controller => "diary_entry", :action => "new" }
63 { :path => "/user/username/diary/1", :method => :get },
64 { :controller => "diary_entry", :action => "view", :display_name => "username", :id => "1" }
67 { :path => "/user/username/diary/1/edit", :method => :get },
68 { :controller => "diary_entry", :action => "edit", :display_name => "username", :id => "1" }
71 { :path => "/user/username/diary/1/edit", :method => :post },
72 { :controller => "diary_entry", :action => "edit", :display_name => "username", :id => "1" }
75 { :path => "/user/username/diary/1/newcomment", :method => :post },
76 { :controller => "diary_entry", :action => "comment", :display_name => "username", :id => "1" }
79 { :path => "/user/username/diary/1/hide", :method => :post },
80 { :controller => "diary_entry", :action => "hide", :display_name => "username", :id => "1" }
83 { :path => "/user/username/diary/1/hidecomment/2", :method => :post },
84 { :controller => "diary_entry", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" }
89 # Make sure that you are redirected to the login page when you
92 assert_response :redirect
93 assert_redirected_to :controller => :user, :action => :login, :referer => "/diary/new"
95 # Now try again when logged in
96 get :new, {}, { :user => users(:normal_user).id }
97 assert_response :success
98 assert_select "title", :text => /New Diary Entry/, :count => 1
99 assert_select "div.content-heading", :count => 1 do
100 assert_select "h1", :text => /New Diary Entry/, :count => 1
102 assert_select "div#content", :count => 1 do
103 assert_select "form[action='/diary/new'][method=post]", :count => 1 do
104 assert_select "input#diary_entry_title[name='diary_entry[title]']", :count => 1
105 assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => "", :count => 1
106 assert_select "select#diary_entry_language_code", :count => 1
107 assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1
108 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1
109 assert_select "input[name=commit][type=submit][value=Publish]", :count => 1
110 assert_select "input[name=commit][type=submit][value=Edit]", :count => 1
111 assert_select "input[name=commit][type=submit][value=Preview]", :count => 1
112 assert_select "input", :count => 7
116 new_title = "New Title"
117 new_body = "This is a new body for the diary entry"
119 new_longitude = "2.2"
120 new_language_code = "en"
122 # Now try creating a invalid diary entry with an empty body
123 assert_no_difference "DiaryEntry.count" do
124 post :new, { :commit => "save",
125 :diary_entry => { :title => new_title, :body => "", :latitude => new_latitude,
126 :longitude => new_longitude, :language_code => new_language_code } },
127 { :user => users(:normal_user).id }
129 assert_response :success
130 assert_template :edit
132 assert_nil UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first
134 # Now try creating a diary entry
135 assert_difference "DiaryEntry.count", 1 do
136 post :new, { :commit => "save",
137 :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
138 :longitude => new_longitude, :language_code => new_language_code } },
139 { :user => users(:normal_user).id }
141 assert_response :redirect
142 assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
143 entry = DiaryEntry.order(:id).last
144 assert_equal users(:normal_user).id, entry.user_id
145 assert_equal new_title, entry.title
146 assert_equal new_body, entry.body
147 assert_equal new_latitude.to_f, entry.latitude
148 assert_equal new_longitude.to_f, entry.longitude
149 assert_equal new_language_code, entry.language_code
151 assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
153 new_language_code = "de"
155 # Now try creating a diary entry in a different language
156 assert_difference "DiaryEntry.count", 1 do
157 post :new, { :commit => "save",
158 :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
159 :longitude => new_longitude, :language_code => new_language_code } },
160 { :user => users(:normal_user).id }
162 assert_response :redirect
163 assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
164 entry = DiaryEntry.order(:id).last
165 assert_equal users(:normal_user).id, entry.user_id
166 assert_equal new_title, entry.title
167 assert_equal new_body, entry.body
168 assert_equal new_latitude.to_f, entry.latitude
169 assert_equal new_longitude.to_f, entry.longitude
170 assert_equal new_language_code, entry.language_code
172 assert_equal new_language_code, UserPreference.where(:user_id => users(:normal_user).id, :k => "diary.default_language").first.v
176 # Generate some spammy content
177 spammy_title = "Spam Spam Spam Spam Spam"
178 spammy_body = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
180 # Try creating a spammy diary entry
181 assert_difference "DiaryEntry.count", 1 do
182 post :new, { :commit => "save",
183 :diary_entry => { :title => spammy_title, :body => spammy_body, :language_code => "en" } },
184 { :user => users(:normal_user).id }
186 assert_response :redirect
187 assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
188 entry = DiaryEntry.order(:id).last
189 assert_equal users(:normal_user).id, entry.user_id
190 assert_equal spammy_title, entry.title
191 assert_equal spammy_body, entry.body
192 assert_equal "en", entry.language_code
193 assert_equal "suspended", User.find(users(:normal_user).id).status
195 # Follow the redirect
196 get :list, { :display_name => users(:normal_user).display_name }, { :user => users(:normal_user).id }
197 assert_response :redirect
198 assert_redirected_to :controller => :user, :action => :suspended
202 entry = create(:diary_entry, :user_id => users(:normal_user).id)
204 # Make sure that you are redirected to the login page when you are
205 # not logged in, without and with the id of the entry you want to edit
206 get :edit, :display_name => entry.user.display_name, :id => entry.id
207 assert_response :redirect
208 assert_redirected_to :controller => :user, :action => :login, :referer => "/user/#{entry.user.display_name}/diary/#{entry.id}/edit"
210 # Verify that you get a not found error, when you pass a bogus id
211 get :edit, { :display_name => entry.user.display_name, :id => 9999 }, { :user => entry.user.id }
212 assert_response :not_found
213 assert_select "div.content-heading", :count => 1 do
214 assert_select "h2", :text => "No entry with the id: 9999", :count => 1
217 # Verify that you get redirected to view if you are not the user
218 # that created the entry
219 get :edit, { :display_name => entry.user.display_name, :id => entry.id }, { :user => users(:public_user).id }
220 assert_response :redirect
221 assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
223 # Now pass the id, and check that you can edit it, when using the same
224 # user as the person who created the entry
225 get :edit, { :display_name => entry.user.display_name, :id => entry.id }, { :user => entry.user.id }
226 assert_response :success
227 assert_select "title", :text => /Edit diary entry/, :count => 1
228 assert_select "div.content-heading", :count => 1 do
229 assert_select "h1", :text => /Edit diary entry/, :count => 1
231 assert_select "div#content", :count => 1 do
232 assert_select "form[action='/user/#{entry.user.display_name}/diary/#{entry.id}/edit'][method=post]", :count => 1 do
233 assert_select "input#diary_entry_title[name='diary_entry[title]'][value='#{entry.title}']", :count => 1
234 assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => entry.body, :count => 1
235 assert_select "select#diary_entry_language_code", :count => 1
236 assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1
237 assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1
238 assert_select "input[name=commit][type=submit][value=Save]", :count => 1
239 assert_select "input[name=commit][type=submit][value=Edit]", :count => 1
240 assert_select "input[name=commit][type=submit][value=Preview]", :count => 1
241 assert_select "input", :count => 7
245 # Now lets see if you can edit the diary entry
246 new_title = "New Title"
247 new_body = "This is a new body for the diary entry"
249 new_longitude = "2.2"
250 new_language_code = "en"
251 post :edit, { :display_name => entry.user.display_name, :id => entry.id, :commit => "save",
252 :diary_entry => { :title => new_title, :body => new_body, :latitude => new_latitude,
253 :longitude => new_longitude, :language_code => new_language_code } },
254 { :user => entry.user.id }
255 assert_response :redirect
256 assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
258 # Now check that the new data is rendered, when logged in
259 get :view, { :display_name => entry.user.display_name, :id => entry.id }, { :user => entry.user.id }
260 assert_response :success
261 assert_template "diary_entry/view"
262 assert_select "title", :text => /Users' diaries | /, :count => 1
263 assert_select "div.content-heading", :count => 1 do
264 assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1
266 assert_select "div#content", :count => 1 do
267 assert_select "div.post_heading", :text => /#{new_title}/, :count => 1
268 # This next line won't work if the text has been run through the htmlize function
269 # due to formatting that could be introduced
270 assert_select "p", :text => /#{new_body}/, :count => 1
271 assert_select "abbr[class='geo'][title='#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}']", :count => 1
272 # As we're not logged in, check that you cannot edit
273 # print @response.body
274 assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1
277 # and when not logged in as the user who wrote the entry
278 get :view, { :display_name => entry.user.display_name, :id => entry.id }, { :user => entry.user.id }
279 assert_response :success
280 assert_template "diary_entry/view"
281 assert_select "title", :text => /Users' diaries | /, :count => 1
282 assert_select "div.content-heading", :count => 1 do
283 assert_select "h2", :text => /#{users(:normal_user).display_name}'s diary/, :count => 1
285 assert_select "div#content", :count => 1 do
286 assert_select "div.post_heading", :text => /#{new_title}/, :count => 1
287 # This next line won't work if the text has been run through the htmlize function
288 # due to formatting that could be introduced
289 assert_select "p", :text => /#{new_body}/, :count => 1
290 assert_select "abbr[class=geo][title='#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}']", :count => 1
291 # As we're not logged in, check that you cannot edit
292 assert_select "li[class='hidden show_if_user_#{entry.user.id}']", :count => 1 do
293 assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1
299 diary_entry = create(:diary_entry, :language_code => "en")
300 get :edit, { :display_name => users(:normal_user).display_name, :id => diary_entry.id }, { :user => users(:normal_user).id }
301 assert_response :success
302 assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
306 entry = create(:diary_entry, :user_id => users(:normal_user).id)
308 # Make sure that you are denied when you are not logged in
309 post :comment, :display_name => entry.user.display_name, :id => entry.id
310 assert_response :forbidden
312 # Verify that you get a not found error, when you pass a bogus id
313 post :comment, { :display_name => entry.user.display_name, :id => 9999 }, { :user => users(:public_user).id }
314 assert_response :not_found
315 assert_select "div.content-heading", :count => 1 do
316 assert_select "h2", :text => "No entry with the id: 9999", :count => 1
319 # Now try an invalid comment with an empty body
320 assert_no_difference "ActionMailer::Base.deliveries.size" do
321 assert_no_difference "DiaryComment.count" do
322 post :comment, { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => "" } }, { :user => users(:public_user).id }
325 assert_response :success
326 assert_template :view
328 # Now try again with the right id
329 assert_difference "ActionMailer::Base.deliveries.size", 1 do
330 assert_difference "DiaryComment.count", 1 do
331 post :comment, { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => "New comment" } }, { :user => users(:public_user).id }
334 assert_response :redirect
335 assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
336 email = ActionMailer::Base.deliveries.first
337 assert_equal [users(:normal_user).email], email.to
338 assert_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on your diary entry", email.subject
339 assert_match /New comment/, email.text_part.decoded
340 assert_match /New comment/, email.html_part.decoded
341 ActionMailer::Base.deliveries.clear
342 comment = DiaryComment.order(:id).last
343 assert_equal entry.id, comment.diary_entry_id
344 assert_equal users(:public_user).id, comment.user_id
345 assert_equal "New comment", comment.body
347 # Now view the diary entry, and check the new comment is present
348 get :view, :display_name => entry.user.display_name, :id => entry.id
349 assert_response :success
350 assert_select ".diary-comment", :count => 1 do
351 assert_select "#comment#{comment.id}", :count => 1 do
352 assert_select "a[href='/user/#{users(:public_user).display_name}']", :text => users(:public_user).display_name, :count => 1
354 assert_select ".richtext", :text => /New comment/, :count => 1
358 def test_comment_spammy
359 # Find the entry to comment on
360 entry = create(:diary_entry, :user_id => users(:normal_user).id)
362 # Generate some spammy content
363 spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
365 # Try creating a spammy comment
366 assert_difference "ActionMailer::Base.deliveries.size", 1 do
367 assert_difference "DiaryComment.count", 1 do
368 post :comment, { :display_name => entry.user.display_name, :id => entry.id, :diary_comment => { :body => spammy_text } }, { :user => users(:public_user).id }
371 assert_response :redirect
372 assert_redirected_to :action => :view, :display_name => entry.user.display_name, :id => entry.id
373 email = ActionMailer::Base.deliveries.first
374 assert_equal [users(:normal_user).email], email.to
375 assert_equal "[OpenStreetMap] #{users(:public_user).display_name} commented on your diary entry", email.subject
376 assert_match %r{http://example.com/spam}, email.text_part.decoded
377 assert_match %r{http://example.com/spam}, email.html_part.decoded
378 ActionMailer::Base.deliveries.clear
379 comment = DiaryComment.order(:id).last
380 assert_equal entry.id, comment.diary_entry_id
381 assert_equal users(:public_user).id, comment.user_id
382 assert_equal spammy_text, comment.body
383 assert_equal "suspended", User.find(users(:public_user).id).status
385 # Follow the redirect
386 get :list, { :display_name => users(:normal_user).display_name }, { :user => users(:public_user).id }
387 assert_response :redirect
388 assert_redirected_to :controller => :user, :action => :suspended
390 # Now view the diary entry, and check the new comment is not present
391 get :view, :display_name => entry.user.display_name, :id => entry.id
392 assert_response :success
393 assert_select ".diary-comment", :count => 0
397 diary_entry = create(:diary_entry)
398 geo_entry = create(:diary_entry, :latitude => 51.50763, :longitude => -0.10781)
399 public_entry = create(:diary_entry, :user_id => users(:public_user).id)
401 # Try a list of all diary entries
403 check_diary_list diary_entry, geo_entry, public_entry
407 diary_entry = create(:diary_entry)
408 geo_entry = create(:diary_entry, :latitude => 51.50763, :longitude => -0.10781)
410 # Try a list of diary entries for a valid user
411 get :list, :display_name => users(:normal_user).display_name
412 check_diary_list diary_entry, geo_entry
414 # Try a list of diary entries for an invalid user
415 get :list, :display_name => "No Such User"
416 assert_response :not_found
417 assert_template "user/no_such_user"
420 def test_list_friends
421 diary_entry = create(:diary_entry, :user_id => friends(:normal_user_with_second_user).friend_user_id)
423 # Try a list of diary entries for your friends when not logged in
424 get :list, :friends => true
425 assert_response :redirect
426 assert_redirected_to :controller => :user, :action => :login, :referer => "/diary/friends"
428 # Try a list of diary entries for your friends when logged in
429 get :list, { :friends => true }, { :user => users(:normal_user).id }
430 check_diary_list diary_entry
431 get :list, { :friends => true }, { :user => users(:public_user).id }
436 diary_entry = create(:diary_entry, :user_id => users(:public_user).id)
437 # Try a list of diary entries for nearby users when not logged in
438 get :list, :nearby => true
439 assert_response :redirect
440 assert_redirected_to :controller => :user, :action => :login, :referer => "/diary/nearby"
442 # Try a list of diary entries for nearby users when logged in
443 get :list, { :nearby => true }, { :user => users(:german_user).id }
444 check_diary_list diary_entry
445 get :list, { :nearby => true }, { :user => users(:public_user).id }
449 def test_list_language
450 diary_entry_en = create(:diary_entry, :language_code => "en")
451 diary_entry_en2 = create(:diary_entry, :language_code => "en")
452 diary_entry_de = create(:diary_entry, :language_code => "de")
454 # Try a list of diary entries in english
455 get :list, :language => "en"
456 check_diary_list diary_entry_en, diary_entry_en2
458 # Try a list of diary entries in german
459 get :list, :language => "de"
460 check_diary_list diary_entry_de
462 # Try a list of diary entries in slovenian
463 get :list, :language => "sl"
468 create(:diary_entry, :language_code => "en")
469 create(:diary_entry, :language_code => "en")
470 create(:diary_entry, :language_code => "de")
472 get :rss, :format => :rss
473 assert_response :success, "Should be able to get a diary RSS"
474 assert_select "rss", :count => 1 do
475 assert_select "channel", :count => 1 do
476 assert_select "channel>title", :count => 1
477 assert_select "image", :count => 1
478 assert_select "channel>item", :count => 3
483 def test_rss_language
484 create(:diary_entry, :language_code => "en")
485 create(:diary_entry, :language_code => "en")
486 create(:diary_entry, :language_code => "de")
488 get :rss, :language => "en", :format => :rss
489 assert_response :success, "Should be able to get a specific language diary RSS"
490 assert_select "rss>channel>item", :count => 2 # , "Diary entries should be filtered by language"
493 # def test_rss_nonexisting_language
494 # get :rss, {:language => 'xx', :format => :rss}
495 # assert_response :not_found, "Should not be able to get a nonexisting language diary RSS"
498 def test_rss_language_with_no_entries
499 create(:diary_entry, :language_code => "en")
501 get :rss, :language => "sl", :format => :rss
502 assert_response :success, "Should be able to get a specific language diary RSS"
503 assert_select "rss>channel>item", :count => 0 # , "Diary entries should be filtered by language"
507 create(:diary_entry, :user_id => users(:normal_user).id)
508 create(:diary_entry, :user_id => users(:normal_user).id)
509 create(:diary_entry, :user_id => users(:public_user).id)
511 get :rss, :display_name => users(:normal_user).display_name, :format => :rss
512 assert_response :success, "Should be able to get a specific users diary RSS"
513 assert_select "rss>channel>item", :count => 2 # , "Diary entries should be filtered by user"
516 def test_rss_nonexisting_user
517 # Try a user that has never existed
518 get :rss, :display_name => "fakeUsername76543", :format => :rss
519 assert_response :not_found, "Should not be able to get a nonexisting users diary RSS"
521 # Try a suspended user
522 get :rss, :display_name => users(:suspended_user).display_name, :format => :rss
523 assert_response :not_found, "Should not be able to get a suspended users diary RSS"
526 get :rss, :display_name => users(:deleted_user).display_name, :format => :rss
527 assert_response :not_found, "Should not be able to get a deleted users diary RSS"
531 # Try a normal entry that should work
532 diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
533 get :view, :display_name => users(:normal_user).display_name, :id => diary_entry.id
534 assert_response :success
535 assert_template :view
537 # Try a deleted entry
538 diary_entry_deleted = create(:diary_entry, :user_id => users(:normal_user).id, :visible => false)
539 get :view, :display_name => users(:normal_user).display_name, :id => diary_entry_deleted.id
540 assert_response :not_found
542 # Try an entry by a suspended user
543 diary_entry_suspended = create(:diary_entry, :user_id => users(:suspended_user).id)
544 get :view, :display_name => users(:suspended_user).display_name, :id => diary_entry_suspended.id
545 assert_response :not_found
547 # Try an entry by a deleted user
548 diary_entry_deleted = create(:diary_entry, :user_id => users(:deleted_user).id)
549 get :view, :display_name => users(:deleted_user).display_name, :id => diary_entry_deleted.id
550 assert_response :not_found
553 def test_view_hidden_comments
554 # Get a diary entry that has hidden comments
555 diary_entry = create(:diary_entry)
556 visible_comment = create(:diary_comment, :diary_entry => diary_entry)
557 suspended_user_comment = create(:diary_comment, :diary_entry => diary_entry, :user_id => users(:suspended_user).id)
558 deleted_user_comment = create(:diary_comment, :diary_entry => diary_entry, :user_id => users(:deleted_user).id)
559 hidden_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
561 get :view, :display_name => users(:normal_user).display_name, :id => diary_entry.id
562 assert_response :success
563 assert_template :view
564 assert_select "div.comments" do
565 assert_select "p#comment#{visible_comment.id}", :count => 1
566 assert_select "p#comment#{suspended_user_comment.id}", :count => 0
567 assert_select "p#comment#{deleted_user_comment.id}", :count => 0
568 assert_select "p#comment#{hidden_comment.id}", :count => 0
573 # Try without logging in
574 diary_entry = create(:diary_entry)
575 post :hide, :display_name => users(:normal_user).display_name, :id => diary_entry.id
576 assert_response :forbidden
577 assert_equal true, DiaryEntry.find(diary_entry.id).visible
579 # Now try as a normal user
580 post :hide, { :display_name => users(:normal_user).display_name, :id => diary_entry.id }, { :user => users(:normal_user).id }
581 assert_response :redirect
582 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entry.id
583 assert_equal true, DiaryEntry.find(diary_entry.id).visible
585 # Finally try as an administrator
586 post :hide, { :display_name => users(:normal_user).display_name, :id => diary_entry.id }, { :user => users(:administrator_user).id }
587 assert_response :redirect
588 assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
589 assert_equal false, DiaryEntry.find(diary_entry.id).visible
593 diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
594 diary_comment = create(:diary_comment, :diary_entry => diary_entry)
595 # Try without logging in
596 post :hidecomment, :display_name => users(:normal_user).display_name, :id => diary_entry.id, :comment => diary_comment.id
597 assert_response :forbidden
598 assert_equal true, DiaryComment.find(diary_comment.id).visible
600 # Now try as a normal user
601 post :hidecomment, { :display_name => users(:normal_user).display_name, :id => diary_entry.id, :comment => diary_comment.id }, { :user => users(:normal_user).id }
602 assert_response :redirect
603 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entry.id
604 assert_equal true, DiaryComment.find(diary_comment.id).visible
606 # Finally try as an administrator
607 post :hidecomment, { :display_name => users(:normal_user).display_name, :id => diary_entry.id, :comment => diary_comment.id }, { :user => users(:administrator_user).id }
608 assert_response :redirect
609 assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entry.id
610 assert_equal false, DiaryComment.find(diary_comment.id).visible
614 # Test a user with no comments
615 get :comments, :display_name => users(:normal_user).display_name
616 assert_response :success
617 assert_template :comments
618 assert_select "table.messages" do
619 assert_select "tr", :count => 1 # header, no comments
622 # Test a user with a comment
623 create(:diary_comment, :user_id => users(:public_user).id)
625 get :comments, :display_name => users(:public_user).display_name
626 assert_response :success
627 assert_template :comments
628 assert_select "table.messages" do
629 assert_select "tr", :count => 2 # header and one comment
632 # Test a suspended user
633 get :comments, :display_name => users(:suspended_user).display_name
634 assert_response :not_found
636 # Test a deleted user
637 get :comments, :display_name => users(:deleted_user).display_name
638 assert_response :not_found
643 def check_diary_list(*entries)
644 assert_response :success
645 assert_template "list"
646 assert_no_missing_translations
647 assert_select "div.diary_post", entries.count
649 entries.each do |entry|
650 assert_select "a[href=?]", "/user/#{entry.user.display_name}/diary/#{entry.id}"