]> git.openstreetmap.org Git - rails.git/blob - test/system/element_old_version_test.rb
Fix eslint warning
[rails.git] / test / system / element_old_version_test.rb
1 require "application_system_test_case"
2
3 class ElementOldVersionTest < ApplicationSystemTestCase
4   test "shows a node with one version" do
5     node = create(:node, :with_history, :lat => 60, :lon => 30)
6
7     visit old_node_path(node, 1)
8
9     within_sidebar do
10       assert_css "h2", :text => "Node: #{node.id}"
11       assert_css "h4", :text => "Version #1"
12       assert_text(/Location: 60\.\d+, 30\.\d+/)
13
14       assert_link "Download XML", :href => api_node_version_path(node, 1)
15       assert_link "Node", :href => node_path(node)
16       assert_link "History", :exact => true, :href => node_history_path(node)
17     end
18   end
19
20   test "shows a way with one version" do
21     way = create(:way, :with_history)
22
23     visit old_way_path(way, 1)
24
25     within_sidebar do
26       assert_css "h2", :text => "Way: #{way.id}"
27       assert_css "h4", :text => "Version #1"
28
29       assert_link "Download XML", :href => api_way_version_path(way, 1)
30       assert_link "Way", :href => way_path(way)
31       assert_link "History", :exact => true, :href => way_history_path(way)
32     end
33   end
34
35   test "shows a relation with one version" do
36     relation = create(:relation, :with_history)
37
38     visit old_relation_path(relation, 1)
39
40     within_sidebar do
41       assert_css "h2", :text => "Relation: #{relation.id}"
42       assert_css "h4", :text => "Version #1"
43
44       assert_link "Download XML", :href => api_relation_version_path(relation, 1)
45       assert_link "Relation", :href => relation_path(relation)
46       assert_link "History", :exact => true, :href => relation_history_path(relation)
47     end
48   end
49
50   test "shows a node with two versions" do
51     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
52     node.old_nodes.find_by(:version => 1).update(:lat => 59, :lon => 29)
53
54     visit old_node_path(node, 1)
55
56     within_sidebar do
57       assert_css "h2", :text => "Node: #{node.id}"
58       assert_css "h4", :text => "Version #1"
59       assert_text(/Location: 59\.\d+, 29\.\d+/)
60
61       assert_link "Download XML", :href => api_node_version_path(node, 1)
62       assert_link "Node", :href => node_path(node)
63       assert_link "History", :exact => true, :href => node_history_path(node)
64
65       click_on "Version #2"
66
67       assert_css "h2", :text => "Node: #{node.id}"
68       assert_css "h4", :text => "Version #2"
69       assert_text(/Location: 60\.\d+, 30\.\d+/)
70
71       assert_link "Download XML", :href => api_node_version_path(node, 2)
72       assert_link "Node", :href => node_path(node)
73       assert_link "History", :exact => true, :href => node_history_path(node)
74     end
75   end
76
77   test "shows a way with two versions" do
78     way = create(:way, :with_history, :version => 2)
79
80     visit old_way_path(way, 1)
81
82     within_sidebar do
83       assert_css "h2", :text => "Way: #{way.id}"
84       assert_css "h4", :text => "Version #1"
85
86       assert_link "Download XML", :href => api_way_version_path(way, 1)
87       assert_link "Way", :href => way_path(way)
88       assert_link "History", :exact => true, :href => way_history_path(way)
89
90       click_on "Version #2"
91
92       assert_css "h2", :text => "Way: #{way.id}"
93       assert_css "h4", :text => "Version #2"
94
95       assert_link "Download XML", :href => api_way_version_path(way, 2)
96       assert_link "Way", :href => way_path(way)
97       assert_link "History", :exact => true, :href => way_history_path(way)
98     end
99   end
100
101   test "shows a relation with two versions" do
102     relation = create(:relation, :with_history, :version => 2)
103
104     visit old_relation_path(relation, 1)
105
106     within_sidebar do
107       assert_css "h2", :text => "Relation: #{relation.id}"
108       assert_css "h4", :text => "Version #1"
109
110       assert_link "Download XML", :href => api_relation_version_path(relation, 1)
111       assert_link "Relation", :href => relation_path(relation)
112       assert_link "History", :exact => true, :href => relation_history_path(relation)
113
114       click_on "Version #2"
115
116       assert_css "h2", :text => "Relation: #{relation.id}"
117       assert_css "h4", :text => "Version #2"
118
119       assert_link "Download XML", :href => api_relation_version_path(relation, 2)
120       assert_link "Relation", :href => relation_path(relation)
121       assert_link "History", :exact => true, :href => relation_history_path(relation)
122     end
123   end
124
125   test "show a redacted node version" do
126     node = create_redacted_node
127
128     visit old_node_path(node, 1)
129
130     within_sidebar do
131       assert_css "h2", :text => "Node: #{node.id}"
132       assert_text "Version 1 of this node cannot be shown"
133       assert_no_text "Location"
134       assert_no_text "TOP SECRET"
135
136       assert_no_link "Download XML"
137       assert_no_link "View Redacted Data"
138       assert_link "Node", :href => node_path(node)
139       assert_link "History", :exact => true, :href => node_history_path(node)
140     end
141   end
142
143   test "show a redacted way version" do
144     way = create_redacted_way
145
146     visit old_way_path(way, 1)
147
148     within_sidebar do
149       assert_css "h2", :text => "Way: #{way.id}"
150       assert_text "Version 1 of this way cannot be shown"
151       assert_no_text "Location"
152       assert_no_text "TOP SECRET"
153
154       assert_no_link "Download XML"
155       assert_no_link "View Redacted Data"
156       assert_link "Way", :href => way_path(way)
157       assert_link "History", :exact => true, :href => way_history_path(way)
158     end
159   end
160
161   test "show a redacted relation version" do
162     relation = create_redacted_relation
163
164     visit old_relation_path(relation, 1)
165
166     within_sidebar do
167       assert_css "h2", :text => "Relation: #{relation.id}"
168       assert_text "Version 1 of this relation cannot be shown"
169       assert_no_text "Location"
170       assert_no_text "TOP SECRET"
171
172       assert_no_link "Download XML"
173       assert_no_link "View Redacted Data"
174       assert_link "Relation", :href => relation_path(relation)
175       assert_link "History", :exact => true, :href => relation_history_path(relation)
176     end
177   end
178
179   test "show a redacted node version to a regular user" do
180     node = create_redacted_node
181
182     sign_in_as(create(:user))
183     visit old_node_path(node, 1)
184
185     within_sidebar do
186       assert_css "h2", :text => "Node: #{node.id}"
187       assert_text "Version 1 of this node cannot be shown"
188       assert_no_text "Location"
189       assert_no_text "TOP SECRET"
190
191       assert_no_link "Download XML"
192       assert_no_link "View Redacted Data"
193       assert_link "Node", :href => node_path(node)
194       assert_link "History", :exact => true, :href => node_history_path(node)
195     end
196   end
197
198   test "show a redacted way version to a regular user" do
199     way = create_redacted_way
200
201     sign_in_as(create(:user))
202     visit old_way_path(way, 1)
203
204     within_sidebar do
205       assert_css "h2", :text => "Way: #{way.id}"
206       assert_text "Version 1 of this way cannot be shown"
207       assert_no_text "Location"
208       assert_no_text "TOP SECRET"
209
210       assert_no_link "Download XML"
211       assert_no_link "View Redacted Data"
212       assert_link "Way", :href => way_path(way)
213       assert_link "History", :exact => true, :href => way_history_path(way)
214     end
215   end
216
217   test "show a redacted relation version to a regular user" do
218     relation = create_redacted_relation
219
220     sign_in_as(create(:user))
221     visit old_relation_path(relation, 1)
222
223     within_sidebar do
224       assert_css "h2", :text => "Relation: #{relation.id}"
225       assert_text "Version 1 of this relation cannot be shown"
226       assert_no_text "Location"
227       assert_no_text "TOP SECRET"
228
229       assert_no_link "Download XML"
230       assert_no_link "View Redacted Data"
231       assert_link "Relation", :href => relation_path(relation)
232       assert_link "History", :exact => true, :href => relation_history_path(relation)
233     end
234   end
235
236   test "show a redacted node version to a moderator" do
237     node = create_redacted_node
238
239     sign_in_as(create(:moderator_user))
240     visit old_node_path(node, 1)
241
242     within_sidebar do
243       assert_css "h2", :text => "Node: #{node.id}"
244       assert_text "Version 1 of this node cannot be shown"
245       assert_no_text "Location"
246       assert_no_text "TOP SECRET"
247
248       assert_no_link "Download XML"
249       assert_link "View Redacted Data"
250       assert_no_link "View Redaction Message"
251       assert_link "Node", :href => node_path(node)
252       assert_link "History", :exact => true, :href => node_history_path(node)
253
254       click_on "View Redacted Data"
255
256       assert_css "h2", :text => "Node: #{node.id}"
257       assert_css "h4", :text => "Redacted Version #1"
258       assert_text(/Location: 59\.\d+, 29\.\d+/)
259       assert_text "TOP SECRET"
260
261       assert_no_link "Download XML"
262       assert_no_link "View Redacted Data"
263       assert_link "View Redaction Message"
264       assert_link "Node", :href => node_path(node)
265       assert_link "History", :exact => true, :href => node_history_path(node)
266
267       click_on "View Redaction Message"
268
269       assert_text "Version 1 of this node cannot be shown"
270     end
271   end
272
273   test "show a redacted way version to a moderator" do
274     way = create_redacted_way
275
276     sign_in_as(create(:moderator_user))
277     visit old_way_path(way, 1)
278
279     within_sidebar do
280       assert_css "h2", :text => "Way: #{way.id}"
281       assert_text "Version 1 of this way cannot be shown"
282       assert_no_text "Location"
283       assert_no_text "TOP SECRET"
284
285       assert_no_link "Download XML"
286       assert_link "View Redacted Data"
287       assert_no_link "View Redaction Message"
288       assert_link "Way", :href => way_path(way)
289       assert_link "History", :exact => true, :href => way_history_path(way)
290
291       click_on "View Redacted Data"
292
293       assert_css "h2", :text => "Way: #{way.id}"
294       assert_css "h4", :text => "Redacted Version #1"
295       assert_text "TOP SECRET"
296
297       assert_no_link "Download XML"
298       assert_no_link "View Redacted Data"
299       assert_link "View Redaction Message"
300       assert_link "Way", :href => way_path(way)
301       assert_link "History", :exact => true, :href => way_history_path(way)
302
303       click_on "View Redaction Message"
304
305       assert_text "Version 1 of this way cannot be shown"
306     end
307   end
308
309   test "show a redacted relation version to a moderator" do
310     relation = create_redacted_relation
311
312     sign_in_as(create(:moderator_user))
313     visit old_relation_path(relation, 1)
314
315     within_sidebar do
316       assert_css "h2", :text => "Relation: #{relation.id}"
317       assert_text "Version 1 of this relation cannot be shown"
318       assert_no_text "Location"
319       assert_no_text "TOP SECRET"
320
321       assert_no_link "Download XML"
322       assert_link "View Redacted Data"
323       assert_no_link "View Redaction Message"
324       assert_link "Relation", :href => relation_path(relation)
325       assert_link "History", :exact => true, :href => relation_history_path(relation)
326
327       click_on "View Redacted Data"
328
329       assert_css "h2", :text => "Relation: #{relation.id}"
330       assert_css "h4", :text => "Redacted Version #1"
331       assert_text "TOP SECRET"
332
333       assert_no_link "Download XML"
334       assert_no_link "View Redacted Data"
335       assert_link "View Redaction Message"
336       assert_link "Relation", :href => relation_path(relation)
337       assert_link "History", :exact => true, :href => relation_history_path(relation)
338
339       click_on "View Redaction Message"
340
341       assert_text "Version 1 of this relation cannot be shown"
342     end
343   end
344
345   test "navigates between multiple node versions" do
346     node = create(:node, :with_history, :version => 5)
347
348     visit node_path(node)
349
350     within_sidebar do
351       assert_css "h4", :text => "Version #5"
352
353       click_on "Version #3"
354
355       assert_css "h4", :text => "Version #3"
356
357       click_on "Version #2"
358
359       assert_css "h4", :text => "Version #2"
360
361       click_on "Version #4"
362
363       assert_css "h4", :text => "Version #4"
364     end
365   end
366
367   private
368
369   def create_redacted_node
370     create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) do |node|
371       node_v1 = node.old_nodes.find_by(:version => 1)
372       node_v1.update(:lat => 59, :lon => 29)
373       create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
374       node_v1.redact!(create(:redaction))
375     end
376   end
377
378   def create_redacted_way
379     create(:way, :with_history, :version => 2) do |way|
380       way_v1 = way.old_ways.find_by(:version => 1)
381       create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
382       way_v1.redact!(create(:redaction))
383     end
384   end
385
386   def create_redacted_relation
387     create(:relation, :with_history, :version => 2) do |relation|
388       relation_v1 = relation.old_relations.find_by(:version => 1)
389       create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET")
390       relation_v1.redact!(create(:redaction))
391     end
392   end
393 end