diff options
author | Go MAEDA <maeda@farend.jp> | 2024-02-08 00:57:07 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-02-08 00:57:07 +0000 |
commit | b61ee85e4d15c7b2d3f90143731ab9f0e2acf4b7 (patch) | |
tree | 8d84d7cad8b5a9381240fe501ab9065b4c7e70a6 | |
parent | 34f1c52e231c0f9b2ae96099d6f370a6a2187e63 (diff) | |
download | redmine-b61ee85e4d15c7b2d3f90143731ab9f0e2acf4b7.tar.gz redmine-b61ee85e4d15c7b2d3f90143731ab9f0e2acf4b7.zip |
Principal.not_member_of scope does not accept ActiveRecord::Relation (#28243).
git-svn-id: https://svn.redmine.org/redmine/trunk@22697 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/principal.rb | 4 | ||||
-rw-r--r-- | test/unit/principal_test.rb | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb index 1ef191796..fe5ef35d2 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -103,8 +103,8 @@ class Principal < ApplicationRecord end) # Principals that are not members of projects scope :not_member_of, (lambda do |projects| - projects = [projects] unless projects.is_a?(Array) - if projects.empty? + projects = [projects] if projects.is_a?(Project) + if projects.blank? where("1=0") else ids = projects.map(&:id) diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb index f36ace7be..8e8a4bdc1 100644 --- a/test/unit/principal_test.rb +++ b/test/unit/principal_test.rb @@ -76,6 +76,12 @@ class PrincipalTest < ActiveSupport::TestCase end end + def test_not_member_of_scope_should_accept_active_record_relation + projects = Project.where(id: [1, 2]) + expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort + assert_equal expected, Principal.not_member_of(projects).sort + end + def test_not_member_of_scope_should_be_empty_for_no_projects assert_equal [], Principal.not_member_of([]).sort end |