]> git.openstreetmap.org Git - rails.git/blob - test/controllers/users/diary_comments_controller_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / controllers / users / diary_comments_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Users
6   class DiaryCommentsControllerTest < ActionDispatch::IntegrationTest
7     def setup
8       super
9       # Create the default language for diary entries
10       create(:language, :code => "en")
11     end
12
13     ##
14     # test all routes which lead to this controller
15     def test_routes
16       assert_routing(
17         { :path => "/user/username/diary_comments", :method => :get },
18         { :controller => "users/diary_comments", :action => "index", :user_display_name => "username" }
19       )
20
21       get "/user/username/diary/comments/1"
22       assert_redirected_to "/user/username/diary_comments"
23
24       get "/user/username/diary/comments"
25       assert_redirected_to "/user/username/diary_comments"
26     end
27
28     def test_index
29       user = create(:user)
30       other_user = create(:user)
31       suspended_user = create(:user, :suspended)
32       deleted_user = create(:user, :deleted)
33
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"
39
40       # Test a user with a comment
41       create(:diary_comment, :user => other_user)
42
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
49       end
50
51       # Test a suspended user
52       get user_diary_comments_path(suspended_user)
53       assert_response :not_found
54
55       # Test a deleted user
56       get user_diary_comments_path(deleted_user)
57       assert_response :not_found
58     end
59
60     def test_index_invalid_paged
61       user = create(:user)
62
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
66
67         get user_diary_comments_path(user, :after => id)
68         assert_redirected_to :controller => "/errors", :action => :bad_request
69       end
70     end
71   end
72 end