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" }
19 { :path => "/note/1", :method => :get },
20 { :controller => "notes", :action => "show", :id => "1" }
23 { :path => "/note/new", :method => :get },
24 { :controller => "notes", :action => "new" }
28 def test_index_success
29 first_user = create(:user)
30 second_user = create(:user)
31 moderator_user = create(:moderator_user)
33 create(:note) do |note|
34 create(:note_comment, :note => note, :author => first_user)
36 create(:note) do |note|
37 create(:note_comment, :note => note, :author => second_user)
39 create(:note, :status => "hidden") do |note|
40 create(:note_comment, :note => note, :author => second_user)
43 get user_notes_path(first_user)
44 assert_response :success
45 assert_select ".content-heading a[href='#{user_path first_user}']", :text => first_user.display_name
46 assert_select "table.note_list tbody tr", :count => 1
48 get user_notes_path(second_user)
49 assert_response :success
50 assert_select ".content-heading a[href='#{user_path second_user}']", :text => second_user.display_name
51 assert_select "table.note_list tbody tr", :count => 1
53 get user_notes_path("non-existent")
54 assert_response :not_found
56 session_for(moderator_user)
58 get user_notes_path(first_user)
59 assert_response :success
60 assert_select "table.note_list tbody tr", :count => 1
62 get user_notes_path(second_user)
63 assert_response :success
64 assert_select "table.note_list tbody tr", :count => 2
66 get user_notes_path("non-existent")
67 assert_response :not_found
73 create_list(:note, 50) do |note|
74 create(:note_comment, :note => note, :author => user)
77 get user_notes_path(user)
78 assert_response :success
79 assert_select "table.note_list tbody tr", :count => 10
81 get user_notes_path(user, :page => 2)
82 assert_response :success
83 assert_select "table.note_list tbody tr", :count => 10
88 get user_notes_path(user)
89 assert_response :success
90 assert_select "h4", :html => "No notes"
94 open_note = create(:note_with_comments)
96 sidebar_browse_check :note_path, open_note.id, "notes/show"
99 def test_read_hidden_note
100 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
102 get note_path(hidden_note_with_comment)
103 assert_response :not_found
104 assert_template "browse/not_found"
105 assert_template :layout => "map"
107 get note_path(hidden_note_with_comment), :xhr => true
108 assert_response :not_found
109 assert_template "browse/not_found"
110 assert_template :layout => "xhr"
112 session_for(create(:moderator_user))
114 sidebar_browse_check :note_path, hidden_note_with_comment.id, "notes/show"
117 def test_read_note_hidden_comments
118 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
119 create(:note_comment, :note => note, :visible => false)
122 sidebar_browse_check :note_path, note_with_hidden_comment.id, "notes/show"
123 assert_select "div.note-comments ul li", :count => 1
125 session_for(create(:moderator_user))
127 sidebar_browse_check :note_path, note_with_hidden_comment.id, "notes/show"
128 assert_select "div.note-comments ul li", :count => 2
131 def test_read_note_hidden_user_comment
132 hidden_user = create(:user, :deleted)
133 note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
134 create(:note_comment, :note => note, :author => hidden_user)
137 sidebar_browse_check :note_path, note_with_hidden_user_comment.id, "notes/show"
138 assert_select "div.note-comments ul li", :count => 1
140 session_for(create(:moderator_user))
142 sidebar_browse_check :note_path, note_with_hidden_user_comment.id, "notes/show"
143 assert_select "div.note-comments ul li", :count => 1
146 def test_read_closed_note
148 closed_note = create(:note_with_comments, :closed, :closed_by => user, :comments_count => 2)
150 sidebar_browse_check :note_path, closed_note.id, "notes/show"
151 assert_select "div.note-comments ul li", :count => 2
152 assert_select "div.details", /Resolved by #{user.display_name}/
158 sidebar_browse_check :note_path, closed_note.id, "notes/show"
159 assert_select "div.note-comments ul li", :count => 1
160 assert_select "div.details", /Resolved by deleted/
165 assert_response :success
166 assert_template "notes/new"