diff options
author | Matija Čupić <matteeyah@gmail.com> | 2017-12-22 23:06:15 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2017-12-22 23:06:15 +0100 |
commit | 771b97394a16ae8dcd9acc84ab6a076f68726fd9 (patch) | |
tree | 30624bc5739274878cd0161d3cbf43b67d64c241 | |
parent | 0a002e230badf96f5c89d55945ddd85113edd628 (diff) | |
download | gitlab-ce-771b97394a16ae8dcd9acc84ab6a076f68726fd9.tar.gz |
Use Project.cache_index in Build#cache
-rw-r--r-- | app/models/ci/build.rb | 6 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 36 |
2 files changed, 41 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 83fe23606d1..e4ca74f87f2 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -461,7 +461,11 @@ module Ci end def cache - [options[:cache]] + if options[:cache] && project.cache_index + options[:cache].merge(key: "#{options[:cache][:key]}:#{project.cache_index}") + else + [options[:cache]] + end end def credentials diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 871e8b47650..96513281994 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -255,6 +255,42 @@ describe Ci::Build do end end + describe '#cache' do + let(:options) { { cache: { key: "key", paths: ["public"], policy: "pull-push" } } } + + subject { build.cache } + + context 'when build has cache' do + before do + allow(build).to receive(:options).and_return(options) + end + + context 'when project has cache_index' do + before do + allow_any_instance_of(Project).to receive(:cache_index).and_return(1) + end + + it { is_expected.to include(key: "key:1") } + end + + context 'when project does not have cache_index' do + before do + allow_any_instance_of(Project).to receive(:cache_index).and_return(nil) + end + + it { is_expected.to eq([options[:cache]]) } + end + end + + context 'when build does not have cache' do + before do + allow(build).to receive(:options).and_return({}) + end + + it { is_expected.to eq([nil]) } + end + end + describe '#depends_on_builds' do let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') } let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') } |