diff options
-rw-r--r-- | app/models/group.rb | 2 | ||||
-rw-r--r-- | test/unit/group_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index 279e145ed..8c683305e 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -32,7 +32,7 @@ class Group < Principal before_destroy :remove_references_before_destroy - scope :sorted, lambda { order(:type => :asc, :lastname => :desc) } + scope :sorted, lambda { order(:type => :asc, :lastname => :asc) } scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)} scope :givable, lambda {where(:type => 'Group')} diff --git a/test/unit/group_test.rb b/test/unit/group_test.rb index 703c423c1..9383cc7e7 100644 --- a/test/unit/group_test.rb +++ b/test/unit/group_test.rb @@ -158,4 +158,12 @@ class GroupTest < ActiveSupport::TestCase end assert_equal 0, group.reload.users.count end + + def test_sorted_scope_should_sort_groups_alphabetically + Group.delete_all + b = Group.generate!(:name => 'B') + a = Group.generate!(:name => 'A') + + assert_equal %w(A B), Group.sorted.to_a.map(&:name) + end end |