]> source.dussan.org Git - redmine.git/commitdiff
Merged r8863 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Mar 2012 12:45:51 +0000 (12:45 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 5 Mar 2012 12:45:51 +0000 (12:45 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@9112 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/member.rb
app/models/principal.rb
test/unit/member_test.rb

index 0e15935c28345dddd01974b8a484b0e2d4271d5c..87d806333bdb087e98ccb201356d822949002d55 100644 (file)
@@ -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?
index 5acb1d45d529ebf0638785a6ac1edd04429ff28e..f79b9df7aeab0229871c2008f54cf005fd6c4ba8 100644 (file)
@@ -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
index 685ecfb201ccfb636d3fd8d0bc1ecad3199ef606..ccc81b80c9108fd939988f05f752c2a9faab33d4 100644 (file)
@@ -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")