3 class ChangesetsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/user/name/history", :method => :get },
9 { :controller => "changesets", :action => "index", :display_name => "name" }
12 { :path => "/user/name/history/feed", :method => :get },
13 { :controller => "changesets", :action => "feed", :display_name => "name", :format => :atom }
16 { :path => "/history/friends", :method => :get },
17 { :controller => "changesets", :action => "index", :friends => true, :format => :html }
20 { :path => "/history/nearby", :method => :get },
21 { :controller => "changesets", :action => "index", :nearby => true, :format => :html }
24 { :path => "/history", :method => :get },
25 { :controller => "changesets", :action => "index" }
28 { :path => "/history/feed", :method => :get },
29 { :controller => "changesets", :action => "feed", :format => :atom }
34 # This should display the last 20 changesets closed
36 changesets = create_list(:changeset, 30, :num_changes => 1)
38 get history_path(:format => "html")
39 assert_response :success
40 assert_template "history"
41 assert_template :layout => "map"
42 assert_select "h2", :text => "Changesets", :count => 1
43 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
44 assert_select "[href=?]", "http://www.example.com/history/feed"
47 get history_path(:format => "html", :list => "1"), :xhr => true
48 assert_response :success
49 assert_template "index"
51 check_index_result(changesets.last(20))
55 # This should display the last 20 changesets closed
57 changesets = create_list(:changeset, 30, :num_changes => 1)
59 get history_path(:format => "html"), :xhr => true
60 assert_response :success
61 assert_template "history"
62 assert_template :layout => "xhr"
63 assert_select "h2", :text => "Changesets", :count => 1
64 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
65 assert_select "[href=?]", "http://www.example.com/history/feed"
68 get history_path(:format => "html", :list => "1"), :xhr => true
69 assert_response :success
70 assert_template "index"
72 check_index_result(changesets.last(20))
76 # This should display the last 20 changesets closed in a specific area
78 changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001)
79 other_changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 0, :max_lat => 1, :min_lon => 0, :max_lon => 1)
81 # First check they all show up without a bbox parameter
82 get history_path(:format => "html", :list => "1"), :xhr => true
83 assert_response :success
84 assert_template "index"
85 check_index_result(changesets + other_changesets)
87 # Then check with bbox parameter
88 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5")
89 assert_response :success
90 assert_template "history"
91 assert_template :layout => "map"
92 assert_select "h2", :text => "Changesets", :count => 1
93 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
94 assert_select "[href=?]", "http://www.example.com/history/feed?bbox=4.5%2C4.5%2C5.5%2C5.5"
97 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1"), :xhr => true
98 assert_response :success
99 assert_template "index"
101 check_index_result(changesets)
105 # Checks the display of the user changesets listing
108 create(:changeset, :user => user)
109 create(:changeset, :closed, :user => user)
111 get history_path(:format => "html", :display_name => user.display_name)
112 assert_response :success
113 assert_template "history"
114 assert_template :layout => "map"
115 assert_select "h2", :text => "Changesets by #{user.display_name}", :count => 1
116 assert_select "link[rel='alternate'][type='application/atom+xml']", :count => 1 do
117 assert_select "[href=?]", "http://www.example.com/user/#{ERB::Util.url_encode(user.display_name)}/history/feed"
120 get history_path(:format => "html", :display_name => user.display_name, :list => "1"), :xhr => true
121 assert_response :success
122 assert_template "index"
124 check_index_result(user.changesets)
128 # Checks the display of the user changesets listing for a private user
129 def test_index_private_user
130 private_user = create(:user, :data_public => false)
131 create(:changeset, :user => private_user)
132 create(:changeset, :closed, :user => private_user)
134 get history_path(:format => "html", :display_name => private_user.display_name)
135 assert_response :success
136 assert_template "history"
138 get history_path(:format => "html", :display_name => private_user.display_name, :list => "1"), :xhr => true
139 assert_response :success
140 assert_template "index"
142 check_index_result([])
146 # Check the not found of the index user changesets
147 def test_index_user_not_found
148 get history_path(:format => "html", :display_name => "Some random user")
149 assert_response :not_found
150 assert_template "users/no_such_user"
152 get history_path(:format => "html", :display_name => "Some random user", :list => "1"), :xhr => true
153 assert_response :not_found
154 assert_template "users/no_such_user"
158 # Checks the display of the friends changesets listing
159 def test_index_friends
160 private_user = create(:user, :data_public => true)
161 friendship = create(:friendship, :befriender => private_user)
162 changeset = create(:changeset, :user => friendship.befriendee, :num_changes => 1)
163 _changeset2 = create(:changeset, :user => create(:user), :num_changes => 1)
165 get friend_changesets_path
166 assert_response :redirect
167 assert_redirected_to login_path(:referer => friend_changesets_path)
169 session_for(private_user)
171 get friend_changesets_path
172 assert_response :success
173 assert_template "history"
175 get friend_changesets_path(:list => "1"), :xhr => true
176 assert_response :success
177 assert_template "index"
179 check_index_result([changeset])
183 # Checks the display of the nearby user changesets listing
184 def test_index_nearby
185 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
186 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
187 far_away_user = create(:user, :home_lat => 51.0, :home_lon => 130)
188 changeset = create(:changeset, :user => user, :num_changes => 1)
189 _changeset2 = create(:changeset, :user => far_away_user, :num_changes => 1)
191 get nearby_changesets_path
192 assert_response :redirect
193 assert_redirected_to login_path(:referer => nearby_changesets_path)
195 session_for(private_user)
197 get nearby_changesets_path
198 assert_response :success
199 assert_template "history"
201 get nearby_changesets_path(:list => "1"), :xhr => true
202 assert_response :success
203 assert_template "index"
205 check_index_result([changeset])
209 # Check that we can't request later pages of the changesets index
210 def test_index_max_id
211 changeset = create(:changeset, :num_changes => 1)
212 _changeset2 = create(:changeset, :num_changes => 1)
214 get history_path(:format => "html", :max_id => changeset.id), :xhr => true
215 assert_response :success
216 assert_template "history"
217 assert_template :layout => "xhr"
218 assert_select "h2", :text => "Changesets", :count => 1
220 get history_path(:format => "html", :list => "1", :max_id => changeset.id), :xhr => true
221 assert_response :success
222 assert_template "index"
224 check_index_result([changeset])
228 # Check that a list with a next page link works
230 create_list(:changeset, 50)
232 get history_path(:format => "html")
233 assert_response :success
235 get history_path(:format => "html"), :xhr => true
236 assert_response :success
240 # This should display the last 20 non-empty changesets
242 changeset = create(:changeset, :num_changes => 1)
243 create(:changeset_tag, :changeset => changeset)
244 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
245 closed_changeset = create(:changeset, :closed, :num_changes => 1)
246 create(:changeset_tag, :changeset => closed_changeset, :k => "website", :v => "https://osm.org/")
247 _empty_changeset = create(:changeset, :num_changes => 0)
249 get history_feed_path(:format => :atom)
250 assert_response :success
251 assert_template "index"
252 assert_equal "application/atom+xml", response.media_type
254 check_feed_result([closed_changeset, changeset])
258 # This should display the last 20 changesets closed in a specific area
260 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)
261 create(:changeset_tag, :changeset => changeset)
262 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
263 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)
264 _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)
265 _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)
267 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
268 assert_response :success
269 assert_template "index"
270 assert_equal "application/atom+xml", response.media_type
272 check_feed_result([closed_changeset, changeset])
276 # Checks the display of the user changesets feed
279 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
280 create(:changeset_tag, :changeset => changesets[1])
281 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
282 _other_changeset = create(:changeset)
284 get history_feed_path(:format => :atom, :display_name => user.display_name)
286 assert_response :success
287 assert_template "index"
288 assert_equal "application/atom+xml", response.media_type
290 check_feed_result(changesets.reverse)
294 # Check the not found of the user changesets feed
295 def test_feed_user_not_found
296 get history_feed_path(:format => "atom", :display_name => "Some random user")
297 assert_response :not_found
301 # Check that we can't request later pages of the changesets feed
303 get history_feed_path(:format => "atom", :max_id => 100)
304 assert_response :redirect
305 assert_redirected_to :action => :feed
311 # check the result of a index
312 def check_index_result(changesets)
313 assert_select "ol.changesets", :count => [changesets.size, 1].min do
314 assert_select "li", :count => changesets.size
316 changesets.each do |changeset|
317 assert_select "li#changeset_#{changeset.id}", :count => 1
323 # check the result of a feed
324 def check_feed_result(changesets)
325 assert_operator changesets.size, :<=, 20
327 assert_select "feed", :count => [changesets.size, 1].min do
328 assert_select "> title", :count => 1, :text => /^Changesets/
329 assert_select "> entry", :count => changesets.size do |entries|
330 entries.zip(changesets) do |entry, changeset|
331 assert_select entry, "> id", :text => changeset_url(:id => changeset.id)
332 assert_select entry, "> content > xhtml|div > xhtml|table" do
333 if changeset.tags.empty?
334 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 0
336 assert_select "> xhtml|tr > xhtml|td > xhtml|table", :count => 1 do
337 changeset.tags.each_key do |key|
338 assert_select "> xhtml|tr > xhtml|td", :text => /^#{key} = /