1 require "application_system_test_case"
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)
12 visit node_history_path(node)
15 v2_heading = find :element, "h4", :text => "Version #2"
16 v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
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+/)
23 assert_link "Node", :href => node_path(node)
24 assert_no_link "History", :exact => true
25 assert_no_link "Unredacted History"
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")
36 visit way_history_path(way)
39 v2_heading = find :element, "h4", :text => "Version #2"
40 v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
42 assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
43 assert_css "td", :text => "VALUE-ONE", :below => v1_heading
45 assert_link "Way", :href => way_path(way)
46 assert_no_link "History", :exact => true
47 assert_no_link "Unredacted History"
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")
58 visit relation_history_path(relation)
61 v2_heading = find :element, "h4", :text => "Version #2"
62 v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
64 assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
65 assert_css "td", :text => "VALUE-ONE", :below => v1_heading
67 assert_link "Relation", :href => relation_path(relation)
68 assert_no_link "History", :exact => true
69 assert_no_link "Unredacted History"
73 test "shows history of a node to a regular user" do
74 node = create(:node, :with_history)
76 visit node_history_path(node)
79 assert_link "Node", :href => node_path(node)
80 assert_no_link "History", :exact => true
81 assert_no_link "Unredacted History"
85 test "shows history of a way to a regular user" do
86 way = create(:way, :with_history)
88 visit way_history_path(way)
91 assert_link "Way", :href => way_path(way)
92 assert_no_link "History", :exact => true
93 assert_no_link "Unredacted History"
97 test "shows history of a relation to a regular user" do
98 relation = create(:relation, :with_history)
100 visit relation_history_path(relation)
103 assert_link "Relation", :href => relation_path(relation)
104 assert_no_link "History", :exact => true
105 assert_no_link "Unredacted History"
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))
118 visit node_history_path(node)
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"
128 assert_link "Node", :href => node_path(node)
129 assert_no_link "History", :exact => true
130 assert_no_link "Unredacted History"
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))
142 visit way_history_path(way)
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"
150 assert_link "Way", :href => way_path(way)
151 assert_no_link "History", :exact => true
152 assert_no_link "Unredacted History"
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))
164 visit relation_history_path(relation)
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"
172 assert_link "Relation", :href => relation_path(relation)
173 assert_no_link "History", :exact => true
174 assert_no_link "Unredacted History"
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))
187 sign_in_as(create(:moderator_user))
188 visit node_history_path(node)
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"
197 assert_link "Node", :href => node_path(node)
198 assert_no_link "History", :exact => true
199 assert_link "Unredacted History"
201 click_on "Unredacted History"
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"
209 assert_link "Node", :href => node_path(node)
210 assert_link "History", :exact => true
211 assert_no_link "Unredacted History"
213 click_on "History", :exact => true
215 assert_text "Version 1 of this node cannot be shown"
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))
227 sign_in_as(create(:moderator_user))
228 visit way_history_path(way)
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"
235 assert_link "Way", :href => way_path(way)
236 assert_no_link "History", :exact => true
237 assert_link "Unredacted History"
239 click_on "Unredacted History"
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"
245 assert_link "Way", :href => way_path(way)
246 assert_link "History", :exact => true
247 assert_no_link "Unredacted History"
249 click_on "History", :exact => true
251 assert_text "Version 1 of this way cannot be shown"
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))
263 sign_in_as(create(:moderator_user))
264 visit relation_history_path(relation)
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"
271 assert_link "Relation", :href => relation_path(relation)
272 assert_no_link "History", :exact => true
273 assert_link "Unredacted History"
275 click_on "Unredacted History"
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"
281 assert_link "Relation", :href => relation_path(relation)
282 assert_link "History", :exact => true
283 assert_no_link "Unredacted History"
285 click_on "History", :exact => true
287 assert_text "Version 1 of this relation cannot be shown"
291 test "can view node history pages" do
292 node = create(:node, :with_history, :version => 41)
294 visit node_path(node)
296 check_element_history_pages(->(v) { old_node_path(node, v) })
299 test "can view way history pages" do
300 way = create(:way, :with_history, :version => 41)
304 check_element_history_pages(->(v) { old_way_path(way, v) })
307 test "can view relation history pages" do
308 relation = create(:relation, :with_history, :version => 41)
310 visit relation_path(relation)
312 check_element_history_pages(->(v) { old_relation_path(relation, v) })
317 def check_element_history_pages(get_path)
319 click_on "History", :exact => true
322 assert_link v.to_s, :href => get_path.call(v)
325 click_on "Older Versions"
328 assert_link v.to_s, :href => get_path.call(v)
331 click_on "Older Versions"
334 assert_link v.to_s, :href => get_path.call(v)
337 assert_no_link "Older Versions"