diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 12:08:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-02 12:08:18 +0000 |
commit | 684d65316ac77c62f47d68b9926eea8af30db227 (patch) | |
tree | d1f4c4eec399d7772ab4ad6294f98e7505c1cee5 /spec/support | |
parent | ade18c9d68d5a2e6c6e28ef7e9d3add3b3491ace (diff) | |
download | gitlab-ce-684d65316ac77c62f47d68b9926eea8af30db227.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/api_validators_helpers.rb | 23 | ||||
-rw-r--r-- | spec/support/services/deploy_token_shared_examples.rb | 22 |
2 files changed, 45 insertions, 0 deletions
diff --git a/spec/support/helpers/api_validators_helpers.rb b/spec/support/helpers/api_validators_helpers.rb new file mode 100644 index 00000000000..dc05e5afd57 --- /dev/null +++ b/spec/support/helpers/api_validators_helpers.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module ApiValidatorsHelpers + def scope + Struct.new(:opts) do + def full_name(attr_name) + attr_name + end + end + end + + def expect_no_validation_error(params) + expect { validate_test_param!(params) }.not_to raise_error + end + + def expect_validation_error(params) + expect { validate_test_param!(params) }.to raise_error(Grape::Exceptions::Validation) + end + + def validate_test_param!(params) + subject.validate_param!('test', params) + end +end diff --git a/spec/support/services/deploy_token_shared_examples.rb b/spec/support/services/deploy_token_shared_examples.rb index 70efd1fcd0c..9d681970739 100644 --- a/spec/support/services/deploy_token_shared_examples.rb +++ b/spec/support/services/deploy_token_shared_examples.rb @@ -58,3 +58,25 @@ RSpec.shared_examples 'a deploy token creation service' do end end end + +RSpec.shared_examples 'a deploy token deletion service' do + let(:user) { create(:user) } + let(:deploy_token_params) { { token_id: deploy_token.id } } + + describe '#execute' do + subject { described_class.new(entity, user, deploy_token_params).execute } + + it "destroys a token record and it's associated DeployToken" do + expect { subject }.to change { deploy_token_class.count }.by(-1) + .and change { DeployToken.count }.by(-1) + end + + context 'invalid token id' do + let(:deploy_token_params) { { token_id: 9999 } } + + it 'raises an error' do + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end +end |