3 class ChangesetsControllerTest < ActionController::TestCase
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 get :index, :params => { :format => "html" }
37 assert_response :success
38 assert_template "history"
39 assert_template :layout => "map"
40 assert_select "h2", :text => "Changesets", :count => 1
42 get :index, :params => { :format => "html", :list => "1" }, :xhr => true
43 assert_response :success
44 assert_template "index"
46 check_index_result(Changeset.all)
50 # This should display the last 20 changesets closed
52 get :index, :params => { :format => "html" }, :xhr => true
53 assert_response :success
54 assert_template "history"
55 assert_template :layout => "xhr"
56 assert_select "h2", :text => "Changesets", :count => 1
58 get :index, :params => { :format => "html", :list => "1" }, :xhr => true
59 assert_response :success
60 assert_template "index"
62 check_index_result(Changeset.all)
66 # This should display the last 20 changesets closed in a specific area
68 get :index, :params => { :format => "html", :bbox => "4.5,4.5,5.5,5.5" }
69 assert_response :success
70 assert_template "history"
71 assert_template :layout => "map"
72 assert_select "h2", :text => "Changesets", :count => 1
74 get :index, :params => { :format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1" }, :xhr => true
75 assert_response :success
76 assert_template "index"
78 check_index_result(Changeset.where("min_lon < 55000000 and max_lon > 45000000 and min_lat < 55000000 and max_lat > 45000000"))
82 # Checks the display of the user changesets listing
85 create(:changeset, :user => user)
86 create(:changeset, :closed, :user => user)
88 get :index, :params => { :format => "html", :display_name => user.display_name }
89 assert_response :success
90 assert_template "history"
92 get :index, :params => { :format => "html", :display_name => user.display_name, :list => "1" }, :xhr => true
93 assert_response :success
94 assert_template "index"
96 check_index_result(user.changesets)
100 # Checks the display of the user changesets listing for a private user
101 def test_index_private_user
102 private_user = create(:user, :data_public => false)
103 create(:changeset, :user => private_user)
104 create(:changeset, :closed, :user => private_user)
106 get :index, :params => { :format => "html", :display_name => private_user.display_name }
107 assert_response :success
108 assert_template "history"
110 get :index, :params => { :format => "html", :display_name => private_user.display_name, :list => "1" }, :xhr => true
111 assert_response :success
112 assert_template "index"
114 check_index_result(Changeset.none)
118 # Check the not found of the index user changesets
119 def test_index_user_not_found
120 get :index, :params => { :format => "html", :display_name => "Some random user" }
121 assert_response :not_found
122 assert_template "users/no_such_user"
124 get :index, :params => { :format => "html", :display_name => "Some random user", :list => "1" }, :xhr => true
125 assert_response :not_found
126 assert_template "users/no_such_user"
130 # Checks the display of the friends changesets listing
131 def test_index_friends
132 private_user = create(:user, :data_public => true)
133 friendship = create(:friendship, :befriender => private_user)
134 create(:changeset, :user => friendship.befriendee)
136 get :index, :params => { :friends => true }
137 assert_response :redirect
138 assert_redirected_to :controller => :users, :action => :login, :referer => friend_changesets_path
140 session[:user] = private_user.id
142 get :index, :params => { :friends => true }
143 assert_response :success
144 assert_template "history"
146 get :index, :params => { :friends => true, :list => "1" }, :xhr => true
147 assert_response :success
148 assert_template "index"
150 check_index_result(Changeset.where(:user => private_user.friends.identifiable))
154 # Checks the display of the nearby user changesets listing
155 def test_index_nearby
156 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
157 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
158 create(:changeset, :user => user)
160 get :index, :params => { :nearby => true }
161 assert_response :redirect
162 assert_redirected_to :controller => :users, :action => :login, :referer => nearby_changesets_path
164 session[:user] = private_user.id
166 get :index, :params => { :nearby => true }
167 assert_response :success
168 assert_template "history"
170 get :index, :params => { :nearby => true, :list => "1" }, :xhr => true
171 assert_response :success
172 assert_template "index"
174 check_index_result(Changeset.where(:user => user.nearby))
178 # Check that we can't request later pages of the changesets index
179 def test_index_max_id
180 get :index, :params => { :format => "html", :max_id => 4 }, :xhr => true
181 assert_response :success
182 assert_template "history"
183 assert_template :layout => "xhr"
184 assert_select "h2", :text => "Changesets", :count => 1
186 get :index, :params => { :format => "html", :list => "1", :max_id => 4 }, :xhr => true
187 assert_response :success
188 assert_template "index"
190 check_index_result(Changeset.where("id <= 4"))
194 # Check that a list with a next page link works
196 create_list(:changeset, 50)
198 get :index, :params => { :format => "html" }
199 assert_response :success
201 get :index, :params => { :format => "html" }, :xhr => true
202 assert_response :success
206 # This should display the last 20 non-empty changesets
208 changeset = create(:changeset, :num_changes => 1)
209 create(:changeset_tag, :changeset => changeset)
210 create(:changeset_tag, :changeset => changeset, :k => "website", :v => "http://example.com/")
211 closed_changeset = create(:changeset, :closed, :num_changes => 1)
212 _empty_changeset = create(:changeset, :num_changes => 0)
214 get :feed, :params => { :format => :atom }
215 assert_response :success
216 assert_template "index"
217 assert_equal "application/atom+xml", response.content_type
219 check_feed_result([changeset, closed_changeset])
223 # This should display the last 20 changesets closed in a specific area
225 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)
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, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
229 _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)
230 _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)
232 get :feed, :params => { :format => :atom, :bbox => "4.5,4.5,5.5,5.5" }
233 assert_response :success
234 assert_template "index"
235 assert_equal "application/atom+xml", response.content_type
237 check_feed_result([changeset, closed_changeset])
241 # Checks the display of the user changesets feed
244 changesets = create_list(:changeset, 3, :user => user, :num_changes => 4)
245 create(:changeset_tag, :changeset => changesets[1])
246 create(:changeset_tag, :changeset => changesets[1], :k => "website", :v => "http://example.com/")
247 _other_changeset = create(:changeset)
249 get :feed, :params => { :format => :atom, :display_name => user.display_name }
251 assert_response :success
252 assert_template "index"
253 assert_equal "application/atom+xml", response.content_type
255 check_feed_result(changesets)
259 # Check the not found of the user changesets feed
260 def test_feed_user_not_found
261 get :feed, :params => { :format => "atom", :display_name => "Some random user" }
262 assert_response :not_found
266 # Check that we can't request later pages of the changesets feed
268 get :feed, :params => { :format => "atom", :max_id => 100 }
269 assert_response :redirect
270 assert_redirected_to :action => :feed
276 # check the result of a index
277 def check_index_result(changesets)
278 changesets = changesets.where("num_changes > 0")
279 .order(:created_at => :desc)
281 assert changesets.size <= 20
283 assert_select "ol.changesets", :count => [changesets.size, 1].min do
284 assert_select "li", :count => changesets.size
286 changesets.each do |changeset|
287 assert_select "li#changeset_#{changeset.id}", :count => 1
293 # check the result of a feed
294 def check_feed_result(changesets)
295 assert changesets.size <= 20
297 assert_select "feed", :count => [changesets.size, 1].min do
298 assert_select "> title", :count => 1, :text => /^Changesets/
299 assert_select "> entry", :count => changesets.size
301 changesets.each do |changeset|
302 assert_select "> entry > id", changeset_url(:id => changeset.id)