4 class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
7 # Create the default language for diary entries
8 create(:language, :code => "en")
12 # test all routes which lead to this controller
15 { :path => "/user/username/diary_comments", :method => :get },
16 { :controller => "users/diary_comments", :action => "index", :user_display_name => "username" }
19 get "/user/username/diary/comments/1"
20 assert_redirected_to "/user/username/diary_comments"
22 get "/user/username/diary/comments"
23 assert_redirected_to "/user/username/diary_comments"
28 other_user = create(:user)
29 suspended_user = create(:user, :suspended)
30 deleted_user = create(:user, :deleted)
32 # Test a user with no comments
33 get user_diary_comments_path(user)
34 assert_response :success
35 assert_template :index
36 assert_select "h4", :html => "No comments"
38 # Test a user with a comment
39 create(:diary_comment, :user => other_user)
41 get user_diary_comments_path(other_user)
42 assert_response :success
43 assert_template :index
44 assert_dom "a[href='#{user_path(other_user)}']", :text => other_user.display_name
45 assert_select "table.table-striped tbody" do
46 assert_select "tr", :count => 1
49 # Test a suspended user
50 get user_diary_comments_path(suspended_user)
51 assert_response :not_found
54 get user_diary_comments_path(deleted_user)
55 assert_response :not_found
58 def test_index_invalid_paged
61 %w[-1 0 fred].each do |id|
62 get user_diary_comments_path(user, :before => id)
63 assert_redirected_to :controller => "/errors", :action => :bad_request
65 get user_diary_comments_path(user, :after => id)
66 assert_redirected_to :controller => "/errors", :action => :bad_request