diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-11 21:14:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-11 21:14:42 +0000 |
commit | 830c9943a95cbd755700d6624c64a158b2602cd0 (patch) | |
tree | 6b0c3710d66ba89732fbb672687233ef785e5133 /spec/models/customer_relations | |
parent | b330f7f0bfb2035b03e84e5fa751816b6ad9b841 (diff) | |
download | gitlab-ce-830c9943a95cbd755700d6624c64a158b2602cd0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/customer_relations')
-rw-r--r-- | spec/models/customer_relations/contact_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/models/customer_relations/contact_spec.rb b/spec/models/customer_relations/contact_spec.rb index 7e26d324ac2..860dcb1f4d7 100644 --- a/spec/models/customer_relations/contact_spec.rb +++ b/spec/models/customer_relations/contact_spec.rb @@ -26,6 +26,38 @@ RSpec.describe CustomerRelations::Contact, type: :model do it_behaves_like 'an object with RFC3696 compliant email-formatted attributes', :email 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 + 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) } + + it { is_expected.to be_invalid } + end + end + describe '#before_validation' do it 'strips leading and trailing whitespace' do contact = described_class.new(first_name: ' First ', last_name: ' Last ', phone: ' 123456 ') |