3 class BrowseControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/node/1", :method => :get },
9 { :controller => "browse", :action => "node", :id => "1" }
12 { :path => "/node/1/history", :method => :get },
13 { :controller => "browse", :action => "node_history", :id => "1" }
16 { :path => "/way/1", :method => :get },
17 { :controller => "browse", :action => "way", :id => "1" }
20 { :path => "/way/1/history", :method => :get },
21 { :controller => "browse", :action => "way_history", :id => "1" }
24 { :path => "/relation/1", :method => :get },
25 { :controller => "browse", :action => "relation", :id => "1" }
28 { :path => "/relation/1/history", :method => :get },
29 { :controller => "browse", :action => "relation_history", :id => "1" }
32 { :path => "/changeset/1", :method => :get },
33 { :controller => "browse", :action => "changeset", :id => "1" }
36 { :path => "/query", :method => :get },
37 { :controller => "browse", :action => "query" }
41 def test_read_relation
42 relation = create(:relation)
43 browse_check :relation_path, relation.id, "browse/feature"
44 assert_select "h4", /^Version/ do
45 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
47 assert_select "a[href='#{api_relation_path relation}']", :count => 1
50 def test_read_relation_history
51 relation = create(:relation, :with_history)
52 browse_check :relation_history_path, relation.id, "browse/history"
53 assert_select "h4", /^Version/ do
54 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
60 browse_check :way_path, way.id, "browse/feature"
61 assert_select "h4", /^Version/ do
62 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
64 assert_select "a[href='#{api_way_path way}']", :count => 1
67 def test_read_way_history
68 way = create(:way, :with_history)
69 browse_check :way_history_path, way.id, "browse/history"
70 assert_select "h4", /^Version/ do
71 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
77 browse_check :node_path, node.id, "browse/feature"
78 assert_select "h4", /^Version/ do
79 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
81 assert_select "a[href='#{api_node_path node}']", :count => 1
84 def test_read_deleted_node
85 node = create(:node, :visible => false)
86 browse_check :node_path, node.id, "browse/feature"
87 assert_select "h4", /^Version/ do
88 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
90 assert_select "a[href='#{api_node_path node}']", :count => 0
93 def test_read_node_history
94 node = create(:node, :with_history)
95 browse_check :node_history_path, node.id, "browse/history"
96 assert_select "h4", /^Version/ do
97 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
101 def test_read_changeset
103 changeset = create(:changeset, :user => user)
104 create(:changeset, :user => user)
105 browse_check :changeset_path, changeset.id, "browse/changeset"
108 def test_read_private_changeset
110 changeset = create(:changeset, :user => create(:user, :data_public => false))
111 create(:changeset, :user => user)
112 browse_check :changeset_path, changeset.id, "browse/changeset"
115 def test_read_changeset_hidden_comments
116 changeset = create(:changeset)
117 create_list(:changeset_comment, 3, :changeset => changeset)
118 create(:changeset_comment, :visible => false, :changeset => changeset)
120 browse_check :changeset_path, changeset.id, "browse/changeset"
121 assert_select "div.changeset-comments ul li", :count => 3
123 session_for(create(:moderator_user))
125 browse_check :changeset_path, changeset.id, "browse/changeset"
126 assert_select "div.changeset-comments ul li", :count => 4
130 # Methods to check redaction.
132 # note that these are presently highly reliant on the structure of the
133 # page for the selection tests, which doesn't work out particularly
134 # well if that structure changes. so... if you change the page layout
135 # then please make it more easily (and robustly) testable!
137 def test_redacted_node
138 node = create(:node, :with_history, :deleted, :version => 2)
139 node_v1 = node.old_nodes.find_by(:version => 1)
140 node_v1.redact!(create(:redaction))
142 get node_path(:id => node)
143 assert_response :success
144 assert_template "feature"
146 # check that we don't show lat/lon for a redacted node.
147 assert_select ".browse-section", 1
148 assert_select ".browse-section.browse-node", 1
149 assert_select ".browse-section.browse-node .latitude", 0
150 assert_select ".browse-section.browse-node .longitude", 0
153 def test_redacted_node_history
154 node = create(:node, :with_history, :deleted, :version => 2)
155 node_v1 = node.old_nodes.find_by(:version => 1)
156 node_v1.redact!(create(:redaction))
158 get node_history_path(:id => node)
159 assert_response :success
160 assert_template "browse/history"
162 # there are 2 revisions of the redacted node, but only one
163 # should be showing details here.
164 assert_select ".browse-section", 2
165 assert_select ".browse-section.browse-redacted", 1
166 assert_select ".browse-section.browse-node", 1
167 assert_select ".browse-section.browse-node .latitude", 0
168 assert_select ".browse-section.browse-node .longitude", 0
171 def test_redacted_way_history
172 way = create(:way, :with_history, :version => 4)
173 way_v1 = way.old_ways.find_by(:version => 1)
174 way_v1.redact!(create(:redaction))
175 way_v3 = way.old_ways.find_by(:version => 3)
176 way_v3.redact!(create(:redaction))
178 get way_history_path(:id => way)
179 assert_response :success
180 assert_template "browse/history"
182 # there are 4 revisions of the redacted way, but only 2
183 # should be showing details here.
184 assert_select ".browse-section", 4
185 assert_select ".browse-section.browse-redacted", 2
186 assert_select ".browse-section.browse-way", 2
189 def test_redacted_relation_history
190 relation = create(:relation, :with_history, :version => 4)
191 relation_v1 = relation.old_relations.find_by(:version => 1)
192 relation_v1.redact!(create(:redaction))
193 relation_v3 = relation.old_relations.find_by(:version => 3)
194 relation_v3.redact!(create(:redaction))
196 get relation_history_path(:id => relation)
197 assert_response :success
198 assert_template "browse/history"
200 # there are 4 revisions of the redacted relation, but only 2
201 # should be showing details here.
202 assert_select ".browse-section", 4
203 assert_select ".browse-section.browse-redacted", 2
204 assert_select ".browse-section.browse-relation", 2
209 assert_response :success
210 assert_template "browse/query"
215 # This is a convenience method for most of the above checks
216 # First we check that when we don't have an id, it will correctly return a 404
217 # then we check that we get the correct 404 when a non-existant id is passed
218 # then we check that it will get a successful response, when we do pass an id
219 def browse_check(path, id, template)
220 path_method = method(path)
222 assert_raise ActionController::UrlGenerationError do
226 assert_raise ActionController::UrlGenerationError do
227 get path_method.call(:id => -10) # we won't have an id that's negative
230 get path_method.call(:id => 0)
231 assert_response :not_found
232 assert_template "browse/not_found"
233 assert_template :layout => "map"
235 get path_method.call(:id => 0), :xhr => true
236 assert_response :not_found
237 assert_template "browse/not_found"
238 assert_template :layout => "xhr"
240 get path_method.call(:id => id)
241 assert_response :success
242 assert_template template
243 assert_template :layout => "map"
245 get path_method.call(:id => id), :xhr => true
246 assert_response :success
247 assert_template template
248 assert_template :layout => "xhr"