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 => "/query", :method => :get },
33 { :controller => "browse", :action => "query" }
37 def test_read_relation
38 relation = create(:relation)
39 sidebar_browse_check :relation_path, relation.id, "browse/feature"
40 assert_select "h4", /^Version/ do
41 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
43 assert_select ".secondary-actions a[href='#{api_relation_path relation}']", :count => 1
44 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
45 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
48 def test_multiple_version_relation_links
49 relation = create(:relation, :with_history, :version => 2)
50 sidebar_browse_check :relation_path, relation.id, "browse/feature"
51 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
52 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
53 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
56 def test_read_relation_history
57 relation = create(:relation, :with_history)
58 sidebar_browse_check :relation_history_path, relation.id, "browse/history"
59 assert_select "h4", /^Version/ do
60 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
66 sidebar_browse_check :way_path, way.id, "browse/feature"
67 assert_select "h4", /^Version/ do
68 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
70 assert_select ".secondary-actions a[href='#{api_way_path way}']", :count => 1
71 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
72 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
75 def test_multiple_version_way_links
76 way = create(:way, :with_history, :version => 2)
77 sidebar_browse_check :way_path, way.id, "browse/feature"
78 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
79 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
80 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
83 def test_read_way_history
84 way = create(:way, :with_history)
85 sidebar_browse_check :way_history_path, way.id, "browse/history"
86 assert_select "h4", /^Version/ do
87 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
93 sidebar_browse_check :node_path, node.id, "browse/feature"
94 assert_select "h4", /^Version/ do
95 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
97 assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1
98 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
99 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
102 def test_multiple_version_node_links
103 node = create(:node, :with_history, :version => 2)
104 sidebar_browse_check :node_path, node.id, "browse/feature"
105 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
106 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
107 assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
110 def test_read_deleted_node
111 node = create(:node, :visible => false)
112 sidebar_browse_check :node_path, node.id, "browse/feature"
113 assert_select "h4", /^Version/ do
114 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
116 assert_select "a[href='#{api_node_path node}']", :count => 0
119 def test_read_node_history
120 node = create(:node, :with_history)
121 sidebar_browse_check :node_history_path, node.id, "browse/history"
122 assert_select "h4", /^Version/ do
123 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
128 # Methods to check redaction.
130 # note that these are presently highly reliant on the structure of the
131 # page for the selection tests, which doesn't work out particularly
132 # well if that structure changes. so... if you change the page layout
133 # then please make it more easily (and robustly) testable!
135 def test_redacted_node
136 node = create(:node, :with_history, :deleted, :version => 2)
137 node_v1 = node.old_nodes.find_by(:version => 1)
138 node_v1.redact!(create(:redaction))
140 get node_path(:id => node)
141 assert_response :success
142 assert_template "feature"
144 # check that we don't show lat/lon for a redacted node.
145 assert_select ".browse-section", 1
146 assert_select ".browse-section.browse-node", 1
147 assert_select ".browse-section.browse-node .latitude", 0
148 assert_select ".browse-section.browse-node .longitude", 0
151 def test_redacted_node_history
152 node = create(:node, :with_history, :deleted, :version => 2)
153 node_v1 = node.old_nodes.find_by(:version => 1)
154 node_v1.redact!(create(:redaction))
156 get node_history_path(:id => node)
157 assert_response :success
158 assert_template "browse/history"
160 # there are 2 revisions of the redacted node, but only one
161 # should be showing details here.
162 assert_select ".browse-section", 2
163 assert_select ".browse-section.browse-redacted", 1
164 assert_select ".browse-section.browse-node", 1
165 assert_select ".browse-section.browse-node .latitude", 0
166 assert_select ".browse-section.browse-node .longitude", 0
169 def test_redacted_node_unredacted_history
170 session_for(create(:moderator_user))
171 node = create(:node, :with_history, :deleted, :version => 2)
172 node_v1 = node.old_nodes.find_by(:version => 1)
173 node_v1.redact!(create(:redaction))
175 get node_history_path(:id => node, :params => { :show_redactions => true })
176 assert_response :success
177 assert_template "browse/history"
179 assert_select ".browse-section", 2
180 assert_select ".browse-section.browse-redacted", 0
181 assert_select ".browse-section.browse-node", 2
184 def test_redacted_way_history
185 way = create(:way, :with_history, :version => 4)
186 way_v1 = way.old_ways.find_by(:version => 1)
187 way_v1.redact!(create(:redaction))
188 way_v3 = way.old_ways.find_by(:version => 3)
189 way_v3.redact!(create(:redaction))
191 get way_history_path(:id => way)
192 assert_response :success
193 assert_template "browse/history"
195 # there are 4 revisions of the redacted way, but only 2
196 # should be showing details here.
197 assert_select ".browse-section", 4
198 assert_select ".browse-section.browse-redacted", 2
199 assert_select ".browse-section.browse-way", 2
202 def test_redacted_way_unredacted_history
203 session_for(create(:moderator_user))
204 way = create(:way, :with_history, :version => 4)
205 way_v1 = way.old_ways.find_by(:version => 1)
206 way_v1.redact!(create(:redaction))
207 way_v3 = way.old_ways.find_by(:version => 3)
208 way_v3.redact!(create(:redaction))
210 get way_history_path(:id => way, :params => { :show_redactions => true })
211 assert_response :success
212 assert_template "browse/history"
214 assert_select ".browse-section", 4
215 assert_select ".browse-section.browse-redacted", 0
216 assert_select ".browse-section.browse-way", 4
219 def test_redacted_relation_history
220 relation = create(:relation, :with_history, :version => 4)
221 relation_v1 = relation.old_relations.find_by(:version => 1)
222 relation_v1.redact!(create(:redaction))
223 relation_v3 = relation.old_relations.find_by(:version => 3)
224 relation_v3.redact!(create(:redaction))
226 get relation_history_path(:id => relation)
227 assert_response :success
228 assert_template "browse/history"
230 # there are 4 revisions of the redacted relation, but only 2
231 # should be showing details here.
232 assert_select ".browse-section", 4
233 assert_select ".browse-section.browse-redacted", 2
234 assert_select ".browse-section.browse-relation", 2
237 def test_redacted_relation_unredacted_history
238 session_for(create(:moderator_user))
239 relation = create(:relation, :with_history, :version => 4)
240 relation_v1 = relation.old_relations.find_by(:version => 1)
241 relation_v1.redact!(create(:redaction))
242 relation_v3 = relation.old_relations.find_by(:version => 3)
243 relation_v3.redact!(create(:redaction))
245 get relation_history_path(:id => relation, :params => { :show_redactions => true })
246 assert_response :success
247 assert_template "browse/history"
249 assert_select ".browse-section", 4
250 assert_select ".browse-section.browse-redacted", 0
251 assert_select ".browse-section.browse-relation", 4
256 assert_response :success
257 assert_template "browse/query"
260 def test_anonymous_user_feature_page_secondary_actions
261 node = create(:node, :with_history)
262 get node_path(:id => node)
263 assert_response :success
264 assert_select ".secondary-actions a", :text => "View Details", :count => 0
265 assert_select ".secondary-actions a", :text => "View History", :count => 1
266 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
269 def test_regular_user_feature_page_secondary_actions
270 session_for(create(:user))
271 node = create(:node, :with_history)
272 get node_path(:id => node)
273 assert_response :success
274 assert_select ".secondary-actions a", :text => "View Details", :count => 0
275 assert_select ".secondary-actions a", :text => "View History", :count => 1
276 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
279 def test_moderator_user_feature_page_secondary_actions
280 session_for(create(:moderator_user))
281 node = create(:node, :with_history)
282 get node_path(:id => node)
283 assert_response :success
284 assert_select ".secondary-actions a", :text => "View Details", :count => 0
285 assert_select ".secondary-actions a", :text => "View History", :count => 1
286 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
289 def test_anonymous_user_history_page_secondary_actions
290 node = create(:node, :with_history)
291 get node_history_path(:id => node)
292 assert_response :success
293 assert_select ".secondary-actions a", :text => "View Details", :count => 1
294 assert_select ".secondary-actions a", :text => "View History", :count => 0
295 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
298 def test_regular_user_history_page_secondary_actions
299 session_for(create(:user))
300 node = create(:node, :with_history)
301 get node_history_path(:id => node)
302 assert_response :success
303 assert_select ".secondary-actions a", :text => "View Details", :count => 1
304 assert_select ".secondary-actions a", :text => "View History", :count => 0
305 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
308 def test_moderator_user_history_page_secondary_actions
309 session_for(create(:moderator_user))
310 node = create(:node, :with_history)
311 get node_history_path(:id => node)
312 assert_response :success
313 assert_select ".secondary-actions a", :text => "View Details", :count => 1
314 assert_select ".secondary-actions a", :text => "View History", :count => 0
315 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
318 def test_anonymous_user_unredacted_history_page_secondary_actions
319 node = create(:node, :with_history)
320 get node_history_path(:id => node, :params => { :show_redactions => true })
321 assert_response :redirect
324 def test_regular_user_unredacted_history_page_secondary_actions
325 session_for(create(:user))
326 node = create(:node, :with_history)
327 get node_history_path(:id => node, :params => { :show_redactions => true })
328 assert_response :redirect
331 def test_moderator_user_unredacted_history_page_secondary_actions
332 session_for(create(:moderator_user))
333 node = create(:node, :with_history)
334 get node_history_path(:id => node, :params => { :show_redactions => true })
335 assert_response :success
336 assert_select ".secondary-actions a", :text => "View Details", :count => 1
337 assert_select ".secondary-actions a", :text => "View History", :count => 1
338 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0