Commit 43906336 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix tests and add has_environment?

parent d6e00f53
......@@ -131,12 +131,16 @@ module Ci
ExpandVariables.expand(environment, variables) if environment
end
def has_environment?
self.environment.present?
end
def starts_environment?
self.environment.present? && self.environment_action == 'start'
has_environment? && self.environment_action == 'start'
end
def stops_environment?
self.environment.present? && self.environment_action == 'stop'
has_environment? && self.environment_action == 'stop'
end
def environment_action
......@@ -148,7 +152,7 @@ module Ci
end
def last_deployment
deployments.order(id: :desc).last
deployments.last
end
def depends_on_builds
......
......@@ -26,7 +26,7 @@
= link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
Runners page
- if @build.environment.present? && @build.starts_environment?
- if @build.starts_environment?
.prepend-top-default
.environment-information
- if @build.outdated_deployment?
......
......@@ -4,7 +4,7 @@ class BuildSuccessWorker
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
create_deployment(build) if build.environment.present?
create_deployment(build) if build.has_environment?
end
end
......
......@@ -1053,6 +1053,26 @@ describe Ci::Build, models: true do
end
end
describe '#has_environment?' do
subject { build.has_environment? }
context 'when environment is defined' do
before do
build.update(environment: 'review')
end
it { is_expected.to be_truthy }
end
context 'when environment is not defined' do
before do
build.update(environment: nil)
end
it { is_expected.to be_falsey }
end
end
describe '#starts_environment?' do
subject { build.starts_environment? }
......@@ -1061,7 +1081,17 @@ describe Ci::Build, models: true do
build.update(environment: 'review')
end
it { is_expected.to be_truthy }
context 'no action is defined' do
it { is_expected.to be_truthy }
end
context 'and start action is defined' do
before do
build.update(options: { environment: { action: 'start' } } )
end
it { is_expected.to be_truthy }
end
end
context 'when environment is not defined' do
......@@ -1106,11 +1136,13 @@ describe Ci::Build, models: true do
describe '#last_deployment' do
subject { build.last_deployment }
context 'when multiple deployments is created returns latest one' do
context 'when multiple deployments are created' do
let!(:deployment1) { create(:deployment, deployable: build) }
let!(:deployment2) { create(:deployment, deployable: build) }
it { is_expected.to eq(deployment2) }
it 'returns the latest one' do
is_expected.to eq(deployment2)
end
end
end
......
......@@ -4,14 +4,12 @@ describe Ci::Build, models: true do
let(:build) { create(:ci_build) }
let(:test_trace) { 'This is a test' }
describe 'ss' do
it { is_expected.to belong_to(:runner) }
it { is_expected.to belong_to(:trigger_request) }
it { is_expected.to belong_to(:erased_by) }
it { is_expected.to have_many(:deployments) }
end
describe '#trace' do
it 'obfuscates project runners token' do
allow(build).to receive(:raw_trace).and_return("Test: #{build.project.runners_token}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment