3 class NotesControllerTest < ActionDispatch::IntegrationTest
6 # Stub nominatim response for note locations
7 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
8 .to_return(:status => 404)
12 # test all routes which lead to this controller
15 { :path => "/user/username/notes", :method => :get },
16 { :controller => "notes", :action => "index", :display_name => "username" }
20 def test_index_success
21 first_user = create(:user)
22 second_user = create(:user)
23 moderator_user = create(:moderator_user)
25 create(:note) do |note|
26 create(:note_comment, :note => note, :author => first_user)
28 create(:note) do |note|
29 create(:note_comment, :note => note, :author => second_user)
31 create(:note, :status => "hidden") do |note|
32 create(:note_comment, :note => note, :author => second_user)
35 # Note that the table rows include a header row
36 get user_notes_path(:display_name => first_user.display_name)
37 assert_response :success
38 assert_select "table.note_list tr", :count => 2
40 get user_notes_path(:display_name => second_user.display_name)
41 assert_response :success
42 assert_select "table.note_list tr", :count => 2
44 get user_notes_path(:display_name => "non-existent")
45 assert_response :not_found
47 session_for(moderator_user)
49 get user_notes_path(:display_name => first_user.display_name)
50 assert_response :success
51 assert_select "table.note_list tr", :count => 2
53 get user_notes_path(:display_name => second_user.display_name)
54 assert_response :success
55 assert_select "table.note_list tr", :count => 3
57 get user_notes_path(:display_name => "non-existent")
58 assert_response :not_found
64 create_list(:note, 50) do |note|
65 create(:note_comment, :note => note, :author => user)
68 get user_notes_path(:display_name => user.display_name)
69 assert_response :success
70 assert_select "table.note_list tr", :count => 11
72 get user_notes_path(:display_name => user.display_name, :page => 2)
73 assert_response :success
74 assert_select "table.note_list tr", :count => 11
79 get user_notes_path(:display_name => user.display_name)
80 assert_response :success
81 assert_select "h4", :html => "No notes"