3 class NotesControllerTest < ActionController::TestCase
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 => "mine", :display_name => "username" }
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 :mine, :params => { :display_name => first_user.display_name }
37 assert_response :success
38 assert_select "table.note_list tr", :count => 2
40 get :mine, :params => { :display_name => second_user.display_name }
41 assert_response :success
42 assert_select "table.note_list tr", :count => 2
44 get :mine, :params => { :display_name => "non-existent" }
45 assert_response :not_found
47 session[:user] = moderator_user.id
49 get :mine, :params => { :display_name => first_user.display_name }
50 assert_response :success
51 assert_select "table.note_list tr", :count => 2
53 get :mine, :params => { :display_name => second_user.display_name }
54 assert_response :success
55 assert_select "table.note_list tr", :count => 3
57 get :mine, :params => { :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 :mine, :params => { :display_name => user.display_name }
69 assert_response :success
70 assert_select "table.note_list tr", :count => 11
72 get :mine, :params => { :display_name => user.display_name, :page => 2 }
73 assert_response :success
74 assert_select "table.note_list tr", :count => 11