Commit f8b1f66d782513549f1e2390b9e197dec822ef29
1 parent
895776ac
Exists in
master
and in
28 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 | 16 | elsif @filter == 'deactivated_users' |
| 17 | 17 | scope = scope.deactivated |
| 18 | 18 | end |
| 19 | + scope = scope.order('name ASC') | |
| 19 | 20 | @q = params[:q] |
| 20 | 21 | @collection = find_by_contents(:people, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results] |
| 21 | 22 | end | ... | ... |
test/functional/users_controller_test.rb
| ... | ... | @@ -107,6 +107,16 @@ class UsersControllerTest < ActionController::TestCase |
| 107 | 107 | assert_equal false, u.activated? |
| 108 | 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 | 120 | should 'response as XML to export users' do |
| 111 | 121 | get :download, :format => 'xml' |
| 112 | 122 | assert_equal 'text/xml', @response.content_type | ... | ... |
test/test_helper.rb
| ... | ... | @@ -177,6 +177,19 @@ class ActiveSupport::TestCase |
| 177 | 177 | assert !tag, "expected no tag #{options.inspect}, but tag found in #{text.inspect}" |
| 178 | 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 | 193 | # For models that render views (blocks, articles, ...) |
| 181 | 194 | def render(*args) |
| 182 | 195 | view_paths = @explicit_view_paths || ActionController::Base.view_paths | ... | ... |