Commit 43906336 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix tests and add has_environment?

parent d6e00f53
...@@ -131,12 +131,16 @@ module Ci ...@@ -131,12 +131,16 @@ module Ci
ExpandVariables.expand(environment, variables) if environment ExpandVariables.expand(environment, variables) if environment
end end
def has_environment?
self.environment.present?
end
def starts_environment? def starts_environment?
self.environment.present? && self.environment_action == 'start' has_environment? && self.environment_action == 'start'
end end
def stops_environment? def stops_environment?
self.environment.present? && self.environment_action == 'stop' has_environment? && self.environment_action == 'stop'
end end
def environment_action def environment_action
...@@ -148,7 +152,7 @@ module Ci ...@@ -148,7 +152,7 @@ module Ci
end end
def last_deployment def last_deployment
deployments.order(id: :desc).last deployments.last
end end
def depends_on_builds def depends_on_builds
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
= link_to namespace_project_runners_path(@build.project.namespace, @build.project) do = link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
Runners page Runners page
- if @build.environment.present? && @build.starts_environment? - if @build.starts_environment?
.prepend-top-default .prepend-top-default
.environment-information .environment-information
- if @build.outdated_deployment? - if @build.outdated_deployment?
......
...@@ -4,7 +4,7 @@ class BuildSuccessWorker ...@@ -4,7 +4,7 @@ class BuildSuccessWorker
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| 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
end end
......
...@@ -1053,6 +1053,26 @@ describe Ci::Build, models: true do ...@@ -1053,6 +1053,26 @@ describe Ci::Build, models: true do
end end
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 describe '#starts_environment?' do
subject { build.starts_environment? } subject { build.starts_environment? }
...@@ -1061,7 +1081,17 @@ describe Ci::Build, models: true do ...@@ -1061,7 +1081,17 @@ describe Ci::Build, models: true do
build.update(environment: 'review') build.update(environment: 'review')
end 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 end
context 'when environment is not defined' do context 'when environment is not defined' do
...@@ -1106,11 +1136,13 @@ describe Ci::Build, models: true do ...@@ -1106,11 +1136,13 @@ describe Ci::Build, models: true do
describe '#last_deployment' do describe '#last_deployment' do
subject { build.last_deployment } 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!(:deployment1) { create(:deployment, deployable: build) }
let!(:deployment2) { 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
end end
......
...@@ -4,14 +4,12 @@ describe Ci::Build, models: true do ...@@ -4,14 +4,12 @@ describe Ci::Build, models: true do
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
let(:test_trace) { 'This is a test' } let(:test_trace) { 'This is a test' }
describe 'ss' do
it { is_expected.to belong_to(:runner) } it { is_expected.to belong_to(:runner) }
it { is_expected.to belong_to(:trigger_request) } it { is_expected.to belong_to(:trigger_request) }
it { is_expected.to belong_to(:erased_by) } it { is_expected.to belong_to(:erased_by) }
it { is_expected.to have_many(:deployments) } it { is_expected.to have_many(:deployments) }
end
describe '#trace' do describe '#trace' do
it 'obfuscates project runners token' do it 'obfuscates project runners token' do
allow(build).to receive(:raw_trace).and_return("Test: #{build.project.runners_token}") 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