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)
149 _changeset2 = create(:changeset, :user => create(:user), :num_changes => 1)
151 get friend_changesets_path
152 assert_response :redirect
153 assert_redirected_to :controller => :users, :action => :login, :referer => friend_changesets_path
155 session_for(private_user)
157 get friend_changesets_path
158 assert_response :success
159 assert_template "history"
161 get friend_changesets_path(:list => "1"), :xhr => true
162 assert_response :success
163 assert_template "index"
165 check_index_result([changeset])
169 # Checks the display of the nearby user changesets listing
170 def test_index_nearby
171 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
172 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
173 far_away_user = create(:user, :home_lat => 51.0, :home_lon => 130)
174 changeset = create(:changeset, :user => user, :num_changes => 1)
175 _changeset2 = create(:changeset, :user => far_away_user, :num_changes => 1)
177 get nearby_changesets_path
178 assert_response :redirect
179 assert_redirected_to :controller => :users, :action => :login, :referer => nearby_changesets_path
181 session_for(private_user)
183 get nearby_changesets_path
184 assert_response :success
185 assert_template "history"
187 get nearby_changesets_path(:list => "1"), :xhr => true
188 assert_response :success
189 assert_template "index"
191 check_index_result([changeset])
195 # Check that we can't request later pages of the changesets index
196 def test_index_max_id
197 changeset = create(:changeset, :num_changes => 1)
198 _changeset2 = create(:changeset, :num_changes => 1)
200 get history_path(:format => "html", :max_id => changeset.id), :xhr => true
201 assert_response :success
202 assert_template "history"
203 assert_template :layout => "xhr"
204 assert_select "h2", :text => "Changesets", :count => 1
206 get history_path(:format => "html", :list => "1", :max_id => changeset.id), :xhr => true
207 assert_response :success
208 assert_template "index"
210 check_index_result([changeset])
214 # Check that a list with a next page link works
216 create_list(:changeset, 50)
218 get history_path(:format => "html")
219 assert_response :success
221 get history_path(:format => "html"), :xhr => true
222 assert_response :success
226 # This should display the last 20 non-empty changesets
228 changeset = create(:changeset, :num_changes => 1)
229 create(:changeset_tag, :changeset => changeset)
230 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
231 closed_changeset = create(:changeset, :closed, :num_changes => 1)
232 _empty_changeset = create(:changeset, :num_changes => 0)
234 get history_feed_path(:format => :atom)
235 assert_response :success
236 assert_template "index"
237 assert_equal "application/atom+xml", response.media_type
239 check_feed_result([changeset, closed_changeset])
243 # This should display the last 20 changesets closed in a specific area
245 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)
246 create(:changeset_tag, :changeset => changeset)
247 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
248 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)
249 _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)
250 _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)
252 get history_feed_path(:format => :atom, :bbox => "4.5,4.5,5.5,5.5")
253 assert_response :success
254 assert_template "index"
255 assert_equal "application/atom+xml", response.media_type
257 check_feed_result([changeset, closed_changeset])
261 # Checks the display of the user changesets feed
264 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
265 create(:changeset_tag, :changeset => changesets[1])
266 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
267 _other_changeset = create(:changeset)
269 get history_feed_path(:format => :atom, :display_name => user.display_name)
271 assert_response :success
272 assert_template "index"
273 assert_equal "application/atom+xml", response.media_type
275 check_feed_result(changesets)
279 # Check the not found of the user changesets feed
280 def test_feed_user_not_found
281 get history_feed_path(:format => "atom", :display_name => "Some random user")
282 assert_response :not_found
286 # Check that we can't request later pages of the changesets feed
288 get history_feed_path(:format => "atom", :max_id => 100)
289 assert_response :redirect
290 assert_redirected_to :action => :feed
296 # check the result of a index
297 def check_index_result(changesets)
298 assert_select "ol.changesets", :count => [changesets.size, 1].min do
299 assert_select "li", :count => changesets.size
301 changesets.each do |changeset|
302 assert_select "li#changeset_#{changeset.id}", :count => 1
308 # check the result of a feed
309 def check_feed_result(changesets)
310 assert changesets.size <= 20
312 assert_select "feed", :count => [changesets.size, 1].min do
313 assert_select "> title", :count => 1, :text => /^Changesets/
314 assert_select "> entry", :count => changesets.size
316 changesets.each do |changeset|
317 assert_select "> entry > id", changeset_url(:id => changeset.id)