mirror of
https://github.com/redmine/redmine.git
synced 2025-11-15 17:56:03 +01:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user