Simplifies Principal.active scope (status defaults to 1 for groups).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8746 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-02-01 19:35:49 +00:00
parent 5dd08133ef
commit 0154d7477b
2 changed files with 9 additions and 1 deletions

View File

@ -24,7 +24,7 @@ class Principal < ActiveRecord::Base
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
# Groups and active users
named_scope :active, :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status = 1)"
named_scope :active, :conditions => "#{Principal.table_name}.status = 1"
named_scope :like, lambda {|q|
s = "%#{q.to_s.strip.downcase}%"

View File

@ -19,6 +19,14 @@ require File.expand_path('../../test_helper', __FILE__)
class PrincipalTest < ActiveSupport::TestCase
def test_active_scope_should_return_groups_and_active_users
result = Principal.active.all
assert_include Group.first, result
assert_not_nil result.detect {|p| p.is_a?(User)}
assert_nil result.detect {|p| p.is_a?(User) && !p.active?}
assert_nil result.detect {|p| p.is_a?(AnonymousUser)}
end
context "#like" do
setup do
Principal.generate!(:login => 'login')