3 class BrowseControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/node/1", :method => :get },
9 { :controller => "browse", :action => "node", :id => "1" }
12 { :path => "/node/1/history", :method => :get },
13 { :controller => "browse", :action => "node_history", :id => "1" }
16 { :path => "/way/1", :method => :get },
17 { :controller => "browse", :action => "way", :id => "1" }
20 { :path => "/way/1/history", :method => :get },
21 { :controller => "browse", :action => "way_history", :id => "1" }
24 { :path => "/relation/1", :method => :get },
25 { :controller => "browse", :action => "relation", :id => "1" }
28 { :path => "/relation/1/history", :method => :get },
29 { :controller => "browse", :action => "relation_history", :id => "1" }
32 { :path => "/changeset/1", :method => :get },
33 { :controller => "browse", :action => "changeset", :id => "1" }
36 { :path => "/note/1", :method => :get },
37 { :controller => "browse", :action => "note", :id => "1" }
40 { :path => "/note/new", :method => :get },
41 { :controller => "browse", :action => "new_note" }
44 { :path => "/query", :method => :get },
45 { :controller => "browse", :action => "query" }
49 def test_read_relation
50 browse_check :relation_path, create(:relation).id, "browse/feature"
53 def test_read_relation_history
54 browse_check :relation_history_path, create(:relation, :with_history).id, "browse/history"
58 browse_check :way_path, create(:way).id, "browse/feature"
61 def test_read_way_history
62 browse_check :way_history_path, create(:way, :with_history).id, "browse/history"
67 browse_check :node_path, node.id, "browse/feature"
68 assert_select "a[href='#{api_node_path node}']", :count => 1
71 def test_read_deleted_node
72 node = create :node, :visible => false
73 browse_check :node_path, node.id, "browse/feature"
74 assert_select "a[href='#{api_node_path node}']", :count => 0
77 def test_read_node_history
78 browse_check :node_history_path, create(:node, :with_history).id, "browse/history"
81 def test_read_changeset
83 changeset = create(:changeset, :user => user)
84 create(:changeset, :user => user)
85 browse_check :changeset_path, changeset.id, "browse/changeset"
88 def test_read_private_changeset
90 changeset = create(:changeset, :user => create(:user, :data_public => false))
91 create(:changeset, :user => user)
92 browse_check :changeset_path, changeset.id, "browse/changeset"
95 def test_read_changeset_hidden_comments
96 changeset = create(:changeset)
97 create_list(:changeset_comment, 3, :changeset => changeset)
98 create(:changeset_comment, :visible => false, :changeset => changeset)
100 browse_check :changeset_path, changeset.id, "browse/changeset"
101 assert_select "div.changeset-comments ul li", :count => 3
103 session_for(create(:moderator_user))
105 browse_check :changeset_path, changeset.id, "browse/changeset"
106 assert_select "div.changeset-comments ul li", :count => 4
110 open_note = create(:note_with_comments)
112 browse_check :browse_note_path, open_note.id, "browse/note"
115 def test_read_hidden_note
116 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
118 get browse_note_path(:id => hidden_note_with_comment)
119 assert_response :not_found
120 assert_template "browse/not_found"
121 assert_template :layout => "map"
123 get browse_note_path(:id => hidden_note_with_comment), :xhr => true
124 assert_response :not_found
125 assert_template "browse/not_found"
126 assert_template :layout => "xhr"
128 session_for(create(:moderator_user))
130 browse_check :browse_note_path, hidden_note_with_comment.id, "browse/note"
133 def test_read_note_hidden_comments
134 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
135 create(:note_comment, :note => note, :visible => false)
138 browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
139 assert_select "div.note-comments ul li", :count => 1
141 session_for(create(:moderator_user))
143 browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
144 assert_select "div.note-comments ul li", :count => 2
147 def test_read_note_hidden_user_comment
148 hidden_user = create(:user, :deleted)
149 note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
150 create(:note_comment, :note => note, :author => hidden_user)
153 browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
154 assert_select "div.note-comments ul li", :count => 1
156 session_for(create(:moderator_user))
158 browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
159 assert_select "div.note-comments ul li", :count => 1
162 def test_read_closed_note
164 closed_note = create(:note_with_comments, :status => "closed", :closed_at => Time.now.utc, :comments_count => 2) do |note|
165 create(:note_comment, :event => "closed", :note => note, :author => user)
168 browse_check :browse_note_path, closed_note.id, "browse/note"
169 assert_select "div.note-comments ul li", :count => 2
170 assert_select "div.details", /Resolved by #{user.display_name}/
176 browse_check :browse_note_path, closed_note.id, "browse/note"
177 assert_select "div.note-comments ul li", :count => 1
178 assert_select "div.details", /Resolved by deleted/
182 # Methods to check redaction.
184 # note that these are presently highly reliant on the structure of the
185 # page for the selection tests, which doesn't work out particularly
186 # well if that structure changes. so... if you change the page layout
187 # then please make it more easily (and robustly) testable!
189 def test_redacted_node
190 node = create(:node, :with_history, :deleted, :version => 2)
191 node_v1 = node.old_nodes.find_by(:version => 1)
192 node_v1.redact!(create(:redaction))
194 get node_path(:id => node)
195 assert_response :success
196 assert_template "feature"
198 # check that we don't show lat/lon for a redacted node.
199 assert_select ".browse-section", 1
200 assert_select ".browse-section.browse-node", 1
201 assert_select ".browse-section.browse-node .latitude", 0
202 assert_select ".browse-section.browse-node .longitude", 0
205 def test_redacted_node_history
206 node = create(:node, :with_history, :deleted, :version => 2)
207 node_v1 = node.old_nodes.find_by(:version => 1)
208 node_v1.redact!(create(:redaction))
210 get node_history_path(:id => node)
211 assert_response :success
212 assert_template "browse/history"
214 # there are 2 revisions of the redacted node, but only one
215 # should be showing details here.
216 assert_select ".browse-section", 2
217 assert_select ".browse-section.browse-redacted", 1
218 assert_select ".browse-section.browse-node", 1
219 assert_select ".browse-section.browse-node .latitude", 0
220 assert_select ".browse-section.browse-node .longitude", 0
223 def test_redacted_way_history
224 way = create(:way, :with_history, :version => 4)
225 way_v1 = way.old_ways.find_by(:version => 1)
226 way_v1.redact!(create(:redaction))
227 way_v3 = way.old_ways.find_by(:version => 3)
228 way_v3.redact!(create(:redaction))
230 get way_history_path(:id => way)
231 assert_response :success
232 assert_template "browse/history"
234 # there are 4 revisions of the redacted way, but only 2
235 # should be showing details here.
236 assert_select ".browse-section", 4
237 assert_select ".browse-section.browse-redacted", 2
238 assert_select ".browse-section.browse-way", 2
241 def test_redacted_relation_history
242 relation = create(:relation, :with_history, :version => 4)
243 relation_v1 = relation.old_relations.find_by(:version => 1)
244 relation_v1.redact!(create(:redaction))
245 relation_v3 = relation.old_relations.find_by(:version => 3)
246 relation_v3.redact!(create(:redaction))
248 get relation_history_path(:id => relation)
249 assert_response :success
250 assert_template "browse/history"
252 # there are 4 revisions of the redacted relation, but only 2
253 # should be showing details here.
254 assert_select ".browse-section", 4
255 assert_select ".browse-section.browse-redacted", 2
256 assert_select ".browse-section.browse-relation", 2
261 assert_response :success
262 assert_template "browse/new_note"
267 assert_response :success
268 assert_template "browse/query"
273 # This is a convenience method for most of the above checks
274 # First we check that when we don't have an id, it will correctly return a 404
275 # then we check that we get the correct 404 when a non-existant id is passed
276 # then we check that it will get a successful response, when we do pass an id
277 def browse_check(path, id, template)
278 path_method = method(path)
280 assert_raise ActionController::UrlGenerationError do
284 assert_raise ActionController::UrlGenerationError do
285 get path_method.call(:id => -10) # we won't have an id that's negative
288 get path_method.call(:id => 0)
289 assert_response :not_found
290 assert_template "browse/not_found"
291 assert_template :layout => "map"
293 get path_method.call(:id => 0), :xhr => true
294 assert_response :not_found
295 assert_template "browse/not_found"
296 assert_template :layout => "xhr"
298 get path_method.call(:id => id)
299 assert_response :success
300 assert_template template
301 assert_template :layout => "map"
303 get path_method.call(:id => id), :xhr => true
304 assert_response :success
305 assert_template template
306 assert_template :layout => "xhr"