1 # frozen_string_literal: true
6 class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
9 # Create the default language for diary entries
10 create(:language, :code => "en")
14 # test all routes which lead to this controller
17 { :path => "/user/username/diary_comments", :method => :get },
18 { :controller => "users/diary_comments", :action => "index", :user_display_name => "username" }
21 get "/user/username/diary/comments/1"
22 assert_redirected_to "/user/username/diary_comments"
24 get "/user/username/diary/comments"
25 assert_redirected_to "/user/username/diary_comments"
30 other_user = create(:user)
31 suspended_user = create(:user, :suspended)
32 deleted_user = create(:user, :deleted)
34 # Test a user with no comments
35 get user_diary_comments_path(user)
36 assert_response :success
37 assert_template :index
38 assert_select "h4", :html => "No comments"
40 # Test a user with a comment
41 create(:diary_comment, :user => other_user)
43 get user_diary_comments_path(other_user)
44 assert_response :success
45 assert_template :index
46 assert_dom "a[href='#{user_path(other_user)}']", :text => other_user.display_name
47 assert_select "table.table-striped tbody" do
48 assert_select "tr", :count => 1
51 # Test a suspended user
52 get user_diary_comments_path(suspended_user)
53 assert_response :not_found
56 get user_diary_comments_path(deleted_user)
57 assert_response :not_found
60 def test_index_invalid_paged
63 %w[-1 fred].each do |id|
64 get user_diary_comments_path(user, :before => id)
65 assert_redirected_to :controller => "/errors", :action => :bad_request
67 get user_diary_comments_path(user, :after => id)
68 assert_redirected_to :controller => "/errors", :action => :bad_request