3 class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
6 # Create the default language for diary entries
7 create(:language, :code => "en")
12 { :path => "/user/username/diary/comments", :method => :get },
13 { :controller => "diary_comments", :action => "index", :display_name => "username" }
16 get "/user/username/diary/comments/1"
17 assert_redirected_to "/user/username/diary/comments"
22 other_user = create(:user)
23 suspended_user = create(:user, :suspended)
24 deleted_user = create(:user, :deleted)
26 # Test a user with no comments
27 get diary_comments_path(:display_name => user.display_name)
28 assert_response :success
29 assert_template :index
30 assert_select "h4", :html => "No diary comments"
32 # Test a user with a comment
33 create(:diary_comment, :user => other_user)
35 get diary_comments_path(:display_name => other_user.display_name)
36 assert_response :success
37 assert_template :index
38 assert_dom "a[href='#{user_path(other_user)}']", :text => other_user.display_name
39 assert_select "table.table-striped tbody" do
40 assert_select "tr", :count => 1
43 # Test a suspended user
44 get diary_comments_path(:display_name => suspended_user.display_name)
45 assert_response :not_found
48 get diary_comments_path(:display_name => deleted_user.display_name)
49 assert_response :not_found
52 def test_index_invalid_paged
55 %w[-1 0 fred].each do |id|
56 get diary_comments_path(:display_name => user.display_name, :before => id)
57 assert_redirected_to :controller => :errors, :action => :bad_request
59 get diary_comments_path(:display_name => user.display_name, :after => id)
60 assert_redirected_to :controller => :errors, :action => :bad_request