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 { :path => "/note/new", :method => :get },
21 { :controller => "notes", :action => "new" }
25 def test_index_success
26 first_user = create(:user)
27 second_user = create(:user)
28 moderator_user = create(:moderator_user)
30 create(:note) do |note|
31 create(:note_comment, :note => note, :author => first_user)
33 create(:note) do |note|
34 create(:note_comment, :note => note, :author => second_user)
36 create(:note, :status => "hidden") do |note|
37 create(:note_comment, :note => note, :author => second_user)
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
45 get user_notes_path(:display_name => second_user.display_name)
46 assert_response :success
47 assert_select "table.note_list tr", :count => 2
49 get user_notes_path(:display_name => "non-existent")
50 assert_response :not_found
52 session_for(moderator_user)
54 get user_notes_path(:display_name => first_user.display_name)
55 assert_response :success
56 assert_select "table.note_list tr", :count => 2
58 get user_notes_path(:display_name => second_user.display_name)
59 assert_response :success
60 assert_select "table.note_list tr", :count => 3
62 get user_notes_path(:display_name => "non-existent")
63 assert_response :not_found
69 create_list(:note, 50) do |note|
70 create(:note_comment, :note => note, :author => user)
73 get user_notes_path(:display_name => user.display_name)
74 assert_response :success
75 assert_select "table.note_list tr", :count => 11
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
84 get user_notes_path(:display_name => user.display_name)
85 assert_response :success
86 assert_select "h4", :html => "No notes"
91 assert_response :success
92 assert_template "notes/new"