1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class ElementOldVersionTest < ApplicationSystemTestCase
6 test "shows a node with one version" do
7 node = create(:node, :with_history, :lat => 60, :lon => 30)
9 visit old_node_path(node, 1)
12 assert_css "h2", :text => "Node: #{node.id}"
13 assert_css "h4", :text => "Version #1"
14 assert_text(/Location: 60\.\d+, 30\.\d+/)
16 assert_link "Download XML", :href => api_node_version_path(node, 1)
17 assert_link "Node", :href => node_path(node)
18 assert_link "History", :exact => true, :href => node_history_path(node)
22 test "shows a way with one version" do
23 way = create(:way, :with_history)
25 visit old_way_path(way, 1)
28 assert_css "h2", :text => "Way: #{way.id}"
29 assert_css "h4", :text => "Version #1"
31 assert_link "Download XML", :href => api_way_version_path(way, 1)
32 assert_link "Way", :href => way_path(way)
33 assert_link "History", :exact => true, :href => way_history_path(way)
37 test "shows a relation with one version" do
38 relation = create(:relation, :with_history)
40 visit old_relation_path(relation, 1)
43 assert_css "h2", :text => "Relation: #{relation.id}"
44 assert_css "h4", :text => "Version #1"
46 assert_link "Download XML", :href => api_relation_version_path(relation, 1)
47 assert_link "Relation", :href => relation_path(relation)
48 assert_link "History", :exact => true, :href => relation_history_path(relation)
52 test "shows a node with two versions" do
53 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
54 node.old_nodes.find_by(:version => 1).update(:lat => 59, :lon => 29)
56 visit old_node_path(node, 1)
59 assert_css "h2", :text => "Node: #{node.id}"
60 assert_css "h4", :text => "Version #1"
61 assert_text(/Location: 59\.\d+, 29\.\d+/)
63 assert_link "Download XML", :href => api_node_version_path(node, 1)
64 assert_link "Node", :href => node_path(node)
65 assert_link "History", :exact => true, :href => node_history_path(node)
69 assert_css "h2", :text => "Node: #{node.id}"
70 assert_css "h4", :text => "Version #2"
71 assert_text(/Location: 60\.\d+, 30\.\d+/)
73 assert_link "Download XML", :href => api_node_version_path(node, 2)
74 assert_link "Node", :href => node_path(node)
75 assert_link "History", :exact => true, :href => node_history_path(node)
79 test "shows a way with two versions" do
80 way = create(:way, :with_history, :version => 2)
82 visit old_way_path(way, 1)
85 assert_css "h2", :text => "Way: #{way.id}"
86 assert_css "h4", :text => "Version #1"
88 assert_link "Download XML", :href => api_way_version_path(way, 1)
89 assert_link "Way", :href => way_path(way)
90 assert_link "History", :exact => true, :href => way_history_path(way)
94 assert_css "h2", :text => "Way: #{way.id}"
95 assert_css "h4", :text => "Version #2"
97 assert_link "Download XML", :href => api_way_version_path(way, 2)
98 assert_link "Way", :href => way_path(way)
99 assert_link "History", :exact => true, :href => way_history_path(way)
103 test "shows a relation with two versions" do
104 relation = create(:relation, :with_history, :version => 2)
106 visit old_relation_path(relation, 1)
109 assert_css "h2", :text => "Relation: #{relation.id}"
110 assert_css "h4", :text => "Version #1"
112 assert_link "Download XML", :href => api_relation_version_path(relation, 1)
113 assert_link "Relation", :href => relation_path(relation)
114 assert_link "History", :exact => true, :href => relation_history_path(relation)
116 click_on "Version #2"
118 assert_css "h2", :text => "Relation: #{relation.id}"
119 assert_css "h4", :text => "Version #2"
121 assert_link "Download XML", :href => api_relation_version_path(relation, 2)
122 assert_link "Relation", :href => relation_path(relation)
123 assert_link "History", :exact => true, :href => relation_history_path(relation)
127 test "show a redacted node version" do
128 node = create_redacted_node
130 visit old_node_path(node, 1)
133 assert_css "h2", :text => "Node: #{node.id}"
134 assert_text "Version 1 of this node cannot be shown"
135 assert_no_text "Location"
136 assert_no_text "TOP SECRET"
138 assert_no_link "Download XML"
139 assert_no_link "View Redacted Data"
140 assert_link "Node", :href => node_path(node)
141 assert_link "History", :exact => true, :href => node_history_path(node)
145 test "show a redacted way version" do
146 way = create_redacted_way
148 visit old_way_path(way, 1)
151 assert_css "h2", :text => "Way: #{way.id}"
152 assert_text "Version 1 of this way cannot be shown"
153 assert_no_text "Location"
154 assert_no_text "TOP SECRET"
156 assert_no_link "Download XML"
157 assert_no_link "View Redacted Data"
158 assert_link "Way", :href => way_path(way)
159 assert_link "History", :exact => true, :href => way_history_path(way)
163 test "show a redacted relation version" do
164 relation = create_redacted_relation
166 visit old_relation_path(relation, 1)
169 assert_css "h2", :text => "Relation: #{relation.id}"
170 assert_text "Version 1 of this relation cannot be shown"
171 assert_no_text "Location"
172 assert_no_text "TOP SECRET"
174 assert_no_link "Download XML"
175 assert_no_link "View Redacted Data"
176 assert_link "Relation", :href => relation_path(relation)
177 assert_link "History", :exact => true, :href => relation_history_path(relation)
181 test "show a redacted node version to a regular user" do
182 node = create_redacted_node
184 sign_in_as(create(:user))
185 visit old_node_path(node, 1)
188 assert_css "h2", :text => "Node: #{node.id}"
189 assert_text "Version 1 of this node cannot be shown"
190 assert_no_text "Location"
191 assert_no_text "TOP SECRET"
193 assert_no_link "Download XML"
194 assert_no_link "View Redacted Data"
195 assert_link "Node", :href => node_path(node)
196 assert_link "History", :exact => true, :href => node_history_path(node)
200 test "show a redacted way version to a regular user" do
201 way = create_redacted_way
203 sign_in_as(create(:user))
204 visit old_way_path(way, 1)
207 assert_css "h2", :text => "Way: #{way.id}"
208 assert_text "Version 1 of this way cannot be shown"
209 assert_no_text "Location"
210 assert_no_text "TOP SECRET"
212 assert_no_link "Download XML"
213 assert_no_link "View Redacted Data"
214 assert_link "Way", :href => way_path(way)
215 assert_link "History", :exact => true, :href => way_history_path(way)
219 test "show a redacted relation version to a regular user" do
220 relation = create_redacted_relation
222 sign_in_as(create(:user))
223 visit old_relation_path(relation, 1)
226 assert_css "h2", :text => "Relation: #{relation.id}"
227 assert_text "Version 1 of this relation cannot be shown"
228 assert_no_text "Location"
229 assert_no_text "TOP SECRET"
231 assert_no_link "Download XML"
232 assert_no_link "View Redacted Data"
233 assert_link "Relation", :href => relation_path(relation)
234 assert_link "History", :exact => true, :href => relation_history_path(relation)
238 test "show a redacted node version to a moderator" do
239 node = create_redacted_node
241 sign_in_as(create(:moderator_user))
242 visit old_node_path(node, 1)
245 assert_css "h2", :text => "Node: #{node.id}"
246 assert_text "Version 1 of this node cannot be shown"
247 assert_no_text "Location"
248 assert_no_text "TOP SECRET"
250 assert_no_link "Download XML"
251 assert_link "View Redacted Data"
252 assert_no_link "View Redaction Message"
253 assert_link "Node", :href => node_path(node)
254 assert_link "History", :exact => true, :href => node_history_path(node)
256 click_on "View Redacted Data"
258 assert_css "h2", :text => "Node: #{node.id}"
259 assert_css "h4", :text => "Redacted Version #1"
260 assert_text(/Location: 59\.\d+, 29\.\d+/)
261 assert_text "TOP SECRET"
263 assert_no_link "Download XML"
264 assert_no_link "View Redacted Data"
265 assert_link "View Redaction Message"
266 assert_link "Node", :href => node_path(node)
267 assert_link "History", :exact => true, :href => node_history_path(node)
269 click_on "View Redaction Message"
271 assert_text "Version 1 of this node cannot be shown"
275 test "show a redacted way version to a moderator" do
276 way = create_redacted_way
278 sign_in_as(create(:moderator_user))
279 visit old_way_path(way, 1)
282 assert_css "h2", :text => "Way: #{way.id}"
283 assert_text "Version 1 of this way cannot be shown"
284 assert_no_text "Location"
285 assert_no_text "TOP SECRET"
287 assert_no_link "Download XML"
288 assert_link "View Redacted Data"
289 assert_no_link "View Redaction Message"
290 assert_link "Way", :href => way_path(way)
291 assert_link "History", :exact => true, :href => way_history_path(way)
293 click_on "View Redacted Data"
295 assert_css "h2", :text => "Way: #{way.id}"
296 assert_css "h4", :text => "Redacted Version #1"
297 assert_text "TOP SECRET"
299 assert_no_link "Download XML"
300 assert_no_link "View Redacted Data"
301 assert_link "View Redaction Message"
302 assert_link "Way", :href => way_path(way)
303 assert_link "History", :exact => true, :href => way_history_path(way)
305 click_on "View Redaction Message"
307 assert_text "Version 1 of this way cannot be shown"
311 test "show a redacted relation version to a moderator" do
312 relation = create_redacted_relation
314 sign_in_as(create(:moderator_user))
315 visit old_relation_path(relation, 1)
318 assert_css "h2", :text => "Relation: #{relation.id}"
319 assert_text "Version 1 of this relation cannot be shown"
320 assert_no_text "Location"
321 assert_no_text "TOP SECRET"
323 assert_no_link "Download XML"
324 assert_link "View Redacted Data"
325 assert_no_link "View Redaction Message"
326 assert_link "Relation", :href => relation_path(relation)
327 assert_link "History", :exact => true, :href => relation_history_path(relation)
329 click_on "View Redacted Data"
331 assert_css "h2", :text => "Relation: #{relation.id}"
332 assert_css "h4", :text => "Redacted Version #1"
333 assert_text "TOP SECRET"
335 assert_no_link "Download XML"
336 assert_no_link "View Redacted Data"
337 assert_link "View Redaction Message"
338 assert_link "Relation", :href => relation_path(relation)
339 assert_link "History", :exact => true, :href => relation_history_path(relation)
341 click_on "View Redaction Message"
343 assert_text "Version 1 of this relation cannot be shown"
347 test "navigates between multiple node versions" do
348 node = create(:node, :with_history, :version => 5)
350 visit node_path(node)
353 assert_css "h4", :text => "Version #5"
355 click_on "Version #3"
357 assert_css "h4", :text => "Version #3"
359 click_on "Version #2"
361 assert_css "h4", :text => "Version #2"
363 click_on "Version #4"
365 assert_css "h4", :text => "Version #4"
371 def create_redacted_node
372 create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) do |node|
373 node_v1 = node.old_nodes.find_by(:version => 1)
374 node_v1.update(:lat => 59, :lon => 29)
375 create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
376 node_v1.redact!(create(:redaction))
380 def create_redacted_way
381 create(:way, :with_history, :version => 2) do |way|
382 way_v1 = way.old_ways.find_by(:version => 1)
383 create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
384 way_v1.redact!(create(:redaction))
388 def create_redacted_relation
389 create(:relation, :with_history, :version => 2) do |relation|
390 relation_v1 = relation.old_relations.find_by(:version => 1)
391 create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET")
392 relation_v1.redact!(create(:redaction))