3 class ChangesetsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/changeset/1", :method => :get },
9 { :controller => "changesets", :action => "show", :id => "1" }
12 { :path => "/user/name/history", :method => :get },
13 { :controller => "changesets", :action => "index", :display_name => "name" }
16 { :path => "/user/name/history/feed", :method => :get },
17 { :controller => "changesets", :action => "feed", :display_name => "name", :format => :atom }
20 { :path => "/history/friends", :method => :get },
21 { :controller => "changesets", :action => "index", :friends => true, :format => :html }
24 { :path => "/history/nearby", :method => :get },
25 { :controller => "changesets", :action => "index", :nearby => true, :format => :html }
28 { :path => "/history", :method => :get },
29 { :controller => "changesets", :action => "index" }
32 { :path => "/history/feed", :method => :get },
33 { :controller => "changesets", :action => "feed", :format => :atom }
38 # This should display the last 20 changesets closed
40 changesets = create_list(:changeset, 30, :num_changes => 1)
42 get history_path(:format => "html")
43 assert_response :success
44 assert_template "history"
45 assert_template :layout => "map"
46 assert_select "h2", :text => "Changesets", :count => 1
47 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
48 assert_select "[href=?]", "http://www.example.com/history/feed"
51 get history_path(:format => "html", :list => "1"), :xhr => true
52 assert_response :success
53 assert_template "index"
55 check_index_result(changesets.last(20))
59 # This should display the last 20 changesets closed
61 changesets = create_list(:changeset, 30, :num_changes => 1)
63 get history_path(:format => "html"), :xhr => true
64 assert_response :success
65 assert_template "history"
66 assert_template :layout => "xhr"
67 assert_select "h2", :text => "Changesets", :count => 1
68 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
69 assert_select "[href=?]", "http://www.example.com/history/feed"
72 get history_path(:format => "html", :list => "1"), :xhr => true
73 assert_response :success
74 assert_template "index"
76 check_index_result(changesets.last(20))
80 # This should report an error
81 def test_index_invalid_xhr
82 %w[-1 0 fred].each do |id|
83 get history_path(:format => "html", :list => "1", :before => id)
84 assert_redirected_to :controller => :errors, :action => :bad_request
86 get history_path(:format => "html", :list => "1", :after => id)
87 assert_redirected_to :controller => :errors, :action => :bad_request
92 # This should display the last 20 changesets closed in a specific area
94 changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001)
95 other_changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 0, :max_lat => 1, :min_lon => 0, :max_lon => 1)
97 # First check they all show up without a bbox parameter
98 get history_path(:format => "html", :list => "1"), :xhr => true
99 assert_response :success
100 assert_template "index"
101 check_index_result(changesets + other_changesets)
103 # Then check with bbox parameter
104 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5")
105 assert_response :success
106 assert_template "history"
107 assert_template :layout => "map"
108 assert_select "h2", :text => "Changesets", :count => 1
109 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
110 assert_select "[href=?]", "http://www.example.com/history/feed?bbox=4.5%2C4.5%2C5.5%2C5.5"
113 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1"), :xhr => true
114 assert_response :success
115 assert_template "index"
117 check_index_result(changesets)
121 # Checks the display of the user changesets listing
124 create(:changeset, :user => user, :num_changes => 1)
125 create(:changeset, :closed, :user => user, :num_changes => 1)
128 get history_path(:format => "html", :display_name => user.display_name)
129 assert_response :success
130 assert_template "history"
131 assert_template :layout => "map"
132 assert_select "h2", :text => "Changesets by #{user.display_name}", :count => 1 do
133 assert_select "a[href=?]", user_path(user)
135 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
136 assert_select "[href=?]", "http://www.example.com/user/#{ERB::Util.url_encode(user.display_name)}/history/feed"
139 get history_path(:format => "html", :display_name => user.display_name, :list => "1"), :xhr => true
140 assert_response :success
141 assert_template "index"
143 check_index_result(user.changesets)
147 # Checks the display of the user changesets listing for a private user
148 def test_index_private_user
149 private_user = create(:user, :data_public => false)
150 create(:changeset, :user => private_user)
151 create(:changeset, :closed, :user => private_user)
153 get history_path(:format => "html", :display_name => private_user.display_name)
154 assert_response :success
155 assert_template "history"
157 get history_path(:format => "html", :display_name => private_user.display_name, :list => "1"), :xhr => true
158 assert_response :success
159 assert_template "index"
161 check_index_result([])
165 # Check the not found of the index user changesets
166 def test_index_user_not_found
167 get history_path(:format => "html", :display_name => "Some random user")
168 assert_response :not_found
169 assert_template "users/no_such_user"
171 get history_path(:format => "html", :display_name => "Some random user", :list => "1"), :xhr => true
172 assert_response :not_found
173 assert_template "users/no_such_user"
177 # Checks the display of the friends changesets listing
178 def test_index_friends
179 private_user = create(:user, :data_public => true)
180 follow = create(:follow, :follower => private_user)
181 changeset = create(:changeset, :user => follow.following, :num_changes => 1)
182 _changeset2 = create(:changeset, :user => create(:user), :num_changes => 1)
184 get friend_changesets_path
185 assert_redirected_to login_path(:referer => friend_changesets_path)
187 session_for(private_user)
189 get friend_changesets_path
190 assert_response :success
191 assert_template "history"
193 get friend_changesets_path(:list => "1"), :xhr => true
194 assert_response :success
195 assert_template "index"
197 check_index_result([changeset])
201 # Checks the display of the nearby user changesets listing
202 def test_index_nearby
203 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
204 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
205 far_away_user = create(:user, :home_lat => 51.0, :home_lon => 130)
206 changeset = create(:changeset, :user => user, :num_changes => 1)
207 _changeset2 = create(:changeset, :user => far_away_user, :num_changes => 1)
209 get nearby_changesets_path
210 assert_redirected_to login_path(:referer => nearby_changesets_path)
212 session_for(private_user)
214 get nearby_changesets_path
215 assert_response :success
216 assert_template "history"
218 get nearby_changesets_path(:list => "1"), :xhr => true
219 assert_response :success
220 assert_template "index"
222 check_index_result([changeset])
226 # Check that we can't request later pages of the changesets index
227 def test_index_before_id
228 changeset1 = create(:changeset, :num_changes => 1)
229 changeset2 = create(:changeset, :num_changes => 1)
231 get history_path(:format => "html", :before => changeset2.id), :xhr => true
232 assert_response :success
233 assert_template "history"
234 assert_template :layout => "xhr"
235 assert_select "h2", :text => "Changesets", :count => 1
237 get history_path(:format => "html", :list => "1", :before => changeset2.id), :xhr => true
238 assert_response :success
239 assert_template "index"
241 check_index_result [changeset1]
244 def test_index_after_id
245 changeset1 = create(:changeset, :num_changes => 1)
246 changeset2 = create(:changeset, :num_changes => 1)
248 get history_path(:format => "html", :after => changeset1.id), :xhr => true
249 assert_response :success
250 assert_template "history"
251 assert_template :layout => "xhr"
252 assert_select "h2", :text => "Changesets", :count => 1
254 get history_path(:format => "html", :list => "1", :after => changeset1.id), :xhr => true
255 assert_response :success
256 assert_template "index"
258 check_index_result [changeset2]
262 # Check that a list with a next page link works
264 create_list(:changeset, 50)
266 get history_path(:format => "html")
267 assert_response :success
269 get history_path(:format => "html"), :xhr => true
270 assert_response :success
274 changeset = create(:changeset)
275 create(:changeset_tag, :changeset => changeset, :k => "comment", :v => "tested-changeset-comment")
276 commenting_user = create(:user)
277 changeset_comment = create(:changeset_comment, :changeset => changeset, :author => commenting_user, :body => "Unwanted comment")
279 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
280 assert_dom "h2", :text => "Changeset: #{changeset.id}"
281 assert_dom "p", :text => "tested-changeset-comment"
282 assert_dom "li#c#{changeset_comment.id}" do
283 assert_dom "> small", :text => /^Comment from #{commenting_user.display_name}/
284 assert_dom "a[href='#{user_path(commenting_user)}']"
288 def test_show_closed_changeset
289 changeset = create(:changeset, :closed)
291 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
294 def test_show_private_changeset
296 changeset = create(:changeset, :user => create(:user, :data_public => false))
297 create(:changeset, :user => user)
299 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
302 def test_show_element_links
303 changeset = create(:changeset)
304 node = create(:node, :with_history, :changeset => changeset)
305 way = create(:way, :with_history, :changeset => changeset)
306 relation = create(:relation, :with_history, :changeset => changeset)
308 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
309 assert_dom "a[href='#{node_path node}']", :count => 1
310 assert_dom "a[href='#{old_node_path node, 1}']", :count => 1
311 assert_dom "a[href='#{way_path way}']", :count => 1
312 assert_dom "a[href='#{old_way_path way, 1}']", :count => 1
313 assert_dom "a[href='#{relation_path relation}']", :count => 1
314 assert_dom "a[href='#{old_relation_path relation, 1}']", :count => 1
317 def test_show_paginated_element_links
319 changeset = create(:changeset)
320 nodes = create_list(:node, page_size + 1, :with_history, :changeset => changeset)
321 ways = create_list(:way, page_size + 1, :with_history, :changeset => changeset)
322 relations = create_list(:relation, page_size + 1, :with_history, :changeset => changeset)
324 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
325 page_size.times do |i|
326 assert_dom "a[href='#{node_path nodes[i]}']", :count => 1
327 assert_dom "a[href='#{old_node_path nodes[i], 1}']", :count => 1
328 assert_dom "a[href='#{way_path ways[i]}']", :count => 1
329 assert_dom "a[href='#{old_way_path ways[i], 1}']", :count => 1
330 assert_dom "a[href='#{relation_path relations[i]}']", :count => 1
331 assert_dom "a[href='#{old_relation_path relations[i], 1}']", :count => 1
335 def test_show_adjacent_changesets
337 changesets = create_list(:changeset, 3, :user => user, :num_changes => 1)
339 sidebar_browse_check :changeset_path, changesets[1].id, "changesets/show"
340 assert_dom "a[href='#{changeset_path changesets[0]}']", :count => 1
341 assert_dom "a[href='#{changeset_path changesets[2]}']", :count => 1
344 def test_show_adjacent_nonempty_changesets
346 changeset1 = create(:changeset, :user => user, :num_changes => 1)
347 create(:changeset, :user => user, :num_changes => 0)
348 changeset3 = create(:changeset, :user => user, :num_changes => 1)
349 create(:changeset, :user => user, :num_changes => 0)
350 changeset5 = create(:changeset, :user => user, :num_changes => 1)
352 sidebar_browse_check :changeset_path, changeset3.id, "changesets/show"
353 assert_dom "a[href='#{changeset_path changeset1}']", :count => 1
354 assert_dom "a[href='#{changeset_path changeset5}']", :count => 1
358 # This should display the last 20 non-empty changesets
360 changeset = create(:changeset, :num_changes => 1)
361 create(:changeset_tag, :changeset => changeset)
362 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
363 closed_changeset = create(:changeset, :closed, :num_changes => 1)
364 create(:changeset_tag, :changeset => closed_changeset, :k => "website", :v => "https://osm.org/")
365 _empty_changeset = create(:changeset, :num_changes => 0)
367 get history_feed_path(:format => :atom)
368 assert_response :success
369 assert_template "index"
370 assert_equal "application/atom+xml", response.media_type
372 check_feed_result([closed_changeset, changeset])
376 # This should correctly escape XML special characters in the comment
377 def test_feed_with_comment_tag
378 changeset = create(:changeset, :num_changes => 1)
379 create(:changeset_tag, :changeset => changeset, :k => "comment", :v => "tested<changeset>comment")
381 get history_feed_path(:format => :atom)
382 assert_response :success
383 assert_template "index"
384 assert_equal "application/atom+xml", response.media_type
386 check_feed_result([changeset])
390 # This should display the last 20 changesets closed in a specific area
392 changeset = create(:changeset, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
393 create(:changeset_tag, :changeset => changeset)
394 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
395 closed_changeset = create(:changeset, :closed, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
396 _elsewhere_changeset = create(:changeset, :num_changes => 1, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE)
397 _empty_changeset = create(:changeset, :num_changes => 0, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE)
399 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
400 assert_response :success
401 assert_template "index"
402 assert_equal "application/atom+xml", response.media_type
404 check_feed_result([closed_changeset, changeset])
408 # Checks the display of the user changesets feed
411 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
412 create(:changeset_tag, :changeset => changesets[1])
413 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
414 _other_changeset = create(:changeset)
416 get history_feed_path(:format => :atom, :display_name => user.display_name)
418 assert_response :success
419 assert_template "index"
420 assert_equal "application/atom+xml", response.media_type
422 check_feed_result(changesets.reverse)
426 # Check the not found of the user changesets feed
427 def test_feed_user_not_found
428 get history_feed_path(:format => "atom", :display_name => "Some random user")
429 assert_response :not_found
433 # Check that we can't request later pages of the changesets feed
435 get history_feed_path(:format => "atom", :before => 100)
436 assert_redirected_to :action => :feed
440 get history_feed_path(:format => "atom", :after => 100)
441 assert_redirected_to :action => :feed
447 # check the result of a index
448 def check_index_result(changesets)
449 assert_select "ol.changesets", :count => [changesets.size, 1].min do
450 assert_select "li", :count => changesets.size
452 changesets.each do |changeset|
453 assert_select "li#changeset_#{changeset.id}", :count => 1
459 # check the result of a feed
460 def check_feed_result(changesets)
461 assert_operator changesets.size, :<=, 20
463 assert_select "feed", :count => [changesets.size, 1].min do
464 assert_select "> title", :count => 1, :text => /^Changesets/
465 assert_select "> entry", :count => changesets.size do |entries|
466 entries.zip(changesets) do |entry, changeset|
467 assert_select entry, "> id", :text => changeset_url(:id => changeset.id)
469 changeset_comment = changeset.tags["comment"]
471 assert_select entry, "> title", :count => 1, :text => "Changeset #{changeset.id} - #{changeset_comment}"
473 assert_select entry, "> title", :count => 1, :text => "Changeset #{changeset.id}"
476 assert_select entry, "> content > xhtml|div > xhtml|table" do
477 if changeset.tags.empty?
478 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 0
480 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 1 do
481 changeset.tags.each_key do |key|
482 assert_select "> xhtml|tr > xhtml|td", :text => /^#{key} = /