Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/validators
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/nested_attributes_duplicates_validator_spec.rb (renamed from spec/validators/variable_duplicates_validator_spec.rb)50
1 files changed, 47 insertions, 3 deletions
diff --git a/spec/validators/variable_duplicates_validator_spec.rb b/spec/validators/nested_attributes_duplicates_validator_spec.rb
index acc47ff225f..f59e422e5d4 100644
--- a/spec/validators/variable_duplicates_validator_spec.rb
+++ b/spec/validators/nested_attributes_duplicates_validator_spec.rb
@@ -2,13 +2,16 @@
require 'spec_helper'
-RSpec.describe VariableDuplicatesValidator do
- let(:validator) { described_class.new(attributes: [:variables], **options) }
+RSpec.describe NestedAttributesDuplicatesValidator do
+ let(:validator) { described_class.new(attributes: [attribute], **options) }
describe '#validate_each' do
let(:project) { build(:project) }
+ let(:record) { project }
+ let(:attribute) { :variables }
+ let(:value) { project.variables }
- subject { validator.validate_each(project, :variables, project.variables) }
+ subject { validator.validate_each(record, attribute, value) }
context 'with no scope' do
let(:options) { {} }
@@ -65,5 +68,46 @@ RSpec.describe VariableDuplicatesValidator do
end
end
end
+
+ context 'with a child attribute' do
+ let(:release) { build(:release) }
+ let(:first_link) { build(:release_link, name: 'test1', url: 'https://www.google1.com', release: release) }
+ let(:second_link) { build(:release_link, name: 'test2', url: 'https://www.google2.com', release: release) }
+ let(:record) { release }
+ let(:attribute) { :links }
+ let(:value) { release.links }
+ let(:options) { { scope: :release, child_attributes: %i[name url] } }
+
+ before do
+ release.links << first_link
+ release.links << second_link
+ end
+
+ it 'does not have any errors' do
+ subject
+
+ expect(release.errors.empty?).to be true
+ end
+
+ context 'when name is duplicated' do
+ let(:second_link) { build(:release_link, name: 'test1', release: release) }
+
+ it 'has a duplicate error' do
+ subject
+
+ expect(release.errors).to have_key(attribute)
+ end
+ end
+
+ context 'when url is duplicated' do
+ let(:second_link) { build(:release_link, url: 'https://www.google1.com', release: release) }
+
+ it 'has a duplicate error' do
+ subject
+
+ expect(release.errors).to have_key(attribute)
+ end
+ end
+ end
end
end