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
44 get history_path(:format => "html", :list => "1"), :xhr => true
45 assert_response :success
46 assert_template "index"
48 check_index_result(changesets.last(20))
52 # This should display the last 20 changesets closed
54 changesets = create_list(:changeset, 30, :num_changes => 1)
56 get history_path(:format => "html"), :xhr => true
57 assert_response :success
58 assert_template "history"
59 assert_template :layout => "xhr"
60 assert_select "h2", :text => "Changesets", :count => 1
62 get history_path(:format => "html", :list => "1"), :xhr => true
63 assert_response :success
64 assert_template "index"
66 check_index_result(changesets.last(20))
70 # This should display the last 20 changesets closed in a specific area
72 changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001)
73 other_changesets = create_list(:changeset, 10, :num_changes => 1, :min_lat => 0, :max_lat => 1, :min_lon => 0, :max_lon => 1)
75 # First check they all show up without a bbox parameter
76 get history_path(:format => "html", :list => "1"), :xhr => true
77 assert_response :success
78 assert_template "index"
79 check_index_result(changesets + other_changesets)
81 # Then check with bbox parameter
82 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5")
83 assert_response :success
84 assert_template "history"
85 assert_template :layout => "map"
86 assert_select "h2", :text => "Changesets", :count => 1
88 get history_path(:format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1"), :xhr => true
89 assert_response :success
90 assert_template "index"
92 check_index_result(changesets)
96 # Checks the display of the user changesets listing
99 create(:changeset, :user => user)
100 create(:changeset, :closed, :user => user)
102 get history_path(:format => "html", :display_name => user.display_name)
103 assert_response :success
104 assert_template "history"
106 get history_path(:format => "html", :display_name => user.display_name, :list => "1"), :xhr => true
107 assert_response :success
108 assert_template "index"
110 check_index_result(user.changesets)
114 # Checks the display of the user changesets listing for a private user
115 def test_index_private_user
116 private_user = create(:user, :data_public => false)
117 create(:changeset, :user => private_user)
118 create(:changeset, :closed, :user => private_user)
120 get history_path(:format => "html", :display_name => private_user.display_name)
121 assert_response :success
122 assert_template "history"
124 get history_path(:format => "html", :display_name => private_user.display_name, :list => "1"), :xhr => true
125 assert_response :success
126 assert_template "index"
128 check_index_result([])
132 # Check the not found of the index user changesets
133 def test_index_user_not_found
134 get history_path(:format => "html", :display_name => "Some random user")
135 assert_response :not_found
136 assert_template "users/no_such_user"
138 get history_path(:format => "html", :display_name => "Some random user", :list => "1"), :xhr => true
139 assert_response :not_found
140 assert_template "users/no_such_user"
144 # Checks the display of the friends changesets listing
145 def test_index_friends
146 private_user = create(:user, :data_public => true)
147 friendship = create(:friendship, :befriender => private_user)
148 changeset = create(:changeset, :user => friendship.befriendee, :num_changes => 1)
150 get friend_changesets_path
151 assert_response :redirect
152 assert_redirected_to :controller => :users, :action => :login, :referer => friend_changesets_path
154 session_for(private_user)
156 get friend_changesets_path
157 assert_response :success
158 assert_template "history"
160 get friend_changesets_path(:list => "1"), :xhr => true
161 assert_response :success
162 assert_template "index"
164 check_index_result([changeset])
168 # Checks the display of the nearby user changesets listing
169 def test_index_nearby
170 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
171 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
172 changeset = create(:changeset, :user => user, :num_changes => 1)
174 get nearby_changesets_path
175 assert_response :redirect
176 assert_redirected_to :controller => :users, :action => :login, :referer => nearby_changesets_path
178 session_for(private_user)
180 get nearby_changesets_path
181 assert_response :success
182 assert_template "history"
184 get nearby_changesets_path(:list => "1"), :xhr => true
185 assert_response :success
186 assert_template "index"
188 check_index_result([changeset])
192 # Check that we can't request later pages of the changesets index
193 def test_index_max_id
194 changeset = create(:changeset, :num_changes => 1)
195 _changeset2 = create(:changeset, :num_changes => 1)
197 get history_path(:format => "html", :max_id => changeset.id), :xhr => true
198 assert_response :success
199 assert_template "history"
200 assert_template :layout => "xhr"
201 assert_select "h2", :text => "Changesets", :count => 1
203 get history_path(:format => "html", :list => "1", :max_id => changeset.id), :xhr => true
204 assert_response :success
205 assert_template "index"
207 check_index_result([changeset])
211 # Check that a list with a next page link works
213 create_list(:changeset, 50)
215 get history_path(:format => "html")
216 assert_response :success
218 get history_path(:format => "html"), :xhr => true
219 assert_response :success
223 # This should display the last 20 non-empty changesets
225 changeset = create(:changeset, :num_changes => 1)
226 create(:changeset_tag, :changeset => changeset)
227 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
228 closed_changeset = create(:changeset, :closed, :num_changes => 1)
229 _empty_changeset = create(:changeset, :num_changes => 0)
231 get history_feed_path(:format => :atom)
232 assert_response :success
233 assert_template "index"
234 assert_equal "application/atom+xml", response.media_type
236 check_feed_result([changeset, closed_changeset])
240 # This should display the last 20 changesets closed in a specific area
242 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)
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, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
246 _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)
247 _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)
249 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
250 assert_response :success
251 assert_template "index"
252 assert_equal "application/atom+xml", response.media_type
254 check_feed_result([changeset, closed_changeset])
258 # Checks the display of the user changesets feed
261 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
262 create(:changeset_tag, :changeset => changesets[1])
263 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
264 _other_changeset = create(:changeset)
266 get history_feed_path(:format => :atom, :display_name => user.display_name)
268 assert_response :success
269 assert_template "index"
270 assert_equal "application/atom+xml", response.media_type
272 check_feed_result(changesets)
276 # Check the not found of the user changesets feed
277 def test_feed_user_not_found
278 get history_feed_path(:format => "atom", :display_name => "Some random user")
279 assert_response :not_found
283 # Check that we can't request later pages of the changesets feed
285 get history_feed_path(:format => "atom", :max_id => 100)
286 assert_response :redirect
287 assert_redirected_to :action => :feed
293 # check the result of a index
294 def check_index_result(changesets)
295 assert_select "ol.changesets", :count => [changesets.size, 1].min do
296 assert_select "li", :count => changesets.size
298 changesets.each do |changeset|
299 assert_select "li#changeset_#{changeset.id}", :count => 1
305 # check the result of a feed
306 def check_feed_result(changesets)
307 assert changesets.size <= 20
309 assert_select "feed", :count => [changesets.size, 1].min do
310 assert_select "> title", :count => 1, :text => /^Changesets/
311 assert_select "> entry", :count => changesets.size
313 changesets.each do |changeset|
314 assert_select "> entry > id", changeset_url(:id => changeset.id)