From d25c4803f4429d5aeb2ec1eeb920da216d33f024 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Feb 2018 11:21:40 +0100 Subject: Fix pipeline build specs related to variables order --- spec/models/ci/build_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 2b6b6a61182..43fba1349e3 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1854,7 +1854,8 @@ describe Ci::Build do end allow_any_instance_of(Ci::Pipeline) - .to receive(:predefined_variables) { [pipeline_pre_var] } + .to receive(:predefined_variables) + .and_return([project_pre_var] + [pipeline_pre_var]) end it do -- cgit v1.2.1 From 4f472d49b52452b0377fa0701dfe970f3e83bb85 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Feb 2018 12:24:16 +0100 Subject: Make pipeline priority variables concept explicit --- spec/models/ci/build_spec.rb | 26 +++++++++++++++++++++++++ spec/models/ci/pipeline_spec.rb | 43 +++++++++++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 5a4080f9c6c..d1db61084c3 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1891,6 +1891,32 @@ describe Ci::Build do end end end + + context 'when there are duplicated variables present ' do + context 'when there are duplicated YAML variables' do + before do + build.yaml_variables = [{ key: 'MYVAR', value: 'first', public: true }, + { key: 'MYVAR', value: 'second', public: true}] + end + + it 'keeps the last occurence of a variable by given key' do + expect(subject).not_to include(key: 'MYVAR', value: 'first', public: true) + expect(subject).to include(key: 'MYVAR', value: 'second', public: true) + end + end + + context 'when pipeline trigger variable overrides YAML variables' do + before do + build.yaml_variables = [{ key: 'MYVAR', value: 'myvar', public: true }] + pipeline.variables.build(key: 'MYVAR', value: 'pipeline value') + end + + it 'overrides YAML variable with a pipeline trigger variable' do + expect(subject).not_to include(key: 'MYVAR', value: 'myvar', public: true) + expect(subject).to include(key: 'MYVAR', value: 'pipeline value', public: false) + end + end + end end describe 'state transition: any => [:pending]' do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 14d234f6aab..4d5fc1dfcd8 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -167,15 +167,46 @@ describe Ci::Pipeline, :mailer do end end - describe '#predefined_variables' do - subject { pipeline.predefined_variables } + describe 'pipeline variables' do + describe '#predefined_variables' do + subject { pipeline.predefined_variables } - it { is_expected.to be_an(Array) } + it { is_expected.to be_an(Array) } + + it 'includes the defined keys' do + keys = subject.map { |v| v.fetch(:key) } + + expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') + end + + it 'includes project-level predefined variables' do + keys = subject.map { |v| v.fetch(:key) } + + expect(keys).to include('CI_PROJECT_NAME') + end + end + + describe '#priority_variables' do + before do + pipeline.variables.build(key: 'MY_VAR', value: 'my var') + end - it 'includes the defined keys' do - keys = subject.map { |v| v[:key] } + it 'returns trigger variables' do + expect(pipeline.priority_variables) + .to include(key: 'MY_VAR', value: 'my var', public: false) + end + end - expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') + describe '#runtime_variables' do + before do + pipeline.variables.build(key: 'MY_VAR', value: 'my var') + end + + it 'includes predefined and priority variables' do + variables = pipeline.runtime_variables.map { |v| v.fetch(:key) } + + expect(variables).to include('MY_VAR', 'CI_PIPELINE_ID', 'CI_PROJECT_ID') + end end end -- cgit v1.2.1 From c52255884ea1a54d66c0e5e52a67c25ad1a62644 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 28 Feb 2018 10:50:02 +0100 Subject: Add support for only/except: variables CI/CD config --- spec/models/ci/build_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index d1db61084c3..2328c3ee902 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1896,7 +1896,7 @@ describe Ci::Build do context 'when there are duplicated YAML variables' do before do build.yaml_variables = [{ key: 'MYVAR', value: 'first', public: true }, - { key: 'MYVAR', value: 'second', public: true}] + { key: 'MYVAR', value: 'second', public: true }] end it 'keeps the last occurence of a variable by given key' do -- cgit v1.2.1 From a032c296cc58b9ac95478f9ba3b49fee0cf6575e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 28 Feb 2018 15:10:09 +0100 Subject: Move pipeline-level variables from build to pipeline --- spec/models/ci/build_spec.rb | 20 ++------------------ spec/models/ci/pipeline_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 2328c3ee902..ecfb82f6b8d 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1245,24 +1245,8 @@ describe Ci::Build do end describe '#ref_slug' do - { - 'master' => 'master', - '1-foo' => '1-foo', - 'fix/1-foo' => 'fix-1-foo', - 'fix-1-foo' => 'fix-1-foo', - 'a' * 63 => 'a' * 63, - 'a' * 64 => 'a' * 63, - 'FOO' => 'foo', - '-' + 'a' * 61 + '-' => 'a' * 61, - '-' + 'a' * 62 + '-' => 'a' * 62, - '-' + 'a' * 63 + '-' => 'a' * 62, - 'a' * 62 + ' ' => 'a' * 62 - }.each do |ref, slug| - it "transforms #{ref} to #{slug}" do - build.ref = ref - - expect(build.ref_slug).to eq(slug) - end + it 'delegates ref_slug method to the pipeline' do + expect(build).to delegate_method(:ref_slug).to(:pipeline) end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 4d5fc1dfcd8..082d3262d9d 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1280,6 +1280,28 @@ describe Ci::Pipeline, :mailer do end end + describe '#ref_slug' do + { + 'master' => 'master', + '1-foo' => '1-foo', + 'fix/1-foo' => 'fix-1-foo', + 'fix-1-foo' => 'fix-1-foo', + 'a' * 63 => 'a' * 63, + 'a' * 64 => 'a' * 63, + 'FOO' => 'foo', + '-' + 'a' * 61 + '-' => 'a' * 61, + '-' + 'a' * 62 + '-' => 'a' * 62, + '-' + 'a' * 63 + '-' => 'a' * 62, + 'a' * 62 + ' ' => 'a' * 62 + }.each do |ref, slug| + it "transforms #{ref} to #{slug}" do + pipeline.ref = ref + + expect(pipeline.ref_slug).to eq(slug) + end + end + end + describe '#execute_hooks' do let!(:build_a) { create_build('a', 0) } let!(:build_b) { create_build('b', 0) } -- cgit v1.2.1 From a648209a07704d08e2a2faa9059d7b6e912bda62 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 1 Mar 2018 12:44:23 +0100 Subject: Revert changes to predefined variables hierarchy --- spec/models/ci/build_spec.rb | 49 ++++++++++++------------------- spec/models/ci/pipeline_spec.rb | 65 ++++------------------------------------- 2 files changed, 25 insertions(+), 89 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ecfb82f6b8d..c27313ed88b 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1245,8 +1245,24 @@ describe Ci::Build do end describe '#ref_slug' do - it 'delegates ref_slug method to the pipeline' do - expect(build).to delegate_method(:ref_slug).to(:pipeline) + { + 'master' => 'master', + '1-foo' => '1-foo', + 'fix/1-foo' => 'fix-1-foo', + 'fix-1-foo' => 'fix-1-foo', + 'a' * 63 => 'a' * 63, + 'a' * 64 => 'a' * 63, + 'FOO' => 'foo', + '-' + 'a' * 61 + '-' => 'a' * 61, + '-' + 'a' * 62 + '-' => 'a' * 62, + '-' + 'a' * 63 + '-' => 'a' * 62, + 'a' * 62 + ' ' => 'a' * 62 + }.each do |ref, slug| + it "transforms #{ref} to #{slug}" do + build.ref = ref + + expect(build.ref_slug).to eq(slug) + end end end @@ -1838,8 +1854,7 @@ describe Ci::Build do end allow_any_instance_of(Ci::Pipeline) - .to receive(:predefined_variables) - .and_return([project_pre_var] + [pipeline_pre_var]) + .to receive(:predefined_variables) { [pipeline_pre_var] } end it do @@ -1875,32 +1890,6 @@ describe Ci::Build do end end end - - context 'when there are duplicated variables present ' do - context 'when there are duplicated YAML variables' do - before do - build.yaml_variables = [{ key: 'MYVAR', value: 'first', public: true }, - { key: 'MYVAR', value: 'second', public: true }] - end - - it 'keeps the last occurence of a variable by given key' do - expect(subject).not_to include(key: 'MYVAR', value: 'first', public: true) - expect(subject).to include(key: 'MYVAR', value: 'second', public: true) - end - end - - context 'when pipeline trigger variable overrides YAML variables' do - before do - build.yaml_variables = [{ key: 'MYVAR', value: 'myvar', public: true }] - pipeline.variables.build(key: 'MYVAR', value: 'pipeline value') - end - - it 'overrides YAML variable with a pipeline trigger variable' do - expect(subject).not_to include(key: 'MYVAR', value: 'myvar', public: true) - expect(subject).to include(key: 'MYVAR', value: 'pipeline value', public: false) - end - end - end end describe 'state transition: any => [:pending]' do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 082d3262d9d..14d234f6aab 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -167,46 +167,15 @@ describe Ci::Pipeline, :mailer do end end - describe 'pipeline variables' do - describe '#predefined_variables' do - subject { pipeline.predefined_variables } + describe '#predefined_variables' do + subject { pipeline.predefined_variables } - it { is_expected.to be_an(Array) } - - it 'includes the defined keys' do - keys = subject.map { |v| v.fetch(:key) } - - expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') - end - - it 'includes project-level predefined variables' do - keys = subject.map { |v| v.fetch(:key) } - - expect(keys).to include('CI_PROJECT_NAME') - end - end - - describe '#priority_variables' do - before do - pipeline.variables.build(key: 'MY_VAR', value: 'my var') - end - - it 'returns trigger variables' do - expect(pipeline.priority_variables) - .to include(key: 'MY_VAR', value: 'my var', public: false) - end - end - - describe '#runtime_variables' do - before do - pipeline.variables.build(key: 'MY_VAR', value: 'my var') - end + it { is_expected.to be_an(Array) } - it 'includes predefined and priority variables' do - variables = pipeline.runtime_variables.map { |v| v.fetch(:key) } + it 'includes the defined keys' do + keys = subject.map { |v| v[:key] } - expect(variables).to include('MY_VAR', 'CI_PIPELINE_ID', 'CI_PROJECT_ID') - end + expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') end end @@ -1280,28 +1249,6 @@ describe Ci::Pipeline, :mailer do end end - describe '#ref_slug' do - { - 'master' => 'master', - '1-foo' => '1-foo', - 'fix/1-foo' => 'fix-1-foo', - 'fix-1-foo' => 'fix-1-foo', - 'a' * 63 => 'a' * 63, - 'a' * 64 => 'a' * 63, - 'FOO' => 'foo', - '-' + 'a' * 61 + '-' => 'a' * 61, - '-' + 'a' * 62 + '-' => 'a' * 62, - '-' + 'a' * 63 + '-' => 'a' * 62, - 'a' * 62 + ' ' => 'a' * 62 - }.each do |ref, slug| - it "transforms #{ref} to #{slug}" do - pipeline.ref = ref - - expect(pipeline.ref_slug).to eq(slug) - end - end - end - describe '#execute_hooks' do let!(:build_a) { create_build('a', 0) } let!(:build_b) { create_build('b', 0) } -- cgit v1.2.1 From 96d6193cabacc92f43bd441f48d63b226d9dad21 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Mar 2018 12:55:27 +0100 Subject: Make it possible to access static builds variables This makes it possible to access static build variables even when an object is not persisted yet. This will allow us to evaluate build variables using only/except policies before deciding whether we actually want to persist the build in the database, or not. --- spec/models/ci/build_spec.rb | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 9da3de7a828..c3061940fd7 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1977,6 +1977,59 @@ describe Ci::Build do end end end + + context 'when build has not been persisted yet' do + let(:build) do + described_class.new( + name: 'rspec', + stage: 'test', + ref: 'feature', + project: project, + pipeline: pipeline + ) + end + + it 'does not persist the build' do + expect(build).to be_valid + expect(build).not_to be_persisted + + variables = build.variables + + expect(variables.size).to be >= 28 + expect(build).not_to be_persisted + end + + it 'returns static predefined variables' do + keys = %w[CI_JOB_NAME + CI_COMMIT_SHA + CI_COMMIT_REF_NAME + CI_COMMIT_REF_SLUG + CI_JOB_STAGE] + + build.variables.map { |var| var.fetch(:key) }.tap do |names| + expect(names).to include(*keys) + end + + expect(build.variables).to include(key: 'CI_COMMIT_REF_NAME', + value: 'feature', + public: true) + end + + it 'does not return prohibited variables' do + keys = %w[CI_JOB_ID + CI_JOB_TOKEN + CI_BUILD_ID + CI_BUILD_TOKEN + CI_REGISTRY_USER + CI_REGISTRY_PASSWORD + CI_REPOSITORY_URL + CI_ENVIRONMENT_URL] + + build.variables.map { |var| var.fetch(:key) }.tap do |names| + expect(names).not_to include(*keys) + end + end + end end describe 'state transition: any => [:pending]' do -- cgit v1.2.1 From b6e4e449fbd2f844736e9121067c3cfea2cb2933 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Mar 2018 13:56:16 +0100 Subject: Integrate build seeds with variables expressions policy --- spec/models/ci/pipeline_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 92f00cfbc19..dd94515b0a4 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -346,6 +346,20 @@ describe Ci::Pipeline, :mailer do end end end + + context 'when variables policy is specified' do + let(:config) do + { unit: { script: 'minitest', only: { variables: ['$CI_PIPELINE_SOURCE'] } }, + feature: { script: 'spinach', only: { variables: ['$UNDEFINED'] } } } + end + + it 'returns stage seeds only when variables expression is truthy' do + seeds = pipeline.stage_seeds + + expect(seeds.size).to eq 1 + expect(seeds.dig(0, 0, :name)).to eq 'unit' + end + end end describe '#seeds_size' do -- cgit v1.2.1 From 1c2530ded3b52db0459095d5365460f12d104adb Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Mar 2018 15:21:31 +0100 Subject: Expose evaluable variables method from build object --- spec/models/ci/build_spec.rb | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index c3061940fd7..6081ef04fb7 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1978,6 +1978,27 @@ describe Ci::Build do end end + context 'when build has not been persisted yet' do + let(:build) do + described_class.new( + name: 'rspec', + stage: 'test', + ref: 'feature', + project: project, + pipeline: pipeline + ) + end + + it 'returns static predefined variables' do + expect(build.variables.size).to be >= 28 + expect(build.variables) + .to include(key: 'CI_COMMIT_REF_NAME', value: 'feature', public: true) + expect(build).not_to be_persisted + end + end + end + + describe '#evaluable_variables' do context 'when build has not been persisted yet' do let(:build) do described_class.new( @@ -1993,9 +2014,8 @@ describe Ci::Build do expect(build).to be_valid expect(build).not_to be_persisted - variables = build.variables + variables = build.evaluable_variables - expect(variables.size).to be >= 28 expect(build).not_to be_persisted end @@ -2006,13 +2026,14 @@ describe Ci::Build do CI_COMMIT_REF_SLUG CI_JOB_STAGE] - build.variables.map { |var| var.fetch(:key) }.tap do |names| + variables = build.evaluable_variables + + variables.map { |env| env[:key] }.tap do |names| expect(names).to include(*keys) end - expect(build.variables).to include(key: 'CI_COMMIT_REF_NAME', - value: 'feature', - public: true) + expect(variables) + .to include(key: 'CI_COMMIT_REF_NAME', value: 'feature', public: true) end it 'does not return prohibited variables' do @@ -2025,7 +2046,7 @@ describe Ci::Build do CI_REPOSITORY_URL CI_ENVIRONMENT_URL] - build.variables.map { |var| var.fetch(:key) }.tap do |names| + build.evaluable_variables.map { |env| env[:key] }.tap do |names| expect(names).not_to include(*keys) end end -- cgit v1.2.1 From da6bfd9b801c4d1c91593c6b4a755b097b644ab0 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Mar 2018 13:05:29 +0200 Subject: Decouple build variables from persisted environment --- spec/models/ci/build_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 6a45169c6a8..f4d3e57b225 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1998,7 +1998,7 @@ describe Ci::Build do end end - describe '#evaluable_variables' do + describe '#scoped_variables' do context 'when build has not been persisted yet' do let(:build) do described_class.new( @@ -2014,7 +2014,7 @@ describe Ci::Build do expect(build).to be_valid expect(build).not_to be_persisted - variables = build.evaluable_variables + build.scoped_variables expect(build).not_to be_persisted end @@ -2026,7 +2026,7 @@ describe Ci::Build do CI_COMMIT_REF_SLUG CI_JOB_STAGE] - variables = build.evaluable_variables + variables = build.scoped_variables variables.map { |env| env[:key] }.tap do |names| expect(names).to include(*keys) @@ -2046,7 +2046,7 @@ describe Ci::Build do CI_REPOSITORY_URL CI_ENVIRONMENT_URL] - build.evaluable_variables.map { |env| env[:key] }.tap do |names| + build.scoped_variables.map { |env| env[:key] }.tap do |names| expect(names).not_to include(*keys) end end -- cgit v1.2.1 From a60ccef9fec1d798dd0178d10b6a6a109612c17d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Mar 2018 13:46:22 +0200 Subject: Add specs for method that exposes build variables hash --- spec/models/ci/build_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index f4d3e57b225..0f62ff4ccae 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2053,6 +2053,18 @@ describe Ci::Build do end end + describe '#variables_hash' do + before do + project.variables.create!(key: 'MY_VAR', value: 'my value 1') + pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2') + end + + it 'returns a regular hash created in valid order' do + expect(build.variables_hash).to include('MY_VAR': 'my value 2') + expect(build.variables_hash).not_to include('MY_VAR': 'my value 1') + end + end + describe 'state transition: any => [:pending]' do let(:build) { create(:ci_build, :created) } -- cgit v1.2.1 From b1ce3ba142d3b735eded44bb5490984042c9d2e1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Mar 2018 14:34:55 +0200 Subject: Improve specs for predefined build variables --- spec/models/ci/build_spec.rb | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 0f62ff4ccae..48eeca53f46 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2054,14 +2054,28 @@ describe Ci::Build do end describe '#variables_hash' do - before do - project.variables.create!(key: 'MY_VAR', value: 'my value 1') - pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2') + context 'when overriding secret variables' do + before do + project.variables.create!(key: 'MY_VAR', value: 'my value 1') + pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2') + end + + it 'returns a regular hash created using valid ordering' do + expect(build.variables_hash).to include('MY_VAR': 'my value 2') + expect(build.variables_hash).not_to include('MY_VAR': 'my value 1') + end end - it 'returns a regular hash created in valid order' do - expect(build.variables_hash).to include('MY_VAR': 'my value 2') - expect(build.variables_hash).not_to include('MY_VAR': 'my value 1') + context 'when overriding user-provided variables' do + before do + pipeline.variables.build(key: 'MY_VAR', value: 'pipeline value') + build.yaml_variables = [{ key: 'MY_VAR', value: 'myvar', public: true }] + end + + it 'returns a hash including variable with higher precedence' do + expect(build.variables_hash).to include('MY_VAR': 'pipeline value') + expect(build.variables_hash).not_to include('MY_VAR': 'myvar') + end end end -- cgit v1.2.1 From 1a84f96a0602c9e6a9dfd2e2de3cfbe9385470ff Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 29 Mar 2018 14:42:23 +0200 Subject: Extract build variables that depend on persistence --- spec/models/ci/build_spec.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 42b40ff91fc..4b9ddb3c831 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1463,24 +1463,24 @@ describe Ci::Build do let(:container_registry_enabled) { false } let(:predefined_variables) do [ + { key: 'CI_JOB_ID', value: build.id.to_s, public: true }, + { key: 'CI_JOB_TOKEN', value: build.token, public: false }, + { key: 'CI_BUILD_ID', value: build.id.to_s, public: true }, + { key: 'CI_BUILD_TOKEN', value: build.token, public: false }, + { key: 'CI_REGISTRY_USER', value: 'gitlab-ci-token', public: true }, + { key: 'CI_REGISTRY_PASSWORD', value: build.token, public: false }, + { key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }, { key: 'CI', value: 'true', public: true }, { key: 'GITLAB_CI', value: 'true', public: true }, { key: 'GITLAB_FEATURES', value: project.namespace.features.join(','), public: true }, { key: 'CI_SERVER_NAME', value: 'GitLab', public: true }, { key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true }, { key: 'CI_SERVER_REVISION', value: Gitlab::REVISION, public: true }, - { key: 'CI_JOB_ID', value: build.id.to_s, public: true }, { key: 'CI_JOB_NAME', value: 'test', public: true }, { key: 'CI_JOB_STAGE', value: 'test', public: true }, - { key: 'CI_JOB_TOKEN', value: build.token, public: false }, { key: 'CI_COMMIT_SHA', value: build.sha, public: true }, { key: 'CI_COMMIT_REF_NAME', value: build.ref, public: true }, { key: 'CI_COMMIT_REF_SLUG', value: build.ref_slug, public: true }, - { key: 'CI_REGISTRY_USER', value: 'gitlab-ci-token', public: true }, - { key: 'CI_REGISTRY_PASSWORD', value: build.token, public: false }, - { key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }, - { key: 'CI_BUILD_ID', value: build.id.to_s, public: true }, - { key: 'CI_BUILD_TOKEN', value: build.token, public: false }, { key: 'CI_BUILD_REF', value: build.sha, public: true }, { key: 'CI_BUILD_BEFORE_SHA', value: build.before_sha, public: true }, { key: 'CI_BUILD_REF_NAME', value: build.ref, public: true }, @@ -1945,6 +1945,7 @@ describe Ci::Build do before do allow(build).to receive(:predefined_variables) { [build_pre_var] } allow(build).to receive(:yaml_variables) { [build_yaml_var] } + allow(build).to receive(:persisted_variables) { [] } allow_any_instance_of(Project) .to receive(:predefined_variables) { [project_pre_var] } -- cgit v1.2.1 From a5f9e49f1317345d1b72566ecff188dff5f74913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 29 Mar 2018 21:17:18 +0200 Subject: Add user_provided and gcp_provided cluster scopes --- spec/models/clusters/cluster_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'spec/models') diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 8f12a0e3085..ae96e5d1aa2 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -39,6 +39,30 @@ describe Clusters::Cluster do it { is_expected.to contain_exactly(cluster) } end + describe '.user_provided' do + subject { described_class.user_provided } + + let!(:cluster) { create(:cluster, :provided_by_user) } + + before do + create(:cluster, :provided_by_gcp) + end + + it { is_expected.to contain_exactly(cluster) } + end + + describe '.gcp_provided' do + subject { described_class.gcp_provided } + + let!(:cluster) { create(:cluster, :provided_by_gcp) } + + before do + create(:cluster, :provided_by_user) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe 'validation' do subject { cluster.valid? } -- cgit v1.2.1 From 982e5436e1ef9b309f8ee3a205f1e168273386b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 29 Mar 2018 21:24:10 +0200 Subject: Add installed scope to cluster applications --- spec/models/clusters/applications/helm_spec.rb | 12 ++++++++++++ spec/models/clusters/applications/ingress_spec.rb | 12 ++++++++++++ spec/models/clusters/applications/prometheus_spec.rb | 12 ++++++++++++ spec/models/clusters/applications/runner_spec.rb | 12 ++++++++++++ 4 files changed, 48 insertions(+) (limited to 'spec/models') diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb index ba7bad617b4..0eb1e3876e2 100644 --- a/spec/models/clusters/applications/helm_spec.rb +++ b/spec/models/clusters/applications/helm_spec.rb @@ -3,6 +3,18 @@ require 'rails_helper' describe Clusters::Applications::Helm do include_examples 'cluster application core specs', :clusters_applications_helm + describe '.installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_helm, :installed) } + + before do + create(:clusters_applications_helm, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe '#install_command' do let(:helm) { create(:clusters_applications_helm) } diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb index 03f5b88a525..a47a07d908d 100644 --- a/spec/models/clusters/applications/ingress_spec.rb +++ b/spec/models/clusters/applications/ingress_spec.rb @@ -11,6 +11,18 @@ describe Clusters::Applications::Ingress do allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_async) end + describe '.installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_ingress, :installed) } + + before do + create(:clusters_applications_ingress, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe '#make_installed!' do before do application.make_installed! diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 2905b58066b..aeca6ee903a 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -4,6 +4,18 @@ describe Clusters::Applications::Prometheus do include_examples 'cluster application core specs', :clusters_applications_prometheus include_examples 'cluster application status specs', :cluster_application_prometheus + describe '.installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_prometheus, :installed) } + + before do + create(:clusters_applications_prometheus, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe 'transition to installed' do let(:project) { create(:project) } let(:cluster) { create(:cluster, projects: [project]) } diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index a574779e39d..64d995a73c1 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -8,6 +8,18 @@ describe Clusters::Applications::Runner do it { is_expected.to belong_to(:runner) } + describe '.installed' do + subject { described_class.installed } + + let!(:cluster) { create(:clusters_applications_runner, :installed) } + + before do + create(:clusters_applications_runner, :errored) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe '#install_command' do let(:kubeclient) { double('kubernetes client') } let(:gitlab_runner) { create(:clusters_applications_runner, runner: ci_runner) } -- cgit v1.2.1 From 0a203f408786ae2e28616a0e1bf488595f7f115b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 30 Mar 2018 10:32:28 +0200 Subject: Improve naming and optimize methods of the build class --- spec/models/ci/build_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 4b9ddb3c831..a12717835b0 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2070,7 +2070,7 @@ describe Ci::Build do end end - describe '#variables_hash' do + describe '#scoped_variables_hash' do context 'when overriding secret variables' do before do project.variables.create!(key: 'MY_VAR', value: 'my value 1') @@ -2078,8 +2078,8 @@ describe Ci::Build do end it 'returns a regular hash created using valid ordering' do - expect(build.variables_hash).to include('MY_VAR': 'my value 2') - expect(build.variables_hash).not_to include('MY_VAR': 'my value 1') + expect(build.scoped_variables_hash).to include('MY_VAR': 'my value 2') + expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1') end end @@ -2090,8 +2090,8 @@ describe Ci::Build do end it 'returns a hash including variable with higher precedence' do - expect(build.variables_hash).to include('MY_VAR': 'pipeline value') - expect(build.variables_hash).not_to include('MY_VAR': 'myvar') + expect(build.scoped_variables_hash).to include('MY_VAR': 'pipeline value') + expect(build.scoped_variables_hash).not_to include('MY_VAR': 'myvar') end end end -- cgit v1.2.1 From 22b05a1ff74d4f64490f93995259602b3d07c3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Fri, 30 Mar 2018 15:45:59 +0000 Subject: Extend API for exporting a project with direct upload URL --- spec/models/project_spec.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 05014222623..96adf64bcec 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2560,7 +2560,7 @@ describe Project do end end - describe '#remove_exports' do + describe '#remove_export' do let(:legacy_project) { create(:project, :legacy_storage, :with_export) } let(:project) { create(:project, :with_export) } @@ -2608,6 +2608,23 @@ describe Project do end end + describe '#remove_exported_project_file' do + let(:project) { create(:project, :with_export) } + + it 'removes the exported project file' do + exported_file = project.export_project_path + + expect(File.exist?(exported_file)).to be_truthy + + allow(FileUtils).to receive(:rm_f).and_call_original + expect(FileUtils).to receive(:rm_f).with(exported_file).and_call_original + + project.remove_exported_project_file + + expect(File.exist?(exported_file)).to be_falsy + end + end + describe '#forks_count' do it 'returns the number of forks' do project = build(:project) -- cgit v1.2.1 From b26913a30c608f81c44abece263da8d01faf0126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 30 Mar 2018 17:34:10 +0200 Subject: Extract cluster installed query to scope --- spec/models/clusters/cluster_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/models') diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index ae96e5d1aa2..b942554d67b 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -63,6 +63,18 @@ describe Clusters::Cluster do it { is_expected.to contain_exactly(cluster) } end + describe '.gcp_installed' do + subject { described_class.gcp_installed } + + let!(:cluster) { create(:cluster, :provided_by_gcp) } + + before do + create(:cluster, :providing_by_gcp) + end + + it { is_expected.to contain_exactly(cluster) } + end + describe 'validation' do subject { cluster.valid? } -- cgit v1.2.1 From b95918dda8c6cd5328d028492d36c3ee07e35943 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 2 Apr 2018 17:13:23 +0200 Subject: Make error messages even more descriptive --- spec/models/project_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 96adf64bcec..fef868ac0f2 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -224,14 +224,14 @@ describe Project do project2 = build(:project, import_url: 'http://localhost:9000/t.git') expect(project2).to be_invalid - expect(project2.errors[:import_url]).to include('imports are not allowed from that URL') + expect(project2.errors[:import_url].first).to include('Requests to localhost are not allowed') end it "does not allow blocked import_url port" do project2 = build(:project, import_url: 'http://github.com:25/t.git') expect(project2).to be_invalid - expect(project2.errors[:import_url]).to include('imports are not allowed from that URL') + expect(project2.errors[:import_url].first).to include('Only allowed ports are 22, 80, 443') end describe 'project pending deletion' do -- cgit v1.2.1 From ddfc661f794ca02654853a9e223b9a5f3fb983ab Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Mon, 26 Mar 2018 20:21:49 +0200 Subject: Use shard name in Git::GitlabProjects instead of shard path Closes gitaly#1110 --- spec/models/project_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1a7a6e035ea..4df093c4a10 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1617,7 +1617,7 @@ describe Project do before do allow_any_instance_of(Gitlab::Shell).to receive(:import_repository) - .with(project.repository_storage_path, project.disk_path, project.import_url) + .with(project.repository_storage, project.disk_path, project.import_url) .and_return(true) expect_any_instance_of(Repository).to receive(:after_import) @@ -1770,10 +1770,7 @@ describe Project do let(:project) { forked_project_link.forked_to_project } it 'schedules a RepositoryForkWorker job' do - expect(RepositoryForkWorker).to receive(:perform_async).with( - project.id, - forked_from_project.repository_storage_path, - forked_from_project.disk_path).and_return(import_jid) + expect(RepositoryForkWorker).to receive(:perform_async).with(project.id).and_return(import_jid) expect(project.add_import_job).to eq(import_jid) end -- cgit v1.2.1 From 3d3b46f344748420a638f8a66745d974fa2c2748 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Wed, 4 Apr 2018 09:19:47 +0000 Subject: [Rails5] Rename `sort` methods to `sort_by_attribute` --- spec/models/concerns/issuable_spec.rb | 8 ++++---- spec/models/user_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index f8874d14e3f..05693f067e1 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -176,7 +176,7 @@ describe Issuable do end end - describe "#sort" do + describe "#sort_by_attribute" do let(:project) { create(:project) } context "by milestone due date" do @@ -193,12 +193,12 @@ describe Issuable do let!(:issue3) { create(:issue, project: project) } it "sorts desc" do - issues = project.issues.sort('milestone_due_desc') + issues = project.issues.sort_by_attribute('milestone_due_desc') expect(issues).to match_array([issue2, issue1, issue, issue3]) end it "sorts asc" do - issues = project.issues.sort('milestone_due_asc') + issues = project.issues.sort_by_attribute('milestone_due_asc') expect(issues).to match_array([issue1, issue2, issue, issue3]) end end @@ -210,7 +210,7 @@ describe Issuable do it 'has no duplicates across pages' do sorted_issue_ids = 1.upto(10).map do |i| - project.issues.sort('milestone_due_desc').page(i).per(1).first.id + project.issues.sort_by_attribute('milestone_due_desc').page(i).per(1).first.id end expect(sorted_issue_ids).to eq(sorted_issue_ids.uniq) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 100418da804..4027c420e47 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1451,7 +1451,7 @@ describe User do end end - describe '#sort' do + describe '#sort_by_attribute' do before do described_class.delete_all @user = create :user, created_at: Date.today, current_sign_in_at: Date.today, name: 'Alpha' @@ -1460,7 +1460,7 @@ describe User do end context 'when sort by recent_sign_in' do - let(:users) { described_class.sort('recent_sign_in') } + let(:users) { described_class.sort_by_attribute('recent_sign_in') } it 'sorts users by recent sign-in time' do expect(users.first).to eq(@user) @@ -1473,7 +1473,7 @@ describe User do end context 'when sort by oldest_sign_in' do - let(:users) { described_class.sort('oldest_sign_in') } + let(:users) { described_class.sort_by_attribute('oldest_sign_in') } it 'sorts users by the oldest sign-in time' do expect(users.first).to eq(@user1) @@ -1486,15 +1486,15 @@ describe User do end it 'sorts users in descending order by their creation time' do - expect(described_class.sort('created_desc').first).to eq(@user) + expect(described_class.sort_by_attribute('created_desc').first).to eq(@user) end it 'sorts users in ascending order by their creation time' do - expect(described_class.sort('created_asc').first).to eq(@user2) + expect(described_class.sort_by_attribute('created_asc').first).to eq(@user2) end it 'sorts users by id in descending order when nil is passed' do - expect(described_class.sort(nil).first).to eq(@user2) + expect(described_class.sort_by_attribute(nil).first).to eq(@user2) end end -- cgit v1.2.1 From 16ea3315f2bb2a7764f2c101625422e6a374fa6f Mon Sep 17 00:00:00 2001 From: Zeger-Jan van de Weg Date: Wed, 4 Apr 2018 14:10:22 +0200 Subject: Revert "Allow CI/CD Jobs being grouped on version strings" This reverts commit 4f2cdb51df0f2729055ec4dc6960ae347163da16. --- spec/models/commit_status_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index b7ed8be69fc..c536dab2681 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -368,9 +368,7 @@ describe CommitStatus do 'rspec:windows 0 : / 1' => 'rspec:windows', 'rspec:windows 0 : / 1 name' => 'rspec:windows name', '0 1 name ruby' => 'name ruby', - '0 :/ 1 name ruby' => 'name ruby', - 'golang test 1.8' => 'golang test', - '1.9 golang test' => 'golang test' + '0 :/ 1 name ruby' => 'name ruby' } tests.each do |name, group_name| -- cgit v1.2.1 From 964933c9638c7d039a2843375d76c76c0b2cf25e Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Tue, 3 Apr 2018 16:58:27 +0200 Subject: Create metadata object on build object creation --- spec/models/ci/build_metadata_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 268561ee941..7e75d5a5411 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -13,7 +13,7 @@ describe Ci::BuildMetadata do end let(:build) { create(:ci_build, pipeline: pipeline) } - let(:build_metadata) { create(:ci_build_metadata, build: build) } + let(:build_metadata) { build.metadata } describe '#update_timeout_state' do subject { build_metadata } -- cgit v1.2.1 From a52e3edd1a1869c2656193c95f8f2e8fd3bc8fa2 Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Wed, 4 Apr 2018 21:31:56 +0200 Subject: Specify default value for Project#build_timeout --- .../concerns/chronic_duration_attribute_spec.rb | 34 +++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/chronic_duration_attribute_spec.rb b/spec/models/concerns/chronic_duration_attribute_spec.rb index 27c86e60e60..8847623f705 100644 --- a/spec/models/concerns/chronic_duration_attribute_spec.rb +++ b/spec/models/concerns/chronic_duration_attribute_spec.rb @@ -63,8 +63,8 @@ shared_examples 'ChronicDurationAttribute writer' do subject.send("#{virtual_field}=", '') end - it 'writes nil' do - expect(subject.send(source_field)).to be_nil + it 'writes default value' do + expect(subject.send(source_field)).to eq(default_value) end it 'passes validation' do @@ -77,8 +77,8 @@ shared_examples 'ChronicDurationAttribute writer' do subject.send("#{virtual_field}=", nil) end - it 'writes nil' do - expect(subject.send(source_field)).to be_nil + it 'writes default value' do + expect(subject.send(source_field)).to eq(default_value) end it 'passes validation' do @@ -92,20 +92,34 @@ shared_examples 'ChronicDurationAttribute writer' do end describe 'ChronicDurationAttribute' do - let(:source_field) {:maximum_timeout} - let(:virtual_field) {:maximum_timeout_human_readable} + context 'when default value is not set' do + let(:source_field) {:maximum_timeout} + let(:virtual_field) {:maximum_timeout_human_readable} + let(:default_value) { nil } - subject { Ci::Runner.new } + subject { create(:ci_runner) } - it_behaves_like 'ChronicDurationAttribute reader' - it_behaves_like 'ChronicDurationAttribute writer' + it_behaves_like 'ChronicDurationAttribute reader' + it_behaves_like 'ChronicDurationAttribute writer' + end + + context 'when default value is set' do + let(:source_field) {:build_timeout} + let(:virtual_field) {:build_timeout_human_readable} + let(:default_value) { 3600 } + + subject { create(:project) } + + it_behaves_like 'ChronicDurationAttribute reader' + it_behaves_like 'ChronicDurationAttribute writer' + end end describe 'ChronicDurationAttribute - reader' do let(:source_field) {:timeout} let(:virtual_field) {:timeout_human_readable} - subject {Ci::BuildMetadata.new} + subject { create(:ci_build).ensure_metadata } it "doesn't contain dynamically created writer method" do expect(subject.class).not_to be_public_method_defined("#{virtual_field}=") -- cgit v1.2.1 From 52967b107b7b2f1472b4c005f70f21346079cd95 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 3 Apr 2018 11:00:33 +0000 Subject: Merge branch 'jej/mattermost-notification-confidentiality-10-6' into 'security-10-6' [10.6] Prevent notes on confidential issues from being sent to chat See merge request gitlab/gitlabhq!2366 # Conflicts: # app/helpers/services_helper.rb --- spec/models/note_spec.rb | 15 +++++++++++++++ spec/models/project_services/hipchat_service_spec.rb | 15 +++++++++++++++ spec/models/service_spec.rb | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) (limited to 'spec/models') diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index c853f707e6d..86962cd8d61 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -191,6 +191,21 @@ describe Note do end end + describe "confidential?" do + it "delegates to noteable" do + issue_note = build(:note, :on_issue) + confidential_note = build(:note, noteable: create(:issue, confidential: true)) + + expect(issue_note.confidential?).to be_falsy + expect(confidential_note.confidential?).to be_truthy + end + + it "is falsey when noteable can't be confidential" do + commit_note = build(:note_on_commit) + expect(commit_note.confidential?).to be_falsy + end + end + describe "cross_reference_not_visible_for?" do let(:private_user) { create(:user) } let(:private_project) { create(:project, namespace: private_user.namespace) { |p| p.add_master(private_user) } } diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 3e2a166cdd6..0cd712e2f40 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -253,6 +253,21 @@ describe HipchatService do "#{title}" \ "
issue note
") end + + context 'with confidential issue' do + before do + issue.update!(confidential: true) + end + + it 'calls Hipchat API with issue comment' do + data = Gitlab::DataBuilder::Note.build(issue_note, user) + hipchat.execute(data) + + message = hipchat.send(:create_message, data) + + expect(message).to include("
issue note
") + end + end end context 'when snippet comment event triggered' do diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 83ed3b203e6..28c908ea425 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -10,6 +10,22 @@ describe Service do it { is_expected.to validate_presence_of(:type) } end + describe 'Scopes' do + describe '.confidential_note_hooks' do + it 'includes services where confidential_note_events is true' do + create(:service, active: true, confidential_note_events: true) + + expect(described_class.confidential_note_hooks.count).to eq 1 + end + + it 'excludes services where confidential_note_events is false' do + create(:service, active: true, confidential_note_events: false) + + expect(described_class.confidential_note_hooks.count).to eq 0 + end + end + end + describe "Test Button" do describe '#can_test?' do let(:service) { create(:service, project: project) } -- cgit v1.2.1 From 48b17e991a960c006da278d4c1f534b1db81d070 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Wed, 4 Apr 2018 16:40:58 +0200 Subject: Add helper for accessing lfs_objects for project This makes accessing LFS Objects for a project easier project.lfs_storage_project.lfs_objects` becomes project.all_lfs_objects This will make the refactor in https://gitlab.com/gitlab-org/gitlab-ce/issues/39769 easier to deal with. --- spec/models/project_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0e560be9eaa..8bd62dcdccb 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2022,6 +2022,22 @@ describe Project do expect(forked_project.lfs_storage_project).to eq forked_project end end + + describe '#all_lfs_objects' do + let(:lfs_object) { create(:lfs_object) } + + before do + project.lfs_objects << lfs_object + end + + it 'returns the lfs object for a project' do + expect(project.all_lfs_objects).to contain_exactly(lfs_object) + end + + it 'returns the lfs object for a fork' do + expect(forked_project.all_lfs_objects).to contain_exactly(lfs_object) + end + end end describe '#pushes_since_gc' do -- cgit v1.2.1 From 7de250fb81fb24f8e905cfb330072206c4a8a40a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 5 Apr 2018 11:14:26 +0200 Subject: Ensure internal users (ghost, support bot) get assigned a namespace --- spec/models/user_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4027c420e47..a600987d0bf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2071,6 +2071,8 @@ describe User do expect(ghost).to be_ghost expect(ghost).to be_persisted + expect(ghost.namespace).not_to be_nil + expect(ghost.namespace).to be_persisted end it "does not create a second ghost user if one is already present" do -- cgit v1.2.1 From 902cec12b5b531434ccf7ecf6df22ddb4249c253 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 5 Apr 2018 12:13:10 +0200 Subject: Don't export `Project#description_html` Since we can regenerate `description_html` from the `description`, we should not export it. This avoids some complexity when overriding the description during an import/export where we would need to invalidate this cached field. Now we refresh the markdown cache after the import --- spec/models/project_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0e560be9eaa..af5b1654b65 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -3227,6 +3227,7 @@ describe Project do expect(project).to receive(:update_project_counter_caches) expect(project).to receive(:remove_import_jid) expect(project).to receive(:after_create_default_branch) + expect(project).to receive(:refresh_markdown_cache!) project.after_import end -- cgit v1.2.1 From 8fc9ff7f131aa850ce4b1a8cb86ab4fa9b46410d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 6 Apr 2018 12:10:30 +0200 Subject: Fix environment deployment platform filter method --- spec/models/environment_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'spec/models') diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 412eca4a56b..56161bfcc28 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -368,6 +368,32 @@ describe Environment do end end + describe '#deployment_platform' do + context 'when there is a deployment platform for environment' do + let!(:cluster) do + create(:cluster, :provided_by_gcp, + environment_scope: '*', projects: [project]) + end + + it 'finds a deployment platform' do + expect(environment.deployment_platform).to eq cluster.platform + end + end + + context 'when there is no deployment platform for environment' do + it 'returns nil' do + expect(environment.deployment_platform).to be_nil + end + end + + it 'checks deployment platforms associated with a project' do + expect(project).to receive(:deployment_platform) + .with(environment: environment.name) + + environment.deployment_platform + end + end + describe '#terminals' do subject { environment.terminals } -- cgit v1.2.1 From 29b0a90c208f29606a05d1391a72b9ff7ff843b1 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Wed, 4 Apr 2018 17:14:19 +0200 Subject: Cache personal projects count. Closes #37462. --- spec/models/user_spec.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a600987d0bf..73266c0085f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2234,6 +2234,20 @@ describe User do end end + context '#invalidate_personal_projects_count' do + let(:user) { build_stubbed(:user) } + + it 'invalidates cache for personal projects counter' do + cache_mock = double + + expect(cache_mock).to receive(:delete).with(['users', user.id, 'personal_projects_count']) + + allow(Rails).to receive(:cache).and_return(cache_mock) + + user.invalidate_personal_projects_count + end + end + describe '#allow_password_authentication_for_web?' do context 'regular user' do let(:user) { build(:user) } @@ -2283,11 +2297,9 @@ describe User do user = build(:user) projects = double(:projects, count: 1) - expect(user).to receive(:personal_projects).once.and_return(projects) + expect(user).to receive(:personal_projects).and_return(projects) - 2.times do - expect(user.personal_projects_count).to eq(1) - end + expect(user.personal_projects_count).to eq(1) end end -- cgit v1.2.1 From 20695052db6860620365af9b86ab301759d1405d Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Fri, 6 Apr 2018 10:57:19 +0000 Subject: [Rails5] Update `type_cast_*_database` methods --- spec/models/merge_request_diff_commit_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb index 7709cf43200..8c01a7ac18f 100644 --- a/spec/models/merge_request_diff_commit_spec.rb +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -36,7 +36,7 @@ describe MergeRequestDiffCommit do "committer_email": "dmitriy.zaporozhets@gmail.com", "merge_request_diff_id": merge_request_diff_id, "relative_order": 0, - "sha": sha_attribute.type_cast_for_database('5937ac0a7beb003549fc5fd26fc247adbce4a52e') + "sha": sha_attribute.serialize("5937ac0a7beb003549fc5fd26fc247adbce4a52e") }, { "message": "Change some files\n\nSigned-off-by: Dmitriy Zaporozhets \u003cdmitriy.zaporozhets@gmail.com\u003e\n", @@ -48,7 +48,7 @@ describe MergeRequestDiffCommit do "committer_email": "dmitriy.zaporozhets@gmail.com", "merge_request_diff_id": merge_request_diff_id, "relative_order": 1, - "sha": sha_attribute.type_cast_for_database('570e7b2abdd848b95f2f578043fc23bd6f6fd24d') + "sha": sha_attribute.serialize("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") } ] end @@ -79,7 +79,7 @@ describe MergeRequestDiffCommit do "committer_email": "alejorro70@gmail.com", "merge_request_diff_id": merge_request_diff_id, "relative_order": 0, - "sha": sha_attribute.type_cast_for_database('ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69') + "sha": sha_attribute.serialize("ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69") }] end -- cgit v1.2.1 From db18993f652425b72c4b854e18a002e0ec44b196 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Mon, 19 Mar 2018 10:11:12 -0600 Subject: Create barebones for Deploytoken Includes: - Model, factories, create service and controller actions - As usual, includes specs for everything - Builds UI (copy from PAT) - Add revoke action Closes #31591 --- spec/models/deploy_token_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 spec/models/deploy_token_spec.rb (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb new file mode 100644 index 00000000000..bd27da63dfe --- /dev/null +++ b/spec/models/deploy_token_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe DeployToken do + it { is_expected.to belong_to :project } + + describe 'validations' do + let(:project_deploy_token) { build(:deploy_token) } + + context 'with no scopes defined' do + it 'should not be valid' do + project_deploy_token.scopes = [] + + expect(project_deploy_token).not_to be_valid + expect(project_deploy_token.errors[:scopes].first).to eq("can't be blank") + end + end + end + + describe '#ensure_token' do + let(:project_deploy_token) { build(:deploy_token) } + + it 'should ensure a token' do + project_deploy_token.token = nil + project_deploy_token.save + + expect(project_deploy_token.token).not_to be_empty + end + end + + describe '#revoke!' do + subject { create(:deploy_token) } + + it 'should update revoke attribute' do + subject.revoke! + expect(subject.revoked?).to be_truthy + end + end +end -- cgit v1.2.1 From 370fc05da7f95bf6621867a71d51493cf3899e25 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Thu, 29 Mar 2018 16:56:35 -0600 Subject: Implement 'read_repo' for DeployTokens This will allow to download a repo using the token from the DeployToken --- spec/models/deploy_token_spec.rb | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index bd27da63dfe..26d846ac6c8 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -1,38 +1,56 @@ require 'spec_helper' describe DeployToken do + let(:deploy_token) { create(:deploy_token) } + it { is_expected.to belong_to :project } describe 'validations' do - let(:project_deploy_token) { build(:deploy_token) } - context 'with no scopes defined' do it 'should not be valid' do - project_deploy_token.scopes = [] + deploy_token.scopes = [] - expect(project_deploy_token).not_to be_valid - expect(project_deploy_token.errors[:scopes].first).to eq("can't be blank") + expect(deploy_token).not_to be_valid + expect(deploy_token.errors[:scopes].first).to eq("can't be blank") end end end describe '#ensure_token' do - let(:project_deploy_token) { build(:deploy_token) } - it 'should ensure a token' do - project_deploy_token.token = nil - project_deploy_token.save + deploy_token.token = nil + deploy_token.save - expect(project_deploy_token.token).not_to be_empty + expect(deploy_token.token).not_to be_empty end end describe '#revoke!' do - subject { create(:deploy_token) } - it 'should update revoke attribute' do - subject.revoke! - expect(subject.revoked?).to be_truthy + deploy_token.revoke! + expect(deploy_token.revoked?).to be_truthy + end + end + + describe "#active?" do + context "when it has been revoked" do + it 'should return false' do + deploy_token.revoke! + expect(deploy_token.active?).to be_falsy + end + end + + context "when it hasn't been revoked" do + it 'should return true' do + expect(deploy_token.active?).to be_truthy + end + end + end + + describe '#username' do + it 'returns Ghost username' do + ghost = User.ghost + expect(deploy_token.username).to eq(ghost.username) end end end -- cgit v1.2.1 From 171b2625b128e5954ce0a150a4fc923a22164e4e Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Wed, 4 Apr 2018 18:43:41 -0500 Subject: Addreses backend review suggestions - Remove extra method for authorize_admin_project - Ensure project presence - Rename 'read_repo' to 'read_repository' to be more verbose --- spec/models/deploy_token_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 26d846ac6c8..50f6f441a58 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -4,6 +4,7 @@ describe DeployToken do let(:deploy_token) { create(:deploy_token) } it { is_expected.to belong_to :project } + it { is_expected.to validate_presence_of :project } describe 'validations' do context 'with no scopes defined' do -- cgit v1.2.1 From 8315861c9a50675b4f4f4ca536f0da90f27994f3 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Thu, 5 Apr 2018 12:22:34 -0500 Subject: Include ProjectDeployTokens Also: - Changes scopes from serializer to use boolean columns - Fixes broken specs --- spec/models/deploy_token_spec.rb | 50 ++++++++++++++++++++++---------- spec/models/project_deploy_token_spec.rb | 15 ++++++++++ spec/models/project_spec.rb | 2 ++ 3 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 spec/models/project_deploy_token_spec.rb (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 50f6f441a58..395c97f13a5 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -1,28 +1,49 @@ require 'spec_helper' describe DeployToken do - let(:deploy_token) { create(:deploy_token) } + subject(:deploy_token) { create(:deploy_token) } - it { is_expected.to belong_to :project } - it { is_expected.to validate_presence_of :project } + it { is_expected.to have_many :project_deploy_tokens } + it { is_expected.to have_many(:projects).through(:project_deploy_tokens) } - describe 'validations' do - context 'with no scopes defined' do - it 'should not be valid' do - deploy_token.scopes = [] + describe '#ensure_token' do + it 'should ensure a token' do + deploy_token.token = nil + deploy_token.save + + expect(deploy_token.token).not_to be_empty + end + end + + describe '#ensure_at_least_one_scope' do + context 'with at least one scope' do + it 'should be valid' do + is_expected.to be_valid + end + end + + context 'with no scopes' do + it 'should be invalid' do + deploy_token = build(:deploy_token, read_repository: false, read_registry: false) expect(deploy_token).not_to be_valid - expect(deploy_token.errors[:scopes].first).to eq("can't be blank") + expect(deploy_token.errors[:base].first).to eq("Scopes can't be blank") end end end - describe '#ensure_token' do - it 'should ensure a token' do - deploy_token.token = nil - deploy_token.save + describe '#scopes' do + context 'with all the scopes' do + it 'should return scopes assigned to DeployToken' do + expect(deploy_token.scopes).to eq([:read_repository, :read_registry]) + end + end - expect(deploy_token.token).not_to be_empty + context 'with only one scope' do + it 'should return scopes assigned to DeployToken' do + deploy_token = create(:deploy_token, read_registry: false) + expect(deploy_token.scopes).to eq([:read_repository]) + end end end @@ -50,8 +71,7 @@ describe DeployToken do describe '#username' do it 'returns Ghost username' do - ghost = User.ghost - expect(deploy_token.username).to eq(ghost.username) + expect(deploy_token.username).to eq("gitlab+deploy-token-#{deploy_token.id}") end end end diff --git a/spec/models/project_deploy_token_spec.rb b/spec/models/project_deploy_token_spec.rb new file mode 100644 index 00000000000..ccaed23f11a --- /dev/null +++ b/spec/models/project_deploy_token_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe ProjectDeployToken, type: :model do + let(:project) { create(:project) } + let(:deploy_token) { create(:deploy_token) } + subject(:project_deploy_token) { create(:project_deploy_token, project: project, deploy_token: deploy_token) } + + it { is_expected.to belong_to :project } + it { is_expected.to belong_to :deploy_token } + it { is_expected.to accept_nested_attributes_for :deploy_token } + + it { is_expected.to validate_presence_of :deploy_token } + it { is_expected.to validate_presence_of :project } + it { is_expected.to validate_uniqueness_of(:deploy_token_id).scoped_to(:project_id) } +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7007f78e702..2675c2f52c1 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -84,6 +84,8 @@ describe Project do it { is_expected.to have_many(:custom_attributes).class_name('ProjectCustomAttribute') } it { is_expected.to have_many(:project_badges).class_name('ProjectBadge') } it { is_expected.to have_many(:lfs_file_locks) } + it { is_expected.to have_many(:project_deploy_tokens) } + it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) } context 'after initialized' do it "has a project_feature" do -- cgit v1.2.1 From c4f56a88029c1fe73bf6efb062b5f77a65282fed Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Thu, 5 Apr 2018 22:02:13 -0500 Subject: Increase test suite around deploy tokens behavior Also, fixes broken specs --- spec/models/deploy_token_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 395c97f13a5..1adc049ca58 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -70,8 +70,27 @@ describe DeployToken do end describe '#username' do - it 'returns Ghost username' do + it 'returns a harcoded username' do expect(deploy_token.username).to eq("gitlab+deploy-token-#{deploy_token.id}") end end + + describe '#has_access_to?' do + let(:project) { create(:project) } + + subject(:deploy_token) { create(:deploy_token, projects: [project]) } + + context 'when the deploy token has access to the project' do + it 'should return true' do + expect(deploy_token.has_access_to?(project)).to be_truthy + end + end + + context 'when the deploy token does not have access to the project' do + it 'should return false' do + another_project = create(:project) + expect(deploy_token.has_access_to?(another_project)).to be_falsy + end + end + end end -- cgit v1.2.1 From 29913816309c6f6387b20c8702bcc8e90ef3a984 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Fri, 6 Apr 2018 09:30:21 -0500 Subject: Addresses database comments - Adds a default on expires_at datetime - Modifies deploy tokens views to handle default expires at value - Use datetime_with_timezone where possible - Remove unused scopes --- spec/models/project_deploy_token_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_deploy_token_spec.rb b/spec/models/project_deploy_token_spec.rb index ccaed23f11a..9e2e40c2e8f 100644 --- a/spec/models/project_deploy_token_spec.rb +++ b/spec/models/project_deploy_token_spec.rb @@ -7,7 +7,6 @@ RSpec.describe ProjectDeployToken, type: :model do it { is_expected.to belong_to :project } it { is_expected.to belong_to :deploy_token } - it { is_expected.to accept_nested_attributes_for :deploy_token } it { is_expected.to validate_presence_of :deploy_token } it { is_expected.to validate_presence_of :project } -- cgit v1.2.1 From 5bc58bac2678aed9c8b2318f9f4d4825baa2b110 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Fri, 6 Apr 2018 14:48:17 -0500 Subject: Handle limit for datetime attributes on MySQL The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. A Forever lib class was included to handle future dates for PostgreSQL and MySQL, also changes were made to DeployToken to enforce Forever.date Also removes extra conditional from JwtController --- spec/models/deploy_token_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 1adc049ca58..5a15c23def4 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -93,4 +93,42 @@ describe DeployToken do end end end + + describe '#expires_at' do + context 'when using Forever.date' do + let(:deploy_token) { create(:deploy_token, expires_at: nil) } + + it 'should return nil' do + expect(deploy_token.expires_at).to be_nil + end + end + + context 'when using a personalized date' do + let(:expires_at) { Date.today + 5.months } + let(:deploy_token) { create(:deploy_token, expires_at: expires_at) } + + it 'should return the personalized date' do + expect(deploy_token.expires_at).to eq(expires_at) + end + end + end + + describe '#expires_at=' do + context 'when passing nil' do + let(:deploy_token) { create(:deploy_token, expires_at: nil) } + + it 'should assign Forever.date' do + expect(deploy_token.read_attribute(:expires_at)).to eq(Forever.date) + end + end + + context 'when passign a value' do + let(:expires_at) { Date.today + 5.months } + let(:deploy_token) { create(:deploy_token, expires_at: expires_at) } + + it 'should respect the value' do + expect(deploy_token.read_attribute(:expires_at)).to eq(expires_at) + end + end + end end -- cgit v1.2.1 From 0e78c2e9c925d180a443d132658691adf18f26a1 Mon Sep 17 00:00:00 2001 From: Dylan Griffith Date: Tue, 27 Mar 2018 16:31:43 +1100 Subject: Allow group owner to enable runners from subgroups (#41981) --- spec/models/user_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 73266c0085f..35db7616efb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1850,6 +1850,21 @@ describe User do it_behaves_like :member end + + context 'with subgroup with different owner for project runner', :nested_groups do + let(:group) { create(:group) } + let(:another_user) { create(:user) } + let(:subgroup) { create(:group, parent: group) } + let(:project) { create(:project, group: subgroup) } + + def add_user(access) + group.add_user(user, access) + group.add_user(another_user, :owner) + subgroup.add_user(another_user, :owner) + end + + it_behaves_like :member + end end describe '#projects_with_reporter_access_limited_to' do -- cgit v1.2.1 From 3e35f65394fad201a9277667772f3ad9c6940d07 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Tue, 10 Apr 2018 07:31:30 +0000 Subject: Verify that deploy token has valid access when pulling container registry image --- spec/models/deploy_token_spec.rb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 5a15c23def4..780b200e837 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -78,19 +78,30 @@ describe DeployToken do describe '#has_access_to?' do let(:project) { create(:project) } - subject(:deploy_token) { create(:deploy_token, projects: [project]) } + subject { deploy_token.has_access_to?(project) } - context 'when the deploy token has access to the project' do - it 'should return true' do - expect(deploy_token.has_access_to?(project)).to be_truthy - end + context 'when deploy token is active and related to project' do + let(:deploy_token) { create(:deploy_token, projects: [project]) } + + it { is_expected.to be_truthy } end - context 'when the deploy token does not have access to the project' do - it 'should return false' do - another_project = create(:project) - expect(deploy_token.has_access_to?(another_project)).to be_falsy - end + context 'when deploy token is active but not related to project' do + let(:deploy_token) { create(:deploy_token) } + + it { is_expected.to be_falsy } + end + + context 'when deploy token is revoked and related to project' do + let(:deploy_token) { create(:deploy_token, :revoked, projects: [project]) } + + it { is_expected.to be_falsy } + end + + context 'when deploy token is revoked and not related to the project' do + let(:deploy_token) { create(:deploy_token, :revoked) } + + it { is_expected.to be_falsy } end end -- cgit v1.2.1