summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-08-30 02:54:07 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-08-30 02:54:07 +0800
commit031b162392c074b0bff1a5d4239acd8026592fdd (patch)
treeacfc110a0a744248314a8542a91115881f64ddbf
parent7e32e2ef20feb9c2bbc1b1504cc56c9185621c86 (diff)
downloadgitlab-ce-031b162392c074b0bff1a5d4239acd8026592fdd.tar.gz
Fix test for Pipeline#duration
-rw-r--r--spec/models/ci/pipeline_spec.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 721b20e0cb2..a34b9cb4461 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -124,17 +124,22 @@ describe Ci::Pipeline, models: true do
describe 'state machine' do
let(:current) { Time.now.change(usec: 0) }
- let(:build) { create :ci_build, name: 'build1', pipeline: pipeline }
+ let(:build) { create_build('build1', current - 60) }
+ let(:another_build) { create_build('build2', current + 20) }
describe '#duration' do
before do
- travel_to(current - 120) do
- pipeline.run
- end
+ pipeline.run
travel_to(current) do
- pipeline.succeed
+ build.success
+ end
+
+ travel_to(current + 80) do
+ another_build.drop
end
+
+ pipeline.drop
end
it 'matches sum of builds duration' do
@@ -169,6 +174,13 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.finished_at).to be_nil
end
end
+
+ def create_build(name, started_at = current)
+ create(:ci_build,
+ name: name,
+ pipeline: pipeline,
+ started_at: started_at)
+ end
end
describe '#branch?' do