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 _empty_changeset = create(:changeset, :num_changes => 0)
248 get history_feed_path(:format => :atom)
249 assert_response :success
250 assert_template "index"
251 assert_equal "application/atom+xml", response.media_type
253 check_feed_result([changeset, closed_changeset])
257 # This should display the last 20 changesets closed in a specific area
259 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)
260 create(:changeset_tag, :changeset => changeset)
261 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
262 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)
263 _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)
264 _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)
266 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
267 assert_response :success
268 assert_template "index"
269 assert_equal "application/atom+xml", response.media_type
271 check_feed_result([changeset, closed_changeset])
275 # Checks the display of the user changesets feed
278 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
279 create(:changeset_tag, :changeset => changesets[1])
280 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
281 _other_changeset = create(:changeset)
283 get history_feed_path(:format => :atom, :display_name => user.display_name)
285 assert_response :success
286 assert_template "index"
287 assert_equal "application/atom+xml", response.media_type
289 check_feed_result(changesets)
293 # Check the not found of the user changesets feed
294 def test_feed_user_not_found
295 get history_feed_path(:format => "atom", :display_name => "Some random user")
296 assert_response :not_found
300 # Check that we can't request later pages of the changesets feed
302 get history_feed_path(:format => "atom", :max_id => 100)
303 assert_response :redirect
304 assert_redirected_to :action => :feed
310 # check the result of a index
311 def check_index_result(changesets)
312 assert_select "ol.changesets", :count => [changesets.size, 1].min do
313 assert_select "li", :count => changesets.size
315 changesets.each do |changeset|
316 assert_select "li#changeset_#{changeset.id}", :count => 1
322 # check the result of a feed
323 def check_feed_result(changesets)
324 assert changesets.size <= 20
326 assert_select "feed", :count => [changesets.size, 1].min do
327 assert_select "> title", :count => 1, :text => /^Changesets/
328 assert_select "> entry", :count => changesets.size
330 changesets.each do |changeset|
331 assert_select "> entry > id", changeset_url(:id => changeset.id)