diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-14 15:07:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-14 15:07:59 +0300 |
commit | fd27e4f95b3ea8668e1e67f5a88dfb061909c893 (patch) | |
tree | 439bcc5417be41cd2290485292fe512f6cea8110 /spec/models/customer_relations/contact_spec.rb | |
parent | 6aa920eeb4ef61ea7e7c77b5e10595507874b927 (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 | 55 |
1 files changed, 11 insertions, 44 deletions
diff --git a/spec/models/customer_relations/contact_spec.rb b/spec/models/customer_relations/contact_spec.rb index c7b0f1bd3d4..18896962261 100644 --- a/spec/models/customer_relations/contact_spec.rb +++ b/spec/models/customer_relations/contact_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe CustomerRelations::Contact, type: :model do + let_it_be(:group) { create(:group) } + describe 'associations' do it { is_expected.to belong_to(:group) } it { is_expected.to belong_to(:organization).optional } @@ -23,6 +25,8 @@ RSpec.describe CustomerRelations::Contact, type: :model do it { is_expected.to validate_length_of(:email).is_at_most(255) } it { is_expected.to validate_length_of(:description).is_at_most(1024) } + it { is_expected.to validate_uniqueness_of(:email).scoped_to(:group_id) } + it_behaves_like 'an object with RFC3696 compliant email-formatted attributes', :email end @@ -38,33 +42,15 @@ RSpec.describe CustomerRelations::Contact, type: :model do it { expect(described_class.reference_postfix).to eq(']') } end - describe '#unique_email_for_group_hierarchy' do - let_it_be(:parent) { create(:group) } - let_it_be(:group) { create(:group, parent: parent) } - let_it_be(:subgroup) { create(:group, parent: group) } - - let_it_be(:existing_contact) { create(:contact, group: group) } - - context 'with unique email for group hierarchy' do + describe '#root_group' do + context 'when root group' do subject { build(:contact, group: group) } it { is_expected.to be_valid } end - context 'with duplicate email in group' do - subject { build(:contact, email: existing_contact.email, group: group) } - - it { is_expected.to be_invalid } - end - - context 'with duplicate email in parent group' do - subject { build(:contact, email: existing_contact.email, group: subgroup) } - - it { is_expected.to be_invalid } - end - - context 'with duplicate email in subgroup' do - subject { build(:contact, email: existing_contact.email, group: parent) } + context 'when subgroup' do + subject { build(:contact, group: create(:group, parent: group)) } it { is_expected.to be_invalid } end @@ -82,7 +68,6 @@ RSpec.describe CustomerRelations::Contact, type: :model do 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) } @@ -92,13 +77,6 @@ RSpec.describe CustomerRelations::Contact, type: :model do expect(contact_ids).to match_array(group_contacts.pluck(:id)) end - it 'returns ids of contacts from parent group' do - subgroup = create(:group, parent: group) - contact_ids = described_class.find_ids_by_emails(subgroup, 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, other_contacts.pluck(:email)) @@ -112,28 +90,17 @@ RSpec.describe CustomerRelations::Contact, type: :model do end describe '#self.exists_for_group?' do - let(:group) { create(:group) } - let(:subgroup) { create(:group, parent: group) } - - context 'with no contacts in group or parent' do + context 'with no contacts in group' do it 'returns false' do - expect(described_class.exists_for_group?(subgroup)).to be_falsey + expect(described_class.exists_for_group?(group)).to be_falsey end end context 'with contacts in group' do it 'returns true' do - create(:contact, group: subgroup) - - expect(described_class.exists_for_group?(subgroup)).to be_truthy - end - end - - context 'with contacts in parent' do - it 'returns true' do create(:contact, group: group) - expect(described_class.exists_for_group?(subgroup)).to be_truthy + expect(described_class.exists_for_group?(group)).to be_truthy end end end |