]> git.openstreetmap.org Git - rails.git/blob - test/system/element_old_version_test.rb
Move old way ui tests to system tests
[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 "View Details", :href => node_path(node)
16       assert_link "View History", :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 "View Details", :href => way_path(way)
31       assert_link "View History", :href => way_history_path(way)
32     end
33   end
34
35   test "shows a node with two versions" do
36     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
37     node.old_nodes.find_by(:version => 1).update(:lat => 59, :lon => 29)
38
39     visit old_node_path(node, 1)
40
41     within_sidebar do
42       assert_css "h2", :text => "Node: #{node.id}"
43       assert_css "h4", :text => "Version #1"
44       assert_text(/Location: 59\.\d+, 29\.\d+/)
45
46       assert_link "Download XML", :href => api_node_version_path(node, 1)
47       assert_link "View Details", :href => node_path(node)
48       assert_link "View History", :href => node_history_path(node)
49
50       click_on "Version #2"
51
52       assert_css "h2", :text => "Node: #{node.id}"
53       assert_css "h4", :text => "Version #2"
54       assert_text(/Location: 60\.\d+, 30\.\d+/)
55
56       assert_link "Download XML", :href => api_node_version_path(node, 2)
57       assert_link "View Details", :href => node_path(node)
58       assert_link "View History", :href => node_history_path(node)
59     end
60   end
61
62   test "shows a way with two versions" do
63     way = create(:way, :with_history, :version => 2)
64
65     visit old_way_path(way, 1)
66
67     within_sidebar do
68       assert_css "h2", :text => "Way: #{way.id}"
69       assert_css "h4", :text => "Version #1"
70
71       assert_link "Download XML", :href => api_way_version_path(way, 1)
72       assert_link "View Details", :href => way_path(way)
73       assert_link "View History", :href => way_history_path(way)
74
75       click_on "Version #2"
76
77       assert_css "h2", :text => "Way: #{way.id}"
78       assert_css "h4", :text => "Version #2"
79
80       assert_link "Download XML", :href => api_way_version_path(way, 2)
81       assert_link "View Details", :href => way_path(way)
82       assert_link "View History", :href => way_history_path(way)
83     end
84   end
85
86   test "show a redacted node version" do
87     node = create_redacted_node
88
89     visit old_node_path(node, 1)
90
91     within_sidebar do
92       assert_css "h2", :text => "Node: #{node.id}"
93       assert_text "Version 1 of this node cannot be shown"
94       assert_no_text "Location"
95       assert_no_text "TOP SECRET"
96
97       assert_no_link "Download XML"
98       assert_no_link "View Redacted Data"
99       assert_link "View Details", :href => node_path(node)
100       assert_link "View History", :href => node_history_path(node)
101     end
102   end
103
104   test "show a redacted way version" do
105     way = create_redacted_way
106
107     visit old_way_path(way, 1)
108
109     within_sidebar do
110       assert_css "h2", :text => "Way: #{way.id}"
111       assert_text "Version 1 of this way cannot be shown"
112       assert_no_text "Location"
113       assert_no_text "TOP SECRET"
114
115       assert_no_link "Download XML"
116       assert_no_link "View Redacted Data"
117       assert_link "View Details", :href => way_path(way)
118       assert_link "View History", :href => way_history_path(way)
119     end
120   end
121
122   test "show a redacted node version to a regular user" do
123     node = create_redacted_node
124
125     sign_in_as(create(:user))
126     visit old_node_path(node, 1)
127
128     within_sidebar do
129       assert_css "h2", :text => "Node: #{node.id}"
130       assert_text "Version 1 of this node cannot be shown"
131       assert_no_text "Location"
132       assert_no_text "TOP SECRET"
133
134       assert_no_link "Download XML"
135       assert_no_link "View Redacted Data"
136       assert_link "View Details", :href => node_path(node)
137       assert_link "View History", :href => node_history_path(node)
138     end
139   end
140
141   test "show a redacted way version to a regular user" do
142     way = create_redacted_way
143
144     sign_in_as(create(:user))
145     visit old_way_path(way, 1)
146
147     within_sidebar do
148       assert_css "h2", :text => "Way: #{way.id}"
149       assert_text "Version 1 of this way cannot be shown"
150       assert_no_text "Location"
151       assert_no_text "TOP SECRET"
152
153       assert_no_link "Download XML"
154       assert_no_link "View Redacted Data"
155       assert_link "View Details", :href => way_path(way)
156       assert_link "View History", :href => way_history_path(way)
157     end
158   end
159
160   test "show a redacted node version to a moderator" do
161     node = create_redacted_node
162
163     sign_in_as(create(:moderator_user))
164     visit old_node_path(node, 1)
165
166     within_sidebar do
167       assert_css "h2", :text => "Node: #{node.id}"
168       assert_text "Version 1 of this node cannot be shown"
169       assert_no_text "Location"
170       assert_no_text "TOP SECRET"
171
172       assert_no_link "Download XML"
173       assert_link "View Redacted Data"
174       assert_no_link "View Redaction Message"
175       assert_link "View Details", :href => node_path(node)
176       assert_link "View History", :href => node_history_path(node)
177
178       click_on "View Redacted Data"
179
180       assert_css "h2", :text => "Node: #{node.id}"
181       assert_css "h4", :text => "Redacted Version #1"
182       assert_text(/Location: 59\.\d+, 29\.\d+/)
183       assert_text "TOP SECRET"
184
185       assert_no_link "Download XML"
186       assert_no_link "View Redacted Data"
187       assert_link "View Redaction Message"
188       assert_link "View Details", :href => node_path(node)
189       assert_link "View History", :href => node_history_path(node)
190
191       click_on "View Redaction Message"
192
193       assert_text "Version 1 of this node cannot be shown"
194     end
195   end
196
197   test "show a redacted way version to a moderator" do
198     way = create_redacted_way
199
200     sign_in_as(create(:moderator_user))
201     visit old_way_path(way, 1)
202
203     within_sidebar do
204       assert_css "h2", :text => "Way: #{way.id}"
205       assert_text "Version 1 of this way cannot be shown"
206       assert_no_text "Location"
207       assert_no_text "TOP SECRET"
208
209       assert_no_link "Download XML"
210       assert_link "View Redacted Data"
211       assert_no_link "View Redaction Message"
212       assert_link "View Details", :href => way_path(way)
213       assert_link "View History", :href => way_history_path(way)
214
215       click_on "View Redacted Data"
216
217       assert_css "h2", :text => "Way: #{way.id}"
218       assert_css "h4", :text => "Redacted Version #1"
219       assert_text "TOP SECRET"
220
221       assert_no_link "Download XML"
222       assert_no_link "View Redacted Data"
223       assert_link "View Redaction Message"
224       assert_link "View Details", :href => way_path(way)
225       assert_link "View History", :href => way_history_path(way)
226
227       click_on "View Redaction Message"
228
229       assert_text "Version 1 of this way cannot be shown"
230     end
231   end
232
233   private
234
235   def create_redacted_node
236     create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) do |node|
237       node_v1 = node.old_nodes.find_by(:version => 1)
238       node_v1.update(:lat => 59, :lon => 29)
239       create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
240       node_v1.redact!(create(:redaction))
241     end
242   end
243
244   def create_redacted_way
245     create(:way, :with_history, :version => 2) do |way|
246       way_v1 = way.old_ways.find_by(:version => 1)
247       create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
248       way_v1.redact!(create(:redaction))
249     end
250   end
251 end