diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/services/ci/change_variable_service_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/services/ci/change_variable_service_spec.rb')
-rw-r--r-- | spec/services/ci/change_variable_service_spec.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/services/ci/change_variable_service_spec.rb b/spec/services/ci/change_variable_service_spec.rb new file mode 100644 index 00000000000..7acdd4e834f --- /dev/null +++ b/spec/services/ci/change_variable_service_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::ChangeVariableService do + let(:service) { described_class.new(container: group, current_user: user, params: params) } + + let_it_be(:user) { create(:user) } + let(:group) { create(:group) } + + describe '#execute' do + subject(:execute) { service.execute } + + context 'when creating a variable' do + let(:params) { { variable_params: { key: 'new_variable', value: 'variable_value' }, action: :create } } + + it 'persists a variable' do + expect { execute }.to change(Ci::GroupVariable, :count).from(0).to(1) + end + end + + context 'when updating a variable' do + let!(:variable) { create(:ci_group_variable, value: 'old_value') } + let(:params) { { variable_params: { key: variable.key, value: 'new_value' }, action: :update } } + + before do + group.variables << variable + end + + it 'updates a variable' do + expect { execute }.to change { variable.reload.value }.from('old_value').to('new_value') + end + + context 'when the variable does not exist' do + before do + variable.destroy! + end + + it 'raises a record not found error' do + expect { execute }.to raise_error(::ActiveRecord::RecordNotFound) + end + end + end + + context 'when destroying a variable' do + let!(:variable) { create(:ci_group_variable) } + let(:params) { { variable_params: { key: variable.key }, action: :destroy } } + + before do + group.variables << variable + end + + it 'destroys a variable' do + expect { execute }.to change { Ci::GroupVariable.exists?(variable.id) }.from(true).to(false) + end + + context 'when the variable does not exist' do + before do + variable.destroy! + end + + it 'raises a record not found error' do + expect { execute }.to raise_error(::ActiveRecord::RecordNotFound) + end + end + end + end +end |