]> git.openstreetmap.org Git - rails.git/blob - test/controllers/notes_controller_test.rb
Move browse#new_note to notes#new
[rails.git] / test / controllers / notes_controller_test.rb
1 require "test_helper"
2
3 class NotesControllerTest < ActionDispatch::IntegrationTest
4   def setup
5     super
6     # Stub nominatim response for note locations
7     stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
8       .to_return(:status => 404)
9   end
10
11   ##
12   # test all routes which lead to this controller
13   def test_routes
14     assert_routing(
15       { :path => "/user/username/notes", :method => :get },
16       { :controller => "notes", :action => "index", :display_name => "username" }
17     )
18
19     assert_routing(
20       { :path => "/note/new", :method => :get },
21       { :controller => "notes", :action => "new" }
22     )
23   end
24
25   def test_index_success
26     first_user = create(:user)
27     second_user = create(:user)
28     moderator_user = create(:moderator_user)
29
30     create(:note) do |note|
31       create(:note_comment, :note => note, :author => first_user)
32     end
33     create(:note) do |note|
34       create(:note_comment, :note => note, :author => second_user)
35     end
36     create(:note, :status => "hidden") do |note|
37       create(:note_comment, :note => note, :author => second_user)
38     end
39
40     # Note that the table rows include a header row
41     get user_notes_path(:display_name => first_user.display_name)
42     assert_response :success
43     assert_select "table.note_list tr", :count => 2
44
45     get user_notes_path(:display_name => second_user.display_name)
46     assert_response :success
47     assert_select "table.note_list tr", :count => 2
48
49     get user_notes_path(:display_name => "non-existent")
50     assert_response :not_found
51
52     session_for(moderator_user)
53
54     get user_notes_path(:display_name => first_user.display_name)
55     assert_response :success
56     assert_select "table.note_list tr", :count => 2
57
58     get user_notes_path(:display_name => second_user.display_name)
59     assert_response :success
60     assert_select "table.note_list tr", :count => 3
61
62     get user_notes_path(:display_name => "non-existent")
63     assert_response :not_found
64   end
65
66   def test_index_paged
67     user = create(:user)
68
69     create_list(:note, 50) do |note|
70       create(:note_comment, :note => note, :author => user)
71     end
72
73     get user_notes_path(:display_name => user.display_name)
74     assert_response :success
75     assert_select "table.note_list tr", :count => 11
76
77     get user_notes_path(:display_name => user.display_name, :page => 2)
78     assert_response :success
79     assert_select "table.note_list tr", :count => 11
80   end
81
82   def test_empty_page
83     user = create(:user)
84     get user_notes_path(:display_name => user.display_name)
85     assert_response :success
86     assert_select "h4", :html => "No notes"
87   end
88
89   def test_new_note
90     get new_note_path
91     assert_response :success
92     assert_template "notes/new"
93   end
94 end