2018-03-19 12:11:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-04-06 12:23:45 -04:00
|
|
|
describe DeployTokens::CreateService do
|
2018-03-19 12:11:12 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:deploy_token_params) { attributes_for(:deploy_token) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
2018-03-29 22:11:36 -04:00
|
|
|
subject { described_class.new(project, user, deploy_token_params).execute }
|
2018-03-19 12:11:12 -04:00
|
|
|
|
|
|
|
context 'when the deploy token is valid' do
|
|
|
|
it 'should create a new DeployToken' do
|
2018-03-29 22:11:36 -04:00
|
|
|
expect { subject }.to change { DeployToken.count }.by(1)
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
|
2018-04-05 13:22:34 -04:00
|
|
|
it 'should create a new ProjectDeployToken' do
|
|
|
|
expect { subject }.to change { ProjectDeployToken.count }.by(1)
|
2018-03-29 22:11:36 -04:00
|
|
|
end
|
2018-03-19 12:11:12 -04:00
|
|
|
|
2018-04-05 13:22:34 -04:00
|
|
|
it 'returns a DeployToken' do
|
|
|
|
expect(subject).to be_an_instance_of DeployToken
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 12:23:45 -04:00
|
|
|
context 'when expires at date is not passed' do
|
|
|
|
let(:deploy_token_params) { attributes_for(:deploy_token, expires_at: '') }
|
|
|
|
|
2018-04-06 15:48:17 -04:00
|
|
|
it 'should set Forever.date' do
|
|
|
|
expect(subject.read_attribute(:expires_at)).to eq(Forever.date)
|
2018-04-06 12:23:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-19 12:11:12 -04:00
|
|
|
context 'when the deploy token is invalid' do
|
2018-04-05 13:22:34 -04:00
|
|
|
let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false) }
|
2018-03-19 12:11:12 -04:00
|
|
|
|
2018-04-05 13:22:34 -04:00
|
|
|
it 'should not create a new DeployToken' do
|
2018-03-29 22:11:36 -04:00
|
|
|
expect { subject }.not_to change { DeployToken.count }
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
|
2018-04-05 13:22:34 -04:00
|
|
|
it 'should not create a new ProjectDeployToken' do
|
|
|
|
expect { subject }.not_to change { ProjectDeployToken.count }
|
|
|
|
end
|
2018-03-19 12:11:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|