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"
66 browse_check :node_path, create(:node).id, "browse/feature"
69 def test_read_node_history
70 browse_check :node_history_path, create(:node, :with_history).id, "browse/history"
73 def test_read_changeset
75 changeset = create(:changeset, :user => user)
76 create(:changeset, :user => user)
77 browse_check :changeset_path, changeset.id, "browse/changeset"
80 def test_read_private_changeset
82 changeset = create(:changeset, :user => create(:user, :data_public => false))
83 create(:changeset, :user => user)
84 browse_check :changeset_path, changeset.id, "browse/changeset"
87 def test_read_changeset_hidden_comments
88 changeset = create(:changeset)
89 create_list(:changeset_comment, 3, :changeset => changeset)
90 create(:changeset_comment, :visible => false, :changeset => changeset)
92 browse_check :changeset_path, changeset.id, "browse/changeset"
93 assert_select "div.changeset-comments ul li", :count => 3
95 session_for(create(:moderator_user))
97 browse_check :changeset_path, changeset.id, "browse/changeset"
98 assert_select "div.changeset-comments ul li", :count => 4
102 open_note = create(:note_with_comments)
104 browse_check :browse_note_path, open_note.id, "browse/note"
107 def test_read_hidden_note
108 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
110 get browse_note_path(:id => hidden_note_with_comment)
111 assert_response :not_found
112 assert_template "browse/not_found"
113 assert_template :layout => "map"
115 get browse_note_path(:id => hidden_note_with_comment), :xhr => true
116 assert_response :not_found
117 assert_template "browse/not_found"
118 assert_template :layout => "xhr"
120 session_for(create(:moderator_user))
122 browse_check :browse_note_path, hidden_note_with_comment.id, "browse/note"
125 def test_read_note_hidden_comments
126 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
127 create(:note_comment, :note => note, :visible => false)
130 browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
131 assert_select "div.note-comments ul li", :count => 1
133 session_for(create(:moderator_user))
135 browse_check :browse_note_path, note_with_hidden_comment.id, "browse/note"
136 assert_select "div.note-comments ul li", :count => 2
139 def test_read_note_hidden_user_comment
140 hidden_user = create(:user, :status => "deleted")
141 note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
142 create(:note_comment, :note => note, :author => hidden_user)
145 browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
146 assert_select "div.note-comments ul li", :count => 1
148 session_for(create(:moderator_user))
150 browse_check :browse_note_path, note_with_hidden_user_comment.id, "browse/note"
151 assert_select "div.note-comments ul li", :count => 1
155 # Methods to check redaction.
157 # note that these are presently highly reliant on the structure of the
158 # page for the selection tests, which doesn't work out particularly
159 # well if that structure changes. so... if you change the page layout
160 # then please make it more easily (and robustly) testable!
162 def test_redacted_node
163 node = create(:node, :with_history, :deleted, :version => 2)
164 node_v1 = node.old_nodes.find_by(:version => 1)
165 node_v1.redact!(create(:redaction))
167 get node_path(:id => node)
168 assert_response :success
169 assert_template "feature"
171 # check that we don't show lat/lon for a redacted node.
172 assert_select ".browse-section", 1
173 assert_select ".browse-section.browse-node", 1
174 assert_select ".browse-section.browse-node .latitude", 0
175 assert_select ".browse-section.browse-node .longitude", 0
178 def test_redacted_node_history
179 node = create(:node, :with_history, :deleted, :version => 2)
180 node_v1 = node.old_nodes.find_by(:version => 1)
181 node_v1.redact!(create(:redaction))
183 get node_history_path(:id => node)
184 assert_response :success
185 assert_template "browse/history"
187 # there are 2 revisions of the redacted node, but only one
188 # should be showing details here.
189 assert_select ".browse-section", 2
190 assert_select ".browse-section.browse-redacted", 1
191 assert_select ".browse-section.browse-node", 1
192 assert_select ".browse-section.browse-node .latitude", 0
193 assert_select ".browse-section.browse-node .longitude", 0
196 def test_redacted_way_history
197 way = create(:way, :with_history, :version => 4)
198 way_v1 = way.old_ways.find_by(:version => 1)
199 way_v1.redact!(create(:redaction))
200 way_v3 = way.old_ways.find_by(:version => 3)
201 way_v3.redact!(create(:redaction))
203 get way_history_path(:id => way)
204 assert_response :success
205 assert_template "browse/history"
207 # there are 4 revisions of the redacted way, but only 2
208 # should be showing details here.
209 assert_select ".browse-section", 4
210 assert_select ".browse-section.browse-redacted", 2
211 assert_select ".browse-section.browse-way", 2
214 def test_redacted_relation_history
215 relation = create(:relation, :with_history, :version => 4)
216 relation_v1 = relation.old_relations.find_by(:version => 1)
217 relation_v1.redact!(create(:redaction))
218 relation_v3 = relation.old_relations.find_by(:version => 3)
219 relation_v3.redact!(create(:redaction))
221 get relation_history_path(:id => relation)
222 assert_response :success
223 assert_template "browse/history"
225 # there are 4 revisions of the redacted relation, but only 2
226 # should be showing details here.
227 assert_select ".browse-section", 4
228 assert_select ".browse-section.browse-redacted", 2
229 assert_select ".browse-section.browse-relation", 2
234 assert_response :success
235 assert_template "browse/new_note"
240 assert_response :success
241 assert_template "browse/query"
246 # This is a convenience method for most of the above checks
247 # First we check that when we don't have an id, it will correctly return a 404
248 # then we check that we get the correct 404 when a non-existant id is passed
249 # then we check that it will get a successful response, when we do pass an id
250 def browse_check(path, id, template)
251 path_method = method(path)
253 assert_raise ActionController::UrlGenerationError do
257 assert_raise ActionController::UrlGenerationError do
258 get path_method.call(:id => -10) # we won't have an id that's negative
261 get path_method.call(:id => 0)
262 assert_response :not_found
263 assert_template "browse/not_found"
264 assert_template :layout => "map"
266 get path_method.call(:id => 0), :xhr => true
267 assert_response :not_found
268 assert_template "browse/not_found"
269 assert_template :layout => "xhr"
271 get path_method.call(:id => id)
272 assert_response :success
273 assert_template template
274 assert_template :layout => "map"
276 get path_method.call(:id => id), :xhr => true
277 assert_response :success
278 assert_template template
279 assert_template :layout => "xhr"