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", :max_id => id)
84 assert_redirected_to :controller => :errors, :action => :bad_request
89 # This should display the last 20 changesets closed in a specific area
91 changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001)
92 other_changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 0, :max_lat => 1, :min_lon => 0, :max_lon => 1)
94 # First check they all show up without a bbox parameter
95 get history_path(:format => "html", :list => "1"), :xhr => true
96 assert_response :success
97 assert_template "index"
98 check_index_result(changesets + other_changesets)
100 # Then check with bbox parameter
101 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5")
102 assert_response :success
103 assert_template "history"
104 assert_template :layout => "map"
105 assert_select "h2", :text => "Changesets", :count => 1
106 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
107 assert_select "[href=?]", "http://www.example.com/history/feed?bbox=4.5%2C4.5%2C5.5%2C5.5"
110 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1"), :xhr => true
111 assert_response :success
112 assert_template "index"
114 check_index_result(changesets)
118 # Checks the display of the user changesets listing
121 create(:changeset, :user => user, :num_changes => 1)
122 create(:changeset, :closed, :user => user, :num_changes => 1)
125 get history_path(:format => "html", :display_name => user.display_name)
126 assert_response :success
127 assert_template "history"
128 assert_template :layout => "map"
129 assert_select "h2", :text => "Changesets by #{user.display_name}", :count => 1 do
130 assert_select "a[href=?]", user_path(user)
132 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
133 assert_select "[href=?]", "http://www.example.com/user/#{ERB::Util.url_encode(user.display_name)}/history/feed"
136 get history_path(:format => "html", :display_name => user.display_name, :list => "1"), :xhr => true
137 assert_response :success
138 assert_template "index"
140 check_index_result(user.changesets)
144 # Checks the display of the user changesets listing for a private user
145 def test_index_private_user
146 private_user = create(:user, :data_public => false)
147 create(:changeset, :user => private_user)
148 create(:changeset, :closed, :user => private_user)
150 get history_path(:format => "html", :display_name => private_user.display_name)
151 assert_response :success
152 assert_template "history"
154 get history_path(:format => "html", :display_name => private_user.display_name, :list => "1"), :xhr => true
155 assert_response :success
156 assert_template "index"
158 check_index_result([])
162 # Check the not found of the index user changesets
163 def test_index_user_not_found
164 get history_path(:format => "html", :display_name => "Some random user")
165 assert_response :not_found
166 assert_template "users/no_such_user"
168 get history_path(:format => "html", :display_name => "Some random user", :list => "1"), :xhr => true
169 assert_response :not_found
170 assert_template "users/no_such_user"
174 # Checks the display of the friends changesets listing
175 def test_index_friends
176 private_user = create(:user, :data_public => true)
177 follow = create(:follow, :follower => private_user)
178 changeset = create(:changeset, :user => follow.following, :num_changes => 1)
179 _changeset2 = create(:changeset, :user => create(:user), :num_changes => 1)
181 get friend_changesets_path
182 assert_redirected_to login_path(:referer => friend_changesets_path)
184 session_for(private_user)
186 get friend_changesets_path
187 assert_response :success
188 assert_template "history"
190 get friend_changesets_path(:list => "1"), :xhr => true
191 assert_response :success
192 assert_template "index"
194 check_index_result([changeset])
198 # Checks the display of the nearby user changesets listing
199 def test_index_nearby
200 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
201 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
202 far_away_user = create(:user, :home_lat => 51.0, :home_lon => 130)
203 changeset = create(:changeset, :user => user, :num_changes => 1)
204 _changeset2 = create(:changeset, :user => far_away_user, :num_changes => 1)
206 get nearby_changesets_path
207 assert_redirected_to login_path(:referer => nearby_changesets_path)
209 session_for(private_user)
211 get nearby_changesets_path
212 assert_response :success
213 assert_template "history"
215 get nearby_changesets_path(:list => "1"), :xhr => true
216 assert_response :success
217 assert_template "index"
219 check_index_result([changeset])
223 # Check that we can't request later pages of the changesets index
224 def test_index_max_id
225 changeset = create(:changeset, :num_changes => 1)
226 _changeset2 = create(:changeset, :num_changes => 1)
228 get history_path(:format => "html", :max_id => changeset.id), :xhr => true
229 assert_response :success
230 assert_template "history"
231 assert_template :layout => "xhr"
232 assert_select "h2", :text => "Changesets", :count => 1
234 get history_path(:format => "html", :list => "1", :max_id => changeset.id), :xhr => true
235 assert_response :success
236 assert_template "index"
238 check_index_result([changeset])
242 # Check that a list with a next page link works
244 create_list(:changeset, 50)
246 get history_path(:format => "html")
247 assert_response :success
249 get history_path(:format => "html"), :xhr => true
250 assert_response :success
254 changeset = create(:changeset)
255 create(:changeset_tag, :changeset => changeset, :k => "comment", :v => "tested-changeset-comment")
256 commenting_user = create(:user)
257 changeset_comment = create(:changeset_comment, :changeset => changeset, :author => commenting_user, :body => "Unwanted comment")
259 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
260 assert_dom "h2", :text => "Changeset: #{changeset.id}"
261 assert_dom "p", :text => "tested-changeset-comment"
262 assert_dom "li#c#{changeset_comment.id}" do
263 assert_dom "> small", :text => /^Comment from #{commenting_user.display_name}/
264 assert_dom "a[href='#{user_path(commenting_user)}']"
268 def test_show_closed_changeset
269 changeset = create(:changeset, :closed)
271 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
274 def test_show_private_changeset
276 changeset = create(:changeset, :user => create(:user, :data_public => false))
277 create(:changeset, :user => user)
279 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
282 def test_show_element_links
283 changeset = create(:changeset)
284 node = create(:node, :with_history, :changeset => changeset)
285 way = create(:way, :with_history, :changeset => changeset)
286 relation = create(:relation, :with_history, :changeset => changeset)
288 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
289 assert_dom "a[href='#{node_path node}']", :count => 1
290 assert_dom "a[href='#{old_node_path node, 1}']", :count => 1
291 assert_dom "a[href='#{way_path way}']", :count => 1
292 assert_dom "a[href='#{old_way_path way, 1}']", :count => 1
293 assert_dom "a[href='#{relation_path relation}']", :count => 1
294 assert_dom "a[href='#{old_relation_path relation, 1}']", :count => 1
297 def test_show_paginated_element_links
299 changeset = create(:changeset)
300 nodes = create_list(:node, page_size + 1, :with_history, :changeset => changeset)
301 ways = create_list(:way, page_size + 1, :with_history, :changeset => changeset)
302 relations = create_list(:relation, page_size + 1, :with_history, :changeset => changeset)
304 sidebar_browse_check :changeset_path, changeset.id, "changesets/show"
305 page_size.times do |i|
306 assert_dom "a[href='#{node_path nodes[i]}']", :count => 1
307 assert_dom "a[href='#{old_node_path nodes[i], 1}']", :count => 1
308 assert_dom "a[href='#{way_path ways[i]}']", :count => 1
309 assert_dom "a[href='#{old_way_path ways[i], 1}']", :count => 1
310 assert_dom "a[href='#{relation_path relations[i]}']", :count => 1
311 assert_dom "a[href='#{old_relation_path relations[i], 1}']", :count => 1
315 def test_show_adjacent_changesets
317 changesets = create_list(:changeset, 3, :user => user, :num_changes => 1)
319 sidebar_browse_check :changeset_path, changesets[1].id, "changesets/show"
320 assert_dom "a[href='#{changeset_path changesets[0]}']", :count => 1
321 assert_dom "a[href='#{changeset_path changesets[2]}']", :count => 1
324 def test_show_adjacent_nonempty_changesets
326 changeset1 = create(:changeset, :user => user, :num_changes => 1)
327 create(:changeset, :user => user, :num_changes => 0)
328 changeset3 = create(:changeset, :user => user, :num_changes => 1)
329 create(:changeset, :user => user, :num_changes => 0)
330 changeset5 = create(:changeset, :user => user, :num_changes => 1)
332 sidebar_browse_check :changeset_path, changeset3.id, "changesets/show"
333 assert_dom "a[href='#{changeset_path changeset1}']", :count => 1
334 assert_dom "a[href='#{changeset_path changeset5}']", :count => 1
338 # This should display the last 20 non-empty changesets
340 changeset = create(:changeset, :num_changes => 1)
341 create(:changeset_tag, :changeset => changeset)
342 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
343 closed_changeset = create(:changeset, :closed, :num_changes => 1)
344 create(:changeset_tag, :changeset => closed_changeset, :k => "website", :v => "https://osm.org/")
345 _empty_changeset = create(:changeset, :num_changes => 0)
347 get history_feed_path(:format => :atom)
348 assert_response :success
349 assert_template "index"
350 assert_equal "application/atom+xml", response.media_type
352 check_feed_result([closed_changeset, changeset])
356 # This should correctly escape XML special characters in the comment
357 def test_feed_with_comment_tag
358 changeset = create(:changeset, :num_changes => 1)
359 create(:changeset_tag, :changeset => changeset, :k => "comment", :v => "tested<changeset>comment")
361 get history_feed_path(:format => :atom)
362 assert_response :success
363 assert_template "index"
364 assert_equal "application/atom+xml", response.media_type
366 check_feed_result([changeset])
370 # This should display the last 20 changesets closed in a specific area
372 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)
373 create(:changeset_tag, :changeset => changeset)
374 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
375 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)
376 _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)
377 _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)
379 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
380 assert_response :success
381 assert_template "index"
382 assert_equal "application/atom+xml", response.media_type
384 check_feed_result([closed_changeset, changeset])
388 # Checks the display of the user changesets feed
391 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
392 create(:changeset_tag, :changeset => changesets[1])
393 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
394 _other_changeset = create(:changeset)
396 get history_feed_path(:format => :atom, :display_name => user.display_name)
398 assert_response :success
399 assert_template "index"
400 assert_equal "application/atom+xml", response.media_type
402 check_feed_result(changesets.reverse)
406 # Check the not found of the user changesets feed
407 def test_feed_user_not_found
408 get history_feed_path(:format => "atom", :display_name => "Some random user")
409 assert_response :not_found
413 # Check that we can't request later pages of the changesets feed
415 get history_feed_path(:format => "atom", :max_id => 100)
416 assert_redirected_to :action => :feed
422 # check the result of a index
423 def check_index_result(changesets)
424 assert_select "ol.changesets", :count => [changesets.size, 1].min do
425 assert_select "li", :count => changesets.size
427 changesets.each do |changeset|
428 assert_select "li#changeset_#{changeset.id}", :count => 1
434 # check the result of a feed
435 def check_feed_result(changesets)
436 assert_operator changesets.size, :<=, 20
438 assert_select "feed", :count => [changesets.size, 1].min do
439 assert_select "> title", :count => 1, :text => /^Changesets/
440 assert_select "> entry", :count => changesets.size do |entries|
441 entries.zip(changesets) do |entry, changeset|
442 assert_select entry, "> id", :text => changeset_url(:id => changeset.id)
444 changeset_comment = changeset.tags["comment"]
446 assert_select entry, "> title", :count => 1, :text => "Changeset #{changeset.id} - #{changeset_comment}"
448 assert_select entry, "> title", :count => 1, :text => "Changeset #{changeset.id}"
451 assert_select entry, "> content > xhtml|div > xhtml|table" do
452 if changeset.tags.empty?
453 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 0
455 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 1 do
456 changeset.tags.each_key do |key|
457 assert_select "> xhtml|tr > xhtml|td", :text => /^#{key} = /