]> git.openstreetmap.org Git - rails.git/blob - test/system/element_history_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / system / element_history_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class ElementHistoryTest < ApplicationSystemTestCase
6   test "shows history of a node" do
7     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
8     node_v1 = node.old_nodes.find_by(:version => 1)
9     node_v2 = node.old_nodes.find_by(:version => 2)
10     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
11     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
12     node_v1.update(:lat => 59, :lon => 29)
13
14     visit node_history_path(node)
15
16     within_sidebar do
17       v2_heading = find :element, "h4", :text => "Version #2"
18       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
19
20       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
21       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
22       assert_text(/Location: 60\.\d+, 30\.\d+/)
23       assert_text(/Location: 59\.\d+, 29\.\d+/)
24
25       assert_link "Node", :href => node_path(node)
26       assert_no_link "History", :exact => true
27       assert_no_link "Unredacted History"
28     end
29   end
30
31   test "shows history of a way" do
32     way = create(:way, :with_history, :version => 2)
33     way_v1 = way.old_ways.find_by(:version => 1)
34     way_v2 = way.old_ways.find_by(:version => 2)
35     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
36     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
37
38     visit way_history_path(way)
39
40     within_sidebar do
41       v2_heading = find :element, "h4", :text => "Version #2"
42       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
43
44       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
45       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
46
47       assert_link "Way", :href => way_path(way)
48       assert_no_link "History", :exact => true
49       assert_no_link "Unredacted History"
50     end
51   end
52
53   test "shows history of a relation" do
54     relation = create(:relation, :with_history, :version => 2)
55     relation_v1 = relation.old_relations.find_by(:version => 1)
56     relation_v2 = relation.old_relations.find_by(:version => 2)
57     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
58     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
59
60     visit relation_history_path(relation)
61
62     within_sidebar do
63       v2_heading = find :element, "h4", :text => "Version #2"
64       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
65
66       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
67       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
68
69       assert_link "Relation", :href => relation_path(relation)
70       assert_no_link "History", :exact => true
71       assert_no_link "Unredacted History"
72     end
73   end
74
75   test "shows history of a node to a regular user" do
76     node = create(:node, :with_history)
77
78     visit node_history_path(node)
79
80     within_sidebar do
81       assert_link "Node", :href => node_path(node)
82       assert_no_link "History", :exact => true
83       assert_no_link "Unredacted History"
84     end
85   end
86
87   test "shows history of a way to a regular user" do
88     way = create(:way, :with_history)
89
90     visit way_history_path(way)
91
92     within_sidebar do
93       assert_link "Way", :href => way_path(way)
94       assert_no_link "History", :exact => true
95       assert_no_link "Unredacted History"
96     end
97   end
98
99   test "shows history of a relation to a regular user" do
100     relation = create(:relation, :with_history)
101
102     visit relation_history_path(relation)
103
104     within_sidebar do
105       assert_link "Relation", :href => relation_path(relation)
106       assert_no_link "History", :exact => true
107       assert_no_link "Unredacted History"
108     end
109   end
110
111   test "shows history of a node with one redacted version" do
112     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
113     node_v1 = node.old_nodes.find_by(:version => 1)
114     node_v2 = node.old_nodes.find_by(:version => 2)
115     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
116     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
117     node_v1.update(:lat => 59, :lon => 29)
118     node_v1.redact!(create(:redaction))
119
120     visit node_history_path(node)
121
122     within_sidebar do
123       assert_css "h4", :text => "Version #2"
124       assert_css "td", :text => "VALUE-TWO"
125       assert_no_css "td", :text => "VALUE-ONE"
126       assert_text(/Location: 60\.\d+, 30\.\d+/)
127       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
128       assert_text "Version 1 of this node cannot be shown"
129
130       assert_link "Node", :href => node_path(node)
131       assert_no_link "History", :exact => true
132       assert_no_link "Unredacted History"
133     end
134   end
135
136   test "shows history of a way with one redacted version" do
137     way = create(:way, :with_history, :version => 2)
138     way_v1 = way.old_ways.find_by(:version => 1)
139     way_v2 = way.old_ways.find_by(:version => 2)
140     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
141     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
142     way_v1.redact!(create(:redaction))
143
144     visit way_history_path(way)
145
146     within_sidebar do
147       assert_css "h4", :text => "Version #2"
148       assert_css "td", :text => "VALUE-TWO"
149       assert_no_css "td", :text => "VALUE-ONE"
150       assert_text "Version 1 of this way cannot be shown"
151
152       assert_link "Way", :href => way_path(way)
153       assert_no_link "History", :exact => true
154       assert_no_link "Unredacted History"
155     end
156   end
157
158   test "shows history of a relation with one redacted version" do
159     relation = create(:relation, :with_history, :version => 2)
160     relation_v1 = relation.old_relations.find_by(:version => 1)
161     relation_v2 = relation.old_relations.find_by(:version => 2)
162     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
163     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
164     relation_v1.redact!(create(:redaction))
165
166     visit relation_history_path(relation)
167
168     within_sidebar do
169       assert_css "h4", :text => "Version #2"
170       assert_css "td", :text => "VALUE-TWO"
171       assert_no_css "td", :text => "VALUE-ONE"
172       assert_text "Version 1 of this relation cannot be shown"
173
174       assert_link "Relation", :href => relation_path(relation)
175       assert_no_link "History", :exact => true
176       assert_no_link "Unredacted History"
177     end
178   end
179
180   test "shows history of a node with one redacted version to a moderator" do
181     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
182     node_v1 = node.old_nodes.find_by(:version => 1)
183     node_v2 = node.old_nodes.find_by(:version => 2)
184     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
185     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
186     node_v1.update(:lat => 59, :lon => 29)
187     node_v1.redact!(create(:redaction))
188
189     sign_in_as(create(:moderator_user))
190     visit node_history_path(node)
191
192     within_sidebar do
193       assert_css "td", :text => "VALUE-TWO"
194       assert_no_css "td", :text => "VALUE-ONE"
195       assert_text(/Location: 60\.\d+, 30\.\d+/)
196       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
197       assert_text "Version 1 of this node cannot be shown"
198
199       assert_link "Node", :href => node_path(node)
200       assert_no_link "History", :exact => true
201       assert_link "Unredacted History"
202
203       click_on "Unredacted History"
204
205       assert_css "td", :text => "VALUE-TWO"
206       assert_css "td", :text => "VALUE-ONE"
207       assert_text(/Location: 60\.\d+, 30\.\d+/)
208       assert_text(/Location: 59\.\d+, 29\.\d+/)
209       assert_no_text "Version 1 of this node cannot be shown"
210
211       assert_link "Node", :href => node_path(node)
212       assert_link "History", :exact => true
213       assert_no_link "Unredacted History"
214
215       click_on "History", :exact => true
216
217       assert_text "Version 1 of this node cannot be shown"
218     end
219   end
220
221   test "shows history of a way with one redacted version to a moderator" do
222     way = create(:way, :with_history, :version => 2)
223     way_v1 = way.old_ways.find_by(:version => 1)
224     way_v2 = way.old_ways.find_by(:version => 2)
225     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
226     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
227     way_v1.redact!(create(:redaction))
228
229     sign_in_as(create(:moderator_user))
230     visit way_history_path(way)
231
232     within_sidebar do
233       assert_css "td", :text => "VALUE-TWO"
234       assert_no_css "td", :text => "VALUE-ONE"
235       assert_text "Version 1 of this way cannot be shown"
236
237       assert_link "Way", :href => way_path(way)
238       assert_no_link "History", :exact => true
239       assert_link "Unredacted History"
240
241       click_on "Unredacted History"
242
243       assert_css "td", :text => "VALUE-TWO"
244       assert_css "td", :text => "VALUE-ONE"
245       assert_no_text "Version 1 of this way cannot be shown"
246
247       assert_link "Way", :href => way_path(way)
248       assert_link "History", :exact => true
249       assert_no_link "Unredacted History"
250
251       click_on "History", :exact => true
252
253       assert_text "Version 1 of this way cannot be shown"
254     end
255   end
256
257   test "shows history of a relation with one redacted version to a moderator" do
258     relation = create(:relation, :with_history, :version => 2)
259     relation_v1 = relation.old_relations.find_by(:version => 1)
260     relation_v2 = relation.old_relations.find_by(:version => 2)
261     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
262     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
263     relation_v1.redact!(create(:redaction))
264
265     sign_in_as(create(:moderator_user))
266     visit relation_history_path(relation)
267
268     within_sidebar do
269       assert_css "td", :text => "VALUE-TWO"
270       assert_no_css "td", :text => "VALUE-ONE"
271       assert_text "Version 1 of this relation cannot be shown"
272
273       assert_link "Relation", :href => relation_path(relation)
274       assert_no_link "History", :exact => true
275       assert_link "Unredacted History"
276
277       click_on "Unredacted History"
278
279       assert_css "td", :text => "VALUE-TWO"
280       assert_css "td", :text => "VALUE-ONE"
281       assert_no_text "Version 1 of this relation cannot be shown"
282
283       assert_link "Relation", :href => relation_path(relation)
284       assert_link "History", :exact => true
285       assert_no_link "Unredacted History"
286
287       click_on "History", :exact => true
288
289       assert_text "Version 1 of this relation cannot be shown"
290     end
291   end
292
293   test "can view node history pages" do
294     node = create(:node, :with_history, :version => 41)
295
296     visit node_path(node)
297
298     check_element_history_pages(->(v) { old_node_path(node, v) })
299   end
300
301   test "can view way history pages" do
302     way = create(:way, :with_history, :version => 41)
303
304     visit way_path(way)
305
306     check_element_history_pages(->(v) { old_way_path(way, v) })
307   end
308
309   test "can view relation history pages" do
310     relation = create(:relation, :with_history, :version => 41)
311
312     visit relation_path(relation)
313
314     check_element_history_pages(->(v) { old_relation_path(relation, v) })
315   end
316
317   private
318
319   def check_element_history_pages(get_path)
320     within_sidebar do
321       click_on "History", :exact => true
322
323       41.downto(22) do |v|
324         assert_link v.to_s, :href => get_path.call(v)
325       end
326
327       click_on "Older Versions"
328
329       41.downto(2) do |v|
330         assert_link v.to_s, :href => get_path.call(v)
331       end
332
333       click_on "Older Versions"
334
335       41.downto(1) do |v|
336         assert_link v.to_s, :href => get_path.call(v)
337       end
338
339       assert_no_link "Older Versions"
340     end
341   end
342 end