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 "View Details", :href => node_path(node)
24 assert_no_link "View History"
25 assert_no_link "View 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 "View Details", :href => way_path(way)
46 assert_no_link "View History"
47 assert_no_link "View Unredacted History"
51 test "shows history of a node to a regular user" do
52 node = create(:node, :with_history)
54 visit node_history_path(node)
57 assert_link "View Details", :href => node_path(node)
58 assert_no_link "View History"
59 assert_no_link "View Unredacted History"
63 test "shows history of a way to a regular user" do
64 way = create(:way, :with_history)
66 visit way_history_path(way)
69 assert_link "View Details", :href => way_path(way)
70 assert_no_link "View History"
71 assert_no_link "View Unredacted History"
75 test "shows history of a node with one redacted version" do
76 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
77 node_v1 = node.old_nodes.find_by(:version => 1)
78 node_v2 = node.old_nodes.find_by(:version => 2)
79 create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
80 create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
81 node_v1.update(:lat => 59, :lon => 29)
82 node_v1.redact!(create(:redaction))
84 visit node_history_path(node)
87 assert_css "h4", :text => "Version #2"
88 assert_css "td", :text => "VALUE-TWO"
89 assert_no_css "td", :text => "VALUE-ONE"
90 assert_text(/Location: 60\.\d+, 30\.\d+/)
91 assert_no_text(/Location: 59\.\d+, 29\.\d+/)
92 assert_text "Version 1 of this node cannot be shown"
94 assert_link "View Details", :href => node_path(node)
95 assert_no_link "View History"
96 assert_no_link "View Unredacted History"
100 test "shows history of a way with one redacted version" do
101 way = create(:way, :with_history, :version => 2)
102 way_v1 = way.old_ways.find_by(:version => 1)
103 way_v2 = way.old_ways.find_by(:version => 2)
104 create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
105 create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
106 way_v1.redact!(create(:redaction))
108 visit way_history_path(way)
111 assert_css "h4", :text => "Version #2"
112 assert_css "td", :text => "VALUE-TWO"
113 assert_no_css "td", :text => "VALUE-ONE"
114 assert_text "Version 1 of this way cannot be shown"
116 assert_link "View Details", :href => way_path(way)
117 assert_no_link "View History"
118 assert_no_link "View Unredacted History"
122 test "shows history of a node with one redacted version to a moderator" do
123 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
124 node_v1 = node.old_nodes.find_by(:version => 1)
125 node_v2 = node.old_nodes.find_by(:version => 2)
126 create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
127 create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
128 node_v1.update(:lat => 59, :lon => 29)
129 node_v1.redact!(create(:redaction))
131 sign_in_as(create(:moderator_user))
132 visit node_history_path(node)
135 assert_css "td", :text => "VALUE-TWO"
136 assert_no_css "td", :text => "VALUE-ONE"
137 assert_text(/Location: 60\.\d+, 30\.\d+/)
138 assert_no_text(/Location: 59\.\d+, 29\.\d+/)
139 assert_text "Version 1 of this node cannot be shown"
141 assert_link "View Details", :href => node_path(node)
142 assert_no_link "View History"
143 assert_link "View Unredacted History"
145 click_on "View Unredacted History"
147 assert_css "td", :text => "VALUE-TWO"
148 assert_css "td", :text => "VALUE-ONE"
149 assert_text(/Location: 60\.\d+, 30\.\d+/)
150 assert_text(/Location: 59\.\d+, 29\.\d+/)
151 assert_no_text "Version 1 of this node cannot be shown"
153 assert_link "View Details", :href => node_path(node)
154 assert_link "View History"
155 assert_no_link "View Unredacted History"
157 click_on "View History"
159 assert_text "Version 1 of this node cannot be shown"
163 test "shows history of a way with one redacted version to a moderator" do
164 way = create(:way, :with_history, :version => 2)
165 way_v1 = way.old_ways.find_by(:version => 1)
166 way_v2 = way.old_ways.find_by(:version => 2)
167 create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
168 create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
169 way_v1.redact!(create(:redaction))
171 sign_in_as(create(:moderator_user))
172 visit way_history_path(way)
175 assert_css "td", :text => "VALUE-TWO"
176 assert_no_css "td", :text => "VALUE-ONE"
177 assert_text "Version 1 of this way cannot be shown"
179 assert_link "View Details", :href => way_path(way)
180 assert_no_link "View History"
181 assert_link "View Unredacted History"
183 click_on "View Unredacted History"
185 assert_css "td", :text => "VALUE-TWO"
186 assert_css "td", :text => "VALUE-ONE"
187 assert_no_text "Version 1 of this way cannot be shown"
189 assert_link "View Details", :href => way_path(way)
190 assert_link "View History"
191 assert_no_link "View Unredacted History"
193 click_on "View History"
195 assert_text "Version 1 of this way cannot be shown"
199 test "can view node history pages" do
200 node = create(:node, :with_history, :version => 41)
202 visit node_path(node)
204 check_element_history_pages(->(v) { old_node_path(node, v) })
207 test "can view way history pages" do
208 way = create(:way, :with_history, :version => 41)
212 check_element_history_pages(->(v) { old_way_path(way, v) })
215 test "can view relation history pages" do
216 relation = create(:relation, :with_history, :version => 41)
218 visit relation_path(relation)
220 check_element_history_pages(->(v) { old_relation_path(relation, v) })
225 def check_element_history_pages(get_path)
227 click_on "View History"
230 assert_link v.to_s, :href => get_path.call(v)
233 click_on "Older Versions"
236 assert_link v.to_s, :href => get_path.call(v)
239 click_on "Older Versions"
242 assert_link v.to_s, :href => get_path.call(v)
245 assert_no_link "Older Versions"