diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-21 21:10:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-21 21:10:17 +0000 |
commit | 6b1cf9e9ce2308c3867a241cbbcade8099540604 (patch) | |
tree | 69bdf96873da208dd83b95f209257069b73b7b7d /spec | |
parent | 5d41ea8c8e83ff6054ba4303ec8dc9bc33556602 (diff) | |
download | gitlab-ce-6b1cf9e9ce2308c3867a241cbbcade8099540604.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/graphql/deprecation_spec.rb | 53 | ||||
-rw-r--r-- | spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb | 17 |
2 files changed, 57 insertions, 13 deletions
diff --git a/spec/lib/gitlab/graphql/deprecation_spec.rb b/spec/lib/gitlab/graphql/deprecation_spec.rb index 2931e28a6ee..0ff4c232c6f 100644 --- a/spec/lib/gitlab/graphql/deprecation_spec.rb +++ b/spec/lib/gitlab/graphql/deprecation_spec.rb @@ -6,30 +6,57 @@ require 'active_model' RSpec.describe ::Gitlab::Graphql::Deprecation do let(:options) { {} } - subject(:deprecation) { described_class.parse(options) } + subject(:deprecation) { described_class.new(**options) } describe '.parse' do - context 'with nil' do - let(:options) { nil } + subject(:parsed_deprecation) { described_class.parse(**options) } - it 'parses to nil' do - expect(deprecation).to be_nil + context 'with no arguments' do + it 'returns nil' do + expect(parsed_deprecation).to be_nil end end - context 'with empty options' do - let(:options) { {} } + context 'with an incomplete `deprecated` argument' do + let(:options) { { deprecated: {} } } - it 'parses to an empty deprecation' do - expect(deprecation).to eq(described_class.new) + it 'parses as an invalid deprecation' do + expect(parsed_deprecation).not_to be_valid + expect(parsed_deprecation).to eq(described_class.new) end end - context 'with defined options' do - let(:options) { { reason: :renamed, milestone: '10.10' } } + context 'with a `deprecated` argument' do + let(:options) { { deprecated: { reason: :renamed, milestone: '10.10' } } } + + it 'parses as a deprecation' do + expect(parsed_deprecation).to be_valid + expect(parsed_deprecation).to eq( + described_class.new(reason: 'This was renamed', milestone: '10.10') + ) + end + end + + context 'with an `alpha` argument' do + let(:options) { { alpha: { milestone: '10.10' } } } + + it 'parses as an alpha' do + expect(parsed_deprecation).to be_valid + expect(parsed_deprecation).to eq( + described_class.new(reason: :alpha, milestone: '10.10') + ) + end + end + + context 'with both `deprecated` and `alpha` arguments' do + let(:options) do + { alpha: { milestone: '10.10' }, deprecated: { reason: :renamed, milestone: '10.10' } } + end - it 'assigns the properties' do - expect(deprecation).to eq(described_class.new(reason: 'This was renamed', milestone: '10.10')) + it 'raises an error' do + expect { parsed_deprecation }.to raise_error(ArgumentError, + '`alpha` and `deprecated` arguments cannot be passed at the same time' + ) end end end diff --git a/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb b/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb index 7fd54408b11..2d7da9f9f00 100644 --- a/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb +++ b/spec/support/shared_examples/graphql/types/gitlab_style_deprecations_shared_examples.rb @@ -69,4 +69,21 @@ RSpec.shared_examples 'Gitlab-style deprecations' do 'This feature is in Alpha. It can be changed or removed at any time. Introduced in 1.10.' ) end + + it 'supports :alpha' do + deprecable = subject(alpha: { milestone: '1.10' }) + + expect(deprecable.deprecation_reason).to eq( + 'This feature is in Alpha. It can be changed or removed at any time. Introduced in 1.10.' + ) + end + + it 'does not allow :alpha and :deprecated together' do + expect do + subject(alpha: { milestone: '1.10' }, deprecated: { milestone: '1.10', reason: 'my reason' } ) + end.to raise_error( + ArgumentError, + eq("`alpha` and `deprecated` arguments cannot be passed at the same time") + ) + end end |