diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-03-19 19:11:12 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 05:20:16 +0300 |
commit | db18993f652425b72c4b854e18a002e0ec44b196 (patch) | |
tree | 7466e5f6b154bd79e72c13a5021d92eb9d7e4a13 /spec/services/deploy_tokens | |
parent | aade8b3652573db40e7b777c72caa922b0bc12ef (diff) |
Create barebones for Deploytoken
Includes:
- Model, factories, create service and controller actions
- As usual, includes specs for everything
- Builds UI (copy from PAT)
- Add revoke action
Closes #31591
Diffstat (limited to 'spec/services/deploy_tokens')
-rw-r--r-- | spec/services/deploy_tokens/create_service_spec.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/services/deploy_tokens/create_service_spec.rb b/spec/services/deploy_tokens/create_service_spec.rb new file mode 100644 index 00000000000..84aa17971d6 --- /dev/null +++ b/spec/services/deploy_tokens/create_service_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:deploy_token_params) { attributes_for(:deploy_token) } + + describe '#execute' do + subject { described_class.new(project, user, deploy_token_params) } + + context 'when the deploy token is valid' do + it 'should create a new DeployToken' do + expect { subject.execute }.to change { DeployToken.count }.by(1) + end + + it 'should assign the DeployToken to the project' do + subject.execute + + expect(subject.project).to eq(project) + end + + it 'should store the token on redis' do + subject.execute + redis_key = DeployToken.redis_shared_state_key(user.id) + + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).not_to be_nil + end + end + + context 'when the deploy token is invalid' do + let(:deploy_token_params) { attributes_for(:deploy_token, scopes: []) } + + it 'it should not create a new DeployToken' do + expect { subject.execute }.not_to change { DeployToken.count } + end + + it 'should not store the token on redis' do + subject.execute + redis_key = DeployToken.redis_shared_state_key(user.id) + + expect(Gitlab::Redis::SharedState.with { |redis| redis.get(redis_key) }).to be_nil + end + end + end +end |