Commit f8b1f66d782513549f1e2390b9e197dec822ef29
1 parent
895776ac
Exists in
master
and in
29 other branches
users-controller: order users by name
Also adding a new assert helper to test the order of a collection without assuming all elements inside it. (ActionItem2996)
Showing
3 changed files
with
24 additions
and
0 deletions
Show diff stats
app/controllers/admin/users_controller.rb
@@ -16,6 +16,7 @@ class UsersController < AdminController | @@ -16,6 +16,7 @@ class UsersController < AdminController | ||
16 | elsif @filter == 'deactivated_users' | 16 | elsif @filter == 'deactivated_users' |
17 | scope = scope.deactivated | 17 | scope = scope.deactivated |
18 | end | 18 | end |
19 | + scope = scope.order('name ASC') | ||
19 | @q = params[:q] | 20 | @q = params[:q] |
20 | @collection = find_by_contents(:people, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results] | 21 | @collection = find_by_contents(:people, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results] |
21 | end | 22 | end |
test/functional/users_controller_test.rb
@@ -107,6 +107,16 @@ class UsersControllerTest < ActionController::TestCase | @@ -107,6 +107,16 @@ class UsersControllerTest < ActionController::TestCase | ||
107 | assert_equal false, u.activated? | 107 | assert_equal false, u.activated? |
108 | end | 108 | end |
109 | 109 | ||
110 | + should 'order users by name' do | ||
111 | + create_user('jeremy') | ||
112 | + create_user('bill') | ||
113 | + create_user('ana') | ||
114 | + create_user('creed') | ||
115 | + get :index | ||
116 | + | ||
117 | + assert_order ['ana', 'bill', 'creed', 'jeremy'], assigns(:collection).map(&:name) | ||
118 | + end | ||
119 | + | ||
110 | should 'response as XML to export users' do | 120 | should 'response as XML to export users' do |
111 | get :download, :format => 'xml' | 121 | get :download, :format => 'xml' |
112 | assert_equal 'text/xml', @response.content_type | 122 | assert_equal 'text/xml', @response.content_type |
test/test_helper.rb
@@ -177,6 +177,19 @@ class ActiveSupport::TestCase | @@ -177,6 +177,19 @@ class ActiveSupport::TestCase | ||
177 | assert !tag, "expected no tag #{options.inspect}, but tag found in #{text.inspect}" | 177 | assert !tag, "expected no tag #{options.inspect}, but tag found in #{text.inspect}" |
178 | end | 178 | end |
179 | 179 | ||
180 | + def assert_order(reference, original) | ||
181 | + original.each do |value| | ||
182 | + if reference.include?(value) | ||
183 | + if reference.first == value | ||
184 | + reference.shift | ||
185 | + else | ||
186 | + assert false, "'#{value}' was found before it should be on: #{original.inspect}" | ||
187 | + end | ||
188 | + end | ||
189 | + end | ||
190 | + assert reference.blank?, "The following elements are not in the collection: #{reference.inspect}" | ||
191 | + end | ||
192 | + | ||
180 | # For models that render views (blocks, articles, ...) | 193 | # For models that render views (blocks, articles, ...) |
181 | def render(*args) | 194 | def render(*args) |
182 | view_paths = @explicit_view_paths || ActionController::Base.view_paths | 195 | view_paths = @explicit_view_paths || ActionController::Base.view_paths |