From: Jean-Philippe Lang Date: Mon, 5 Mar 2012 12:45:51 +0000 (+0000) Subject: Merged r8863 from trunk. X-Git-Tag: 1.3.2~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=92dde0d75f3333dd1b2ae5ca297156a948fd5908;p=redmine.git Merged r8863 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@9112 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/member.rb b/app/models/member.rb index 0e15935c2..87d806333 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -50,7 +50,17 @@ class Member < ActiveRecord::Base def <=>(member) a, b = roles.sort.first, member.roles.sort.first - a == b ? (principal <=> member.principal) : (a <=> b) + if a == b + if principal + principal <=> member.principal + else + 1 + end + elsif a + a <=> b + else + 1 + end end def deletable? diff --git a/app/models/principal.rb b/app/models/principal.rb index 5acb1d45d..f79b9df7a 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -40,7 +40,9 @@ class Principal < ActiveRecord::Base end def <=>(principal) - if self.class.name == principal.class.name + if principal.nil? + -1 + elsif self.class.name == principal.class.name self.to_s.downcase <=> principal.to_s.downcase else # groups after users diff --git a/test/unit/member_test.rb b/test/unit/member_test.rb index 685ecfb20..ccc81b80c 100644 --- a/test/unit/member_test.rb +++ b/test/unit/member_test.rb @@ -82,6 +82,23 @@ class MemberTest < ActiveSupport::TestCase assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) } end + def test_sort_without_roles + a = Member.new(:roles => [Role.first]) + b = Member.new + + assert_equal -1, a <=> b + assert_equal 1, b <=> a + end + + def test_sort_without_principal + role = Role.first + a = Member.new(:roles => [role], :principal => User.first) + b = Member.new(:roles => [role]) + + assert_equal -1, a <=> b + assert_equal 1, b <=> a + end + context "removing permissions" do setup do Watcher.delete_all("user_id = 9")