Project

General

Profile

Defect #28243 » 28243.patch

Go MAEDA, 2024-02-05 13:43

View differences:

app/models/principal.rb
103 103
  end)
104 104
  # Principals that are not members of projects
105 105
  scope :not_member_of, (lambda do |projects|
106
    projects = [projects] unless projects.is_a?(Array)
107
    if projects.empty?
106
    projects = [projects] if projects.is_a?(Project)
107
    if projects.blank?
108 108
      where("1=0")
109 109
    else
110 110
      ids = projects.map(&:id)
test/unit/principal_test.rb
76 76
    end
77 77
  end
78 78

  
79
  def test_not_member_of_scope_should_accept_active_record_relation
80
    projects = Project.where(id: [1, 2])
81
    expected = (Principal.all - projects.map(&:memberships).flatten.map(&:principal)).sort
82
    assert_equal expected, Principal.not_member_of(projects).sort
83
  end
84

  
79 85
  def test_not_member_of_scope_should_be_empty_for_no_projects
80 86
    assert_equal [], Principal.not_member_of([]).sort
81 87
  end
(2-2/2)