Commit 32d449d1 authored by Mark Chao's avatar Mark Chao

Ensure group_users to return distinct users

Caused uniqueness constraint when inserting as users
parent aaf1e00b
......@@ -8,7 +8,7 @@ module ApprovalRuleLike
included do
has_and_belongs_to_many :users
has_and_belongs_to_many :groups, class_name: 'Group', join_table: "#{self.table_name}_groups"
has_many :group_users, through: :groups, source: :users
has_many :group_users, -> { distinct }, through: :groups, source: :users
validates :name, presence: true
end
......
......@@ -87,4 +87,16 @@ describe ApprovalRuleLike do
it_behaves_like 'approval rule like'
end
context '.group_users' do
subject { create(:approval_project_rule) }
it 'returns distinct users' do
group1.add_guest(user1)
group2.add_guest(user1)
subject.groups = [group1, group2]
expect(subject.group_users).to eq([user1])
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment