]> git.openstreetmap.org Git - rails.git/blob - test/controllers/browse_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4552'
[rails.git] / test / controllers / browse_controller_test.rb
1 require "test_helper"
2
3 class BrowseControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/node/1", :method => :get },
9       { :controller => "browse", :action => "node", :id => "1" }
10     )
11     assert_routing(
12       { :path => "/node/1/history", :method => :get },
13       { :controller => "browse", :action => "node_history", :id => "1" }
14     )
15     assert_routing(
16       { :path => "/way/1", :method => :get },
17       { :controller => "browse", :action => "way", :id => "1" }
18     )
19     assert_routing(
20       { :path => "/way/1/history", :method => :get },
21       { :controller => "browse", :action => "way_history", :id => "1" }
22     )
23     assert_routing(
24       { :path => "/relation/1", :method => :get },
25       { :controller => "browse", :action => "relation", :id => "1" }
26     )
27     assert_routing(
28       { :path => "/relation/1/history", :method => :get },
29       { :controller => "browse", :action => "relation_history", :id => "1" }
30     )
31     assert_routing(
32       { :path => "/query", :method => :get },
33       { :controller => "browse", :action => "query" }
34     )
35   end
36
37   def test_read_relation
38     relation = create(:relation)
39     sidebar_browse_check :relation_path, relation.id, "browse/feature"
40     assert_select "h4", /^Version/ do
41       assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
42     end
43     assert_select ".secondary-actions a[href='#{api_relation_path relation}']", :count => 1
44     assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
45     assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
46   end
47
48   def test_multiple_version_relation_links
49     relation = create(:relation, :with_history, :version => 2)
50     sidebar_browse_check :relation_path, relation.id, "browse/feature"
51     assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
52     assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
53     assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
54   end
55
56   def test_read_relation_history
57     relation = create(:relation, :with_history)
58     sidebar_browse_check :relation_history_path, relation.id, "browse/history"
59     assert_select "h4", /^Version/ do
60       assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
61     end
62   end
63
64   def test_read_way
65     way = create(:way)
66     sidebar_browse_check :way_path, way.id, "browse/feature"
67     assert_select "h4", /^Version/ do
68       assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
69     end
70     assert_select ".secondary-actions a[href='#{api_way_path way}']", :count => 1
71     assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
72     assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
73   end
74
75   def test_multiple_version_way_links
76     way = create(:way, :with_history, :version => 2)
77     sidebar_browse_check :way_path, way.id, "browse/feature"
78     assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
79     assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
80     assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
81   end
82
83   def test_read_way_history
84     way = create(:way, :with_history)
85     sidebar_browse_check :way_history_path, way.id, "browse/history"
86     assert_select "h4", /^Version/ do
87       assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
88     end
89   end
90
91   def test_read_node
92     node = create(:node)
93     sidebar_browse_check :node_path, node.id, "browse/feature"
94     assert_select "h4", /^Version/ do
95       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
96     end
97     assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1
98     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
99     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
100   end
101
102   def test_multiple_version_node_links
103     node = create(:node, :with_history, :version => 2)
104     sidebar_browse_check :node_path, node.id, "browse/feature"
105     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
106     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
107     assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
108   end
109
110   def test_read_deleted_node
111     node = create(:node, :visible => false)
112     sidebar_browse_check :node_path, node.id, "browse/feature"
113     assert_select "h4", /^Version/ do
114       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
115     end
116     assert_select "a[href='#{api_node_path node}']", :count => 0
117   end
118
119   def test_read_node_history
120     node = create(:node, :with_history)
121     sidebar_browse_check :node_history_path, node.id, "browse/history"
122     assert_select "h4", /^Version/ do
123       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
124     end
125   end
126
127   ##
128   #  Methods to check redaction.
129   #
130   # note that these are presently highly reliant on the structure of the
131   # page for the selection tests, which doesn't work out particularly
132   # well if that structure changes. so... if you change the page layout
133   # then please make it more easily (and robustly) testable!
134   ##
135   def test_redacted_node
136     node = create(:node, :with_history, :deleted, :version => 2)
137     node_v1 = node.old_nodes.find_by(:version => 1)
138     node_v1.redact!(create(:redaction))
139
140     get node_path(:id => node)
141     assert_response :success
142     assert_template "feature"
143
144     # check that we don't show lat/lon for a redacted node.
145     assert_select ".browse-section", 1
146     assert_select ".browse-section.browse-node", 1
147     assert_select ".browse-section.browse-node .latitude", 0
148     assert_select ".browse-section.browse-node .longitude", 0
149   end
150
151   def test_redacted_node_history
152     node = create(:node, :with_history, :deleted, :version => 2)
153     node_v1 = node.old_nodes.find_by(:version => 1)
154     node_v1.redact!(create(:redaction))
155
156     get node_history_path(:id => node)
157     assert_response :success
158     assert_template "browse/history"
159
160     # there are 2 revisions of the redacted node, but only one
161     # should be showing details here.
162     assert_select ".browse-section", 2
163     assert_select ".browse-section.browse-redacted", 1
164     assert_select ".browse-section.browse-node", 1
165     assert_select ".browse-section.browse-node .latitude", 0
166     assert_select ".browse-section.browse-node .longitude", 0
167   end
168
169   def test_redacted_way_history
170     way = create(:way, :with_history, :version => 4)
171     way_v1 = way.old_ways.find_by(:version => 1)
172     way_v1.redact!(create(:redaction))
173     way_v3 = way.old_ways.find_by(:version => 3)
174     way_v3.redact!(create(:redaction))
175
176     get way_history_path(:id => way)
177     assert_response :success
178     assert_template "browse/history"
179
180     # there are 4 revisions of the redacted way, but only 2
181     # should be showing details here.
182     assert_select ".browse-section", 4
183     assert_select ".browse-section.browse-redacted", 2
184     assert_select ".browse-section.browse-way", 2
185   end
186
187   def test_redacted_relation_history
188     relation = create(:relation, :with_history, :version => 4)
189     relation_v1 = relation.old_relations.find_by(:version => 1)
190     relation_v1.redact!(create(:redaction))
191     relation_v3 = relation.old_relations.find_by(:version => 3)
192     relation_v3.redact!(create(:redaction))
193
194     get relation_history_path(:id => relation)
195     assert_response :success
196     assert_template "browse/history"
197
198     # there are 4 revisions of the redacted relation, but only 2
199     # should be showing details here.
200     assert_select ".browse-section", 4
201     assert_select ".browse-section.browse-redacted", 2
202     assert_select ".browse-section.browse-relation", 2
203   end
204
205   def test_query
206     get query_path
207     assert_response :success
208     assert_template "browse/query"
209   end
210 end