diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-19 21:12:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-19 21:12:50 +0300 |
commit | 78f7d2e7266a80502f91d5c3aeb5689c72f156a2 (patch) | |
tree | bd7dca46bb745b27d30ff9e0fab2c5aa92b37c69 /spec/models/customer_relations/contact_spec.rb | |
parent | 03a3b1a4caac4c04e81ee592fdb3b9c47dbb9623 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/customer_relations/contact_spec.rb')
-rw-r--r-- | spec/models/customer_relations/contact_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/models/customer_relations/contact_spec.rb b/spec/models/customer_relations/contact_spec.rb index 3a2d4e2d0ca..7e26d324ac2 100644 --- a/spec/models/customer_relations/contact_spec.rb +++ b/spec/models/customer_relations/contact_spec.rb @@ -36,4 +36,27 @@ RSpec.describe CustomerRelations::Contact, type: :model do expect(contact.phone).to eq('123456') end end + + describe '#self.find_ids_by_emails' do + let_it_be(:group) { create(:group) } + let_it_be(:group_contacts) { create_list(:contact, 2, group: group) } + let_it_be(:other_contacts) { create_list(:contact, 2) } + + it 'returns ids of contacts from group' do + contact_ids = described_class.find_ids_by_emails(group.id, group_contacts.pluck(:email)) + + expect(contact_ids).to match_array(group_contacts.pluck(:id)) + end + + it 'does not return ids of contacts from other groups' do + contact_ids = described_class.find_ids_by_emails(group.id, other_contacts.pluck(:email)) + + expect(contact_ids).to be_empty + end + + it 'raises ArgumentError when called with too many emails' do + too_many_emails = described_class::MAX_PLUCK + 1 + expect { described_class.find_ids_by_emails(group.id, Array(0..too_many_emails)) }.to raise_error(ArgumentError) + end + end end |