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