]> git.openstreetmap.org Git - rails.git/blob - test/system/element_old_version_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / system / element_old_version_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class ElementOldVersionTest < ApplicationSystemTestCase
6   test "shows a node with one version" do
7     node = create(:node, :with_history, :lat => 60, :lon => 30)
8
9     visit old_node_path(node, 1)
10
11     within_sidebar do
12       assert_css "h2", :text => "Node: #{node.id}"
13       assert_css "h4", :text => "Version #1"
14       assert_text(/Location: 60\.\d+, 30\.\d+/)
15
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)
19     end
20   end
21
22   test "shows a way with one version" do
23     way = create(:way, :with_history)
24
25     visit old_way_path(way, 1)
26
27     within_sidebar do
28       assert_css "h2", :text => "Way: #{way.id}"
29       assert_css "h4", :text => "Version #1"
30
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)
34     end
35   end
36
37   test "shows a relation with one version" do
38     relation = create(:relation, :with_history)
39
40     visit old_relation_path(relation, 1)
41
42     within_sidebar do
43       assert_css "h2", :text => "Relation: #{relation.id}"
44       assert_css "h4", :text => "Version #1"
45
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)
49     end
50   end
51
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)
55
56     visit old_node_path(node, 1)
57
58     within_sidebar do
59       assert_css "h2", :text => "Node: #{node.id}"
60       assert_css "h4", :text => "Version #1"
61       assert_text(/Location: 59\.\d+, 29\.\d+/)
62
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)
66
67       click_on "Version #2"
68
69       assert_css "h2", :text => "Node: #{node.id}"
70       assert_css "h4", :text => "Version #2"
71       assert_text(/Location: 60\.\d+, 30\.\d+/)
72
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)
76     end
77   end
78
79   test "shows a way with two versions" do
80     way = create(:way, :with_history, :version => 2)
81
82     visit old_way_path(way, 1)
83
84     within_sidebar do
85       assert_css "h2", :text => "Way: #{way.id}"
86       assert_css "h4", :text => "Version #1"
87
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)
91
92       click_on "Version #2"
93
94       assert_css "h2", :text => "Way: #{way.id}"
95       assert_css "h4", :text => "Version #2"
96
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)
100     end
101   end
102
103   test "shows a relation with two versions" do
104     relation = create(:relation, :with_history, :version => 2)
105
106     visit old_relation_path(relation, 1)
107
108     within_sidebar do
109       assert_css "h2", :text => "Relation: #{relation.id}"
110       assert_css "h4", :text => "Version #1"
111
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)
115
116       click_on "Version #2"
117
118       assert_css "h2", :text => "Relation: #{relation.id}"
119       assert_css "h4", :text => "Version #2"
120
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)
124     end
125   end
126
127   test "show a redacted node version" do
128     node = create_redacted_node
129
130     visit old_node_path(node, 1)
131
132     within_sidebar do
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"
137
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)
142     end
143   end
144
145   test "show a redacted way version" do
146     way = create_redacted_way
147
148     visit old_way_path(way, 1)
149
150     within_sidebar do
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"
155
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)
160     end
161   end
162
163   test "show a redacted relation version" do
164     relation = create_redacted_relation
165
166     visit old_relation_path(relation, 1)
167
168     within_sidebar do
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"
173
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)
178     end
179   end
180
181   test "show a redacted node version to a regular user" do
182     node = create_redacted_node
183
184     sign_in_as(create(:user))
185     visit old_node_path(node, 1)
186
187     within_sidebar do
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"
192
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)
197     end
198   end
199
200   test "show a redacted way version to a regular user" do
201     way = create_redacted_way
202
203     sign_in_as(create(:user))
204     visit old_way_path(way, 1)
205
206     within_sidebar do
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"
211
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)
216     end
217   end
218
219   test "show a redacted relation version to a regular user" do
220     relation = create_redacted_relation
221
222     sign_in_as(create(:user))
223     visit old_relation_path(relation, 1)
224
225     within_sidebar do
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"
230
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)
235     end
236   end
237
238   test "show a redacted node version to a moderator" do
239     node = create_redacted_node
240
241     sign_in_as(create(:moderator_user))
242     visit old_node_path(node, 1)
243
244     within_sidebar do
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"
249
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)
255
256       click_on "View Redacted Data"
257
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"
262
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)
268
269       click_on "View Redaction Message"
270
271       assert_text "Version 1 of this node cannot be shown"
272     end
273   end
274
275   test "show a redacted way version to a moderator" do
276     way = create_redacted_way
277
278     sign_in_as(create(:moderator_user))
279     visit old_way_path(way, 1)
280
281     within_sidebar do
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"
286
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)
292
293       click_on "View Redacted Data"
294
295       assert_css "h2", :text => "Way: #{way.id}"
296       assert_css "h4", :text => "Redacted Version #1"
297       assert_text "TOP SECRET"
298
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)
304
305       click_on "View Redaction Message"
306
307       assert_text "Version 1 of this way cannot be shown"
308     end
309   end
310
311   test "show a redacted relation version to a moderator" do
312     relation = create_redacted_relation
313
314     sign_in_as(create(:moderator_user))
315     visit old_relation_path(relation, 1)
316
317     within_sidebar do
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"
322
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)
328
329       click_on "View Redacted Data"
330
331       assert_css "h2", :text => "Relation: #{relation.id}"
332       assert_css "h4", :text => "Redacted Version #1"
333       assert_text "TOP SECRET"
334
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)
340
341       click_on "View Redaction Message"
342
343       assert_text "Version 1 of this relation cannot be shown"
344     end
345   end
346
347   test "navigates between multiple node versions" do
348     node = create(:node, :with_history, :version => 5)
349
350     visit node_path(node)
351
352     within_sidebar do
353       assert_css "h4", :text => "Version #5"
354
355       click_on "Version #3"
356
357       assert_css "h4", :text => "Version #3"
358
359       click_on "Version #2"
360
361       assert_css "h4", :text => "Version #2"
362
363       click_on "Version #4"
364
365       assert_css "h4", :text => "Version #4"
366     end
367   end
368
369   private
370
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))
377     end
378   end
379
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))
385     end
386   end
387
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))
393     end
394   end
395 end