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?
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
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")