]> source.dussan.org Git - redmine.git/commitdiff
Simplifies Principal.active scope (status defaults to 1 for groups).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 1 Feb 2012 19:35:49 +0000 (19:35 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 1 Feb 2012 19:35:49 +0000 (19:35 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8746 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/principal.rb
test/unit/principal_test.rb

index 5acb1d45d529ebf0638785a6ac1edd04429ff28e..d7814f59501021d5dc4dce1c9377d817d81ef565 100644 (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}%"
index 5fd10d8ed1adf33d9af17d5f6222096c9a2d11ee..a3230f1c60883c51c22e096f61d032a72d56f3b1 100644 (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')