debian-mirror-gitlab/spec/serializers/deployment_entity_spec.rb

74 lines
2.5 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe DeploymentEntity do
2019-03-02 22:35:43 +05:30
let(:user) { developer }
let(:developer) { create(:user) }
let(:reporter) { create(:user) }
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:request) { double('request') }
2019-03-02 22:35:43 +05:30
let(:deployment) { create(:deployment, deployable: build, project: project) }
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
2017-08-17 22:00:37 +05:30
let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json }
before do
2019-03-02 22:35:43 +05:30
project.add_developer(developer)
project.add_reporter(reporter)
2017-08-17 22:00:37 +05:30
allow(request).to receive(:current_user).and_return(user)
2019-03-02 22:35:43 +05:30
allow(request).to receive(:project).and_return(project)
2017-08-17 22:00:37 +05:30
end
2019-03-02 22:35:43 +05:30
it 'exposes internal deployment id' do
2017-08-17 22:00:37 +05:30
expect(subject).to include(:iid)
end
it 'exposes nested information about branch' do
expect(subject[:ref][:name]).to eq 'master'
end
it 'exposes creation date' do
expect(subject).to include(:created_at)
end
2018-12-13 13:39:08 +05:30
2019-03-02 22:35:43 +05:30
context 'when the pipeline has another manual action' do
let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) }
let!(:other_deployment) { create(:deployment, deployable: other_build) }
it 'returns another manual action' do
expect(subject[:manual_actions].count).to eq(1)
expect(subject[:manual_actions].first[:name]).to eq('another deploy')
end
context 'when user is a reporter' do
let(:user) { reporter }
it 'returns another manual action' do
expect(subject[:manual_actions]).not_to be_present
end
end
end
2018-12-13 13:39:08 +05:30
describe 'scheduled_actions' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let(:deployment) { create(:deployment, deployable: build) }
context 'when the same pipeline has a scheduled action' do
let(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other build') }
let!(:other_deployment) { create(:deployment, deployable: other_build) }
it 'returns other scheduled actions' do
expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
end
end
context 'when the same pipeline does not have a scheduled action' do
it 'does not return other actions' do
expect(subject[:scheduled_actions]).to be_empty
end
end
end
2017-08-17 22:00:37 +05:30
end