debian-mirror-gitlab/spec/services/deploy_tokens/create_service_spec.rb

64 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
require 'spec_helper'
describe DeployTokens::CreateService 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).execute }
context 'when the deploy token is valid' do
2019-07-07 11:18:12 +05:30
it 'creates a new DeployToken' do
2018-05-09 12:01:36 +05:30
expect { subject }.to change { DeployToken.count }.by(1)
end
2019-07-07 11:18:12 +05:30
it 'creates a new ProjectDeployToken' do
2018-05-09 12:01:36 +05:30
expect { subject }.to change { ProjectDeployToken.count }.by(1)
end
it 'returns a DeployToken' do
expect(subject).to be_an_instance_of DeployToken
end
end
context 'when expires at date is not passed' do
let(:deploy_token_params) { attributes_for(:deploy_token, expires_at: '') }
2019-07-07 11:18:12 +05:30
it 'sets Forever.date' do
2018-05-09 12:01:36 +05:30
expect(subject.read_attribute(:expires_at)).to eq(Forever.date)
end
end
2019-09-30 21:07:59 +05:30
context 'when username is empty string' do
let(:deploy_token_params) { attributes_for(:deploy_token, username: '') }
it 'converts it to nil' do
expect(subject.read_attribute(:username)).to be_nil
end
end
context 'when username is provided' do
let(:deploy_token_params) { attributes_for(:deploy_token, username: 'deployer') }
it 'keeps the provided username' do
expect(subject.read_attribute(:username)).to eq('deployer')
end
end
2018-05-09 12:01:36 +05:30
context 'when the deploy token is invalid' do
let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false) }
2019-07-07 11:18:12 +05:30
it 'does not create a new DeployToken' do
2018-05-09 12:01:36 +05:30
expect { subject }.not_to change { DeployToken.count }
end
2019-07-07 11:18:12 +05:30
it 'does not create a new ProjectDeployToken' do
2018-05-09 12:01:36 +05:30
expect { subject }.not_to change { ProjectDeployToken.count }
end
end
end
end