Fix and add spec

This commit is contained in:
Shinya Maeda 2018-10-10 10:47:31 +09:00
parent 4f49f54af5
commit 1f3f06668b
3 changed files with 67 additions and 2 deletions

View file

@ -1523,11 +1523,11 @@ describe Ci::Build do
end end
end end
describe '#other_actions' do describe '#other_manual_actions' do
let(:build) { create(:ci_build, :manual, pipeline: pipeline) } let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
let!(:other_build) { create(:ci_build, :manual, pipeline: pipeline, name: 'other action') } let!(:other_build) { create(:ci_build, :manual, pipeline: pipeline, name: 'other action') }
subject { build.other_actions } subject { build.other_manual_actions }
before do before do
project.add_developer(user) project.add_developer(user)
@ -1558,6 +1558,48 @@ describe Ci::Build do
end end
end end
describe '#other_scheduled_actions' do
let(:build) { create(:ci_build, :scheduled, pipeline: pipeline) }
subject { build.other_scheduled_actions }
before do
project.add_developer(user)
end
context "when other build's status is success" do
let!(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other action') }
it 'returns other actions' do
is_expected.to contain_exactly(other_build)
end
end
context "when other build's status is failed" do
let!(:other_build) { create(:ci_build, :schedulable, :failed, pipeline: pipeline, name: 'other action') }
it 'returns other actions' do
is_expected.to contain_exactly(other_build)
end
end
context "when other build's status is running" do
let!(:other_build) { create(:ci_build, :schedulable, :running, pipeline: pipeline, name: 'other action') }
it 'does not return other actions' do
is_expected.to be_empty
end
end
context "when other build's status is scheduled" do
let!(:other_build) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'other action') }
it 'does not return other actions' do
is_expected.to contain_exactly(other_build)
end
end
end
describe '#persisted_environment' do describe '#persisted_environment' do
let!(:environment) do let!(:environment) do
create(:environment, project: project, name: "foo-#{project.default_branch}") create(:environment, project: project, name: "foo-#{project.default_branch}")

View file

@ -12,6 +12,7 @@ describe Deployment do
it { is_expected.to delegate_method(:commit).to(:project) } it { is_expected.to delegate_method(:commit).to(:project) }
it { is_expected.to delegate_method(:commit_title).to(:commit).as(:try) } it { is_expected.to delegate_method(:commit_title).to(:commit).as(:try) }
it { is_expected.to delegate_method(:manual_actions).to(:deployable).as(:try) } it { is_expected.to delegate_method(:manual_actions).to(:deployable).as(:try) }
it { is_expected.to delegate_method(:scheduled_actions).to(:deployable).as(:try) }
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }

View file

@ -22,4 +22,26 @@ describe DeploymentEntity do
it 'exposes creation date' do it 'exposes creation date' do
expect(subject).to include(:created_at) expect(subject).to include(:created_at)
end end
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 deployment has another action' do
let(:other_build) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'other build') }
let!(:other_deployment) { create(:deployment, deployable: other_build) }
it 'returns other actions' do
expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
end
end
context 'when deployment does not have other actions' do
it 'does not return other actions' do
expect(subject[:scheduled_actions]).to be_empty
end
end
end
end end