3 class NotesControllerTest < ActionController::TestCase
5 # Stub nominatim response for note locations
6 stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
7 .to_return(:status => 404)
11 # test all routes which lead to this controller
14 { :path => "/user/username/notes", :method => :get },
15 { :controller => "notes", :action => "mine", :display_name => "username" }
20 first_user = create(:user)
21 second_user = create(:user)
22 moderator_user = create(:moderator_user)
24 create(:note) do |note|
25 create(:note_comment, :note => note, :author => first_user)
27 create(:note) do |note|
28 create(:note_comment, :note => note, :author => second_user)
30 create(:note, :status => "hidden") do |note|
31 create(:note_comment, :note => note, :author => second_user)
34 # Note that the table rows include a header row
35 get :mine, :params => { :display_name => first_user.display_name }
36 assert_response :success
37 assert_select "table.note_list tr", :count => 2
39 get :mine, :params => { :display_name => second_user.display_name }
40 assert_response :success
41 assert_select "table.note_list tr", :count => 2
43 get :mine, :params => { :display_name => "non-existent" }
44 assert_response :not_found
46 session[:user] = moderator_user.id
48 get :mine, :params => { :display_name => first_user.display_name }
49 assert_response :success
50 assert_select "table.note_list tr", :count => 2
52 get :mine, :params => { :display_name => second_user.display_name }
53 assert_response :success
54 assert_select "table.note_list tr", :count => 3
56 get :mine, :params => { :display_name => "non-existent" }
57 assert_response :not_found
63 create_list(:note, 50) do |note|
64 create(:note_comment, :note => note, :author => user)
67 get :mine, :params => { :display_name => user.display_name }
68 assert_response :success
69 assert_select "table.note_list tr", :count => 11
71 get :mine, :params => { :display_name => user.display_name, :page => 2 }
72 assert_response :success
73 assert_select "table.note_list tr", :count => 11