From 07365e518330289149dd2135424c49fad19f401d Mon Sep 17 00:00:00 2001 From: Keith Pope Date: Fri, 5 Aug 2016 10:29:09 +0100 Subject: Add config option to project to allow custom .gitlab-ci.yml location --- spec/models/ci/pipeline_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/models/project_spec.rb | 1 + 2 files changed, 31 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 550a890797e..8d774666d2b 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -403,6 +403,36 @@ describe Ci::Pipeline, models: true do end end + describe 'yaml config file resolution' do + let(:project) { FactoryGirl.build(:project) } + + let(:pipeline) { create(:ci_empty_pipeline, project: project) } + it 'uses custom ci config file path when present' do + allow(project).to receive(:ci_config_file) { 'custom/path' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.gitlab-ci.yml') + end + it 'uses root when custom path is nil' do + allow(project).to receive(:ci_config_file) { nil } + expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') + end + it 'uses root when custom path is empty' do + allow(project).to receive(:ci_config_file) { '' } + expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') + end + it 'allows custom filename' do + allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.yml' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.yml') + end + it 'custom filename must be yml' do + allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.cnf' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.cnf/.gitlab-ci.yml') + end + it 'reports error if the file is not found' do + pipeline.ci_yaml_file + expect(pipeline.yaml_errors).to eq('Failed to load CI config file') + end + end + describe '#execute_hooks' do let!(:build_a) { create_build('a', 0) } let!(:build_b) { create_build('b', 1) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8aadfcb439b..363b5ff1913 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -118,6 +118,7 @@ describe Project, models: true do it { is_expected.to validate_uniqueness_of(:path).scoped_to(:namespace_id) } it { is_expected.to validate_length_of(:path).is_within(0..255) } it { is_expected.to validate_length_of(:description).is_within(0..2000) } + it { is_expected.to validate_length_of(:ci_config_file).is_within(0..255) } it { is_expected.to validate_presence_of(:creator) } it { is_expected.to validate_presence_of(:namespace) } it { is_expected.to validate_presence_of(:repository_storage) } -- cgit v1.2.1 From 07a65da1d96a71474f6997aed95bac6290d81a42 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 16 Jun 2017 22:15:40 +0800 Subject: Generate KUBECONFIG in KubernetesService#predefined_variables --- .../project_services/kubernetes_service_spec.rb | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index 858ad595dbf..f69e273cd7c 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -129,7 +129,7 @@ describe KubernetesService, models: true, caching: true do it "returns the default namespace" do is_expected.to eq(service.send(:default_namespace)) end - + context 'when namespace is specified' do before do service.namespace = 'my-namespace' @@ -201,6 +201,13 @@ describe KubernetesService, models: true, caching: true do end describe '#predefined_variables' do + let(:kubeconfig) do + File.read(expand_fixture_path('config/kubeconfig.yml')) + .gsub('TOKEN', 'token') + .gsub('PEM', 'CA PEM DATA') + .gsub('NAMESPACE', namespace) + end + before do subject.api_url = 'https://kube.domain.com' subject.token = 'token' @@ -208,32 +215,35 @@ describe KubernetesService, models: true, caching: true do subject.project = project end - context 'namespace is provided' do - before do - subject.namespace = 'my-project' - end - + shared_examples 'setting variables' do it 'sets the variables' do expect(subject.predefined_variables).to include( { key: 'KUBE_URL', value: 'https://kube.domain.com', public: true }, { key: 'KUBE_TOKEN', value: 'token', public: false }, - { key: 'KUBE_NAMESPACE', value: 'my-project', public: true }, + { key: 'KUBE_NAMESPACE', value: namespace, public: true }, + { key: 'KUBECONFIG', value: kubeconfig, public: false }, + { key: 'KUBECONFIG_FILE', value: kubeconfig, public: false, file: true }, { key: 'KUBE_CA_PEM', value: 'CA PEM DATA', public: true }, { key: 'KUBE_CA_PEM_FILE', value: 'CA PEM DATA', public: true, file: true } ) end end - context 'no namespace provided' do - it 'sets the variables' do - expect(subject.predefined_variables).to include( - { key: 'KUBE_URL', value: 'https://kube.domain.com', public: true }, - { key: 'KUBE_TOKEN', value: 'token', public: false }, - { key: 'KUBE_CA_PEM', value: 'CA PEM DATA', public: true }, - { key: 'KUBE_CA_PEM_FILE', value: 'CA PEM DATA', public: true, file: true } - ) + context 'namespace is provided' do + let(:namespace) { 'my-project' } + + before do + subject.namespace = namespace end + it_behaves_like 'setting variables' + end + + context 'no namespace provided' do + let(:namespace) { subject.actual_namespace } + + it_behaves_like 'setting variables' + it 'sets the KUBE_NAMESPACE' do kube_namespace = subject.predefined_variables.find { |h| h[:key] == 'KUBE_NAMESPACE' } -- cgit v1.2.1 From 6eaec942e6ae89818ea1ba0da5ff00daea633c41 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 16 Jun 2017 22:26:40 +0800 Subject: Changelog entry, doc, and only pass KUBECONFIG_FILE --- spec/models/project_services/kubernetes_service_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index f69e273cd7c..d4feae231bc 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -221,7 +221,6 @@ describe KubernetesService, models: true, caching: true do { key: 'KUBE_URL', value: 'https://kube.domain.com', public: true }, { key: 'KUBE_TOKEN', value: 'token', public: false }, { key: 'KUBE_NAMESPACE', value: namespace, public: true }, - { key: 'KUBECONFIG', value: kubeconfig, public: false }, { key: 'KUBECONFIG_FILE', value: kubeconfig, public: false, file: true }, { key: 'KUBE_CA_PEM', value: 'CA PEM DATA', public: true }, { key: 'KUBE_CA_PEM_FILE', value: 'CA PEM DATA', public: true, file: true } -- cgit v1.2.1 From e02ca5fdb7f9b9a7e52d0e6edfb3be65860818a5 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Thu, 11 May 2017 20:04:36 +0200 Subject: Updated spec for build to include new ref_slug invariants --- spec/models/ci/build_spec.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 3816422fec6..a54261667bd 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1033,19 +1033,27 @@ describe Ci::Build, :models do end describe '#ref_slug' do + let(:build) { build(:ci_build, ref: "'100%") } + subject { build.ref_slug } + + it { is_expected.not_to start_with('-') } + it { is_expected.not_to end_with('-') } + { - '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' + '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, }.each do |ref, slug| it "transforms #{ref} to #{slug}" do build.ref = ref - expect(build.ref_slug).to eq(slug) + is_expected.to eq(slug) end end end -- cgit v1.2.1 From 6394d560ada1bc8b70bcd338343fe978916f84a4 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Thu, 11 May 2017 20:50:59 +0200 Subject: removed superfluos tests --- spec/models/ci/build_spec.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index a54261667bd..855e55dd489 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1033,12 +1033,6 @@ describe Ci::Build, :models do end describe '#ref_slug' do - let(:build) { build(:ci_build, ref: "'100%") } - subject { build.ref_slug } - - it { is_expected.not_to start_with('-') } - it { is_expected.not_to end_with('-') } - { 'master' => 'master', '1-foo' => '1-foo', @@ -1053,7 +1047,7 @@ describe Ci::Build, :models do it "transforms #{ref} to #{slug}" do build.ref = ref - is_expected.to eq(slug) + expected(build.ref_slug).to eq(slug) end end end -- cgit v1.2.1 From fde8f9d736b058e1688c87ed4d3ac835d1603937 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Thu, 11 May 2017 20:54:41 +0200 Subject: fix typo --- 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 855e55dd489..4bf1f296803 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1047,7 +1047,7 @@ describe Ci::Build, :models do it "transforms #{ref} to #{slug}" do build.ref = ref - expected(build.ref_slug).to eq(slug) + expect(build.ref_slug).to eq(slug) end end end -- cgit v1.2.1 From d60a59b067f7914ddcd7d28300f025cf125b586d Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Thu, 11 May 2017 21:42:39 +0200 Subject: remove trailing comma --- 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 4bf1f296803..7ec06b6d6be 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1042,7 +1042,7 @@ describe Ci::Build, :models do 'a' * 64 => 'a' * 63, 'FOO' => 'foo', '-' + 'a' * 61 + '-' => 'a' * 61, - 'a' * 62 + ' ' => 'a' * 62, + 'a' * 62 + ' ' => 'a' * 62 }.each do |ref, slug| it "transforms #{ref} to #{slug}" do build.ref = ref -- cgit v1.2.1 From c701ea945a9af4d1332357b9274d36fffd98c345 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Sun, 18 Jun 2017 23:49:04 +0200 Subject: added additional test case --- spec/models/ci/build_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 7ec06b6d6be..7033623d413 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1042,6 +1042,7 @@ describe Ci::Build, :models do 'a' * 64 => 'a' * 63, 'FOO' => 'foo', '-' + 'a' * 61 + '-' => 'a' * 61, + '-' + 'a' * 63 + '-' => 'a' * 63, 'a' * 62 + ' ' => 'a' * 62 }.each do |ref, slug| it "transforms #{ref} to #{slug}" do -- cgit v1.2.1 From da737f13a963075ffc952756cfd6da2997d1a348 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Mon, 19 Jun 2017 14:13:46 +0200 Subject: fixed incorrect test case --- 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 7033623d413..523650eb506 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1042,7 +1042,7 @@ describe Ci::Build, :models do 'a' * 64 => 'a' * 63, 'FOO' => 'foo', '-' + 'a' * 61 + '-' => 'a' * 61, - '-' + 'a' * 63 + '-' => 'a' * 63, + '-' + 'a' * 63 => 'a' * 63, 'a' * 62 + ' ' => 'a' * 62 }.each do |ref, slug| it "transforms #{ref} to #{slug}" do -- cgit v1.2.1 From 071603a0a59ff315b1d6b1ee2996b37a37cb3c75 Mon Sep 17 00:00:00 2001 From: Stefan Hanreich Date: Mon, 19 Jun 2017 14:16:41 +0200 Subject: fixed incorrect test case (for real), added another one --- 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 523650eb506..dec105d13ec 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1042,7 +1042,8 @@ describe Ci::Build, :models do 'a' * 64 => 'a' * 63, 'FOO' => 'foo', '-' + 'a' * 61 + '-' => 'a' * 61, - '-' + 'a' * 63 => 'a' * 63, + '-' + 'a' * 62 + '-' => 'a' * 62, + '-' + 'a' * 63 + '-' => 'a' * 62, 'a' * 62 + ' ' => 'a' * 62 }.each do |ref, slug| it "transforms #{ref} to #{slug}" do -- cgit v1.2.1 From 451e25532ff43de8151b71ced8246f709c08bf92 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 20 Jun 2017 21:32:49 +0200 Subject: Make MergeRequest respond to assignee_ids & assignee_ids= To make it simpler to assign users to an Issuable, make MergeRequest support the attribute `assignee_ids`. --- spec/models/merge_request_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/models') diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index a56bc524a98..945189b922b 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -105,6 +105,22 @@ describe MergeRequest, models: true do end end + describe '#assignee_ids' do + it 'returns an array of the assigned user id' do + subject.assignee_id = 123 + + expect(subject.assignee_ids).to eq([123]) + end + end + + describe '#assignee_ids=' do + it 'sets assignee_id to the last id in the array' do + subject.assignee_ids = [123, 456] + + expect(subject.assignee_id).to eq(456) + end + end + describe '#assignee_or_author?' do let(:user) { create(:user) } -- cgit v1.2.1 From d9ad56f3c5a7fc5e682ec96731b0578719934122 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 21 Jun 2017 17:30:12 +0000 Subject: Add environment_scope column to ci_variables table This is merely to make CE and EE more compatible. See the EE merge request at: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2112 --- spec/models/ci/variable_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 83494af24ba..ad3aa660b96 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -5,12 +5,14 @@ describe Ci::Variable, models: true do let(:secret_value) { 'secret' } - it { is_expected.to validate_presence_of(:key) } - it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id) } - it { is_expected.to validate_length_of(:key).is_at_most(255) } - it { is_expected.to allow_value('foo').for(:key) } - it { is_expected.not_to allow_value('foo bar').for(:key) } - it { is_expected.not_to allow_value('foo/bar').for(:key) } + describe 'validations' do + it { is_expected.to validate_presence_of(:key) } + it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope) } + it { is_expected.to validate_length_of(:key).is_at_most(255) } + it { is_expected.to allow_value('foo').for(:key) } + it { is_expected.not_to allow_value('foo bar').for(:key) } + it { is_expected.not_to allow_value('foo/bar').for(:key) } + end describe '.unprotected' do subject { described_class.unprotected } -- cgit v1.2.1 From 0d5e6536e7c18d839b1c1da0807aa90ba5be3e06 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 18:29:14 +0800 Subject: Fix the test and implement missing update --- spec/models/ci/pipeline_spec.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 8fb6759d3ab..fef40874d95 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -744,31 +744,45 @@ describe Ci::Pipeline, models: true do describe 'yaml config file resolution' do let(:project) { FactoryGirl.build(:project) } - let(:pipeline) { create(:ci_empty_pipeline, project: project) } + it 'uses custom ci config file path when present' do allow(project).to receive(:ci_config_file) { 'custom/path' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.gitlab-ci.yml') end + it 'uses root when custom path is nil' do allow(project).to receive(:ci_config_file) { nil } + expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') end + it 'uses root when custom path is empty' do allow(project).to receive(:ci_config_file) { '' } + expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') end + it 'allows custom filename' do allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.yml' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.yml') end + it 'custom filename must be yml' do allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.cnf' } + expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.cnf/.gitlab-ci.yml') end + it 'reports error if the file is not found' do + allow(project).to receive(:ci_config_file) { 'custom' } + pipeline.ci_yaml_file - expect(pipeline.yaml_errors).to eq('Failed to load CI config file') + + expect(pipeline.yaml_errors) + .to eq('Failed to load CI/CD config file at custom/.gitlab-ci.yml') end end -- cgit v1.2.1 From 2c74e73f6f994346192acb2e723b026c2ec55f8b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 29 Jun 2017 22:25:31 +0800 Subject: We no longer test the presence of the key --- spec/models/ci/variable_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 77201c6f419..50f7c029af8 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -7,7 +7,6 @@ describe Ci::Variable, models: true do describe 'validations' do it { is_expected.to include_module(HasVariable) } - it { is_expected.to validate_presence_of(:key) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope) } it { is_expected.to validate_length_of(:key).is_at_most(255) } it { is_expected.to allow_value('foo').for(:key) } -- cgit v1.2.1 From 2446252cfd1f5a7d7329099e8d6371fcffa99971 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 29 Jun 2017 18:53:32 -0300 Subject: Expires full_path cache after project is renamed --- spec/models/concerns/routable_spec.rb | 12 ++++++++++++ spec/models/project_spec.rb | 2 ++ 2 files changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 65f05121b40..be82a601b36 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -132,6 +132,18 @@ describe Group, 'Routable' do end end + describe '#expires_full_path_cache' do + context 'with RequestStore active', :request_store do + it 'expires the full_path cache' do + expect(group).to receive(:uncached_full_path).twice.and_call_original + + 3.times { group.full_path } + group.expires_full_path_cache + 3.times { group.full_path } + end + end + end + describe '#full_name' do let(:group) { create(:group) } let(:nested_group) { create(:group, parent: group) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1390848ff4a..6ff4ec3d417 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1216,6 +1216,8 @@ describe Project, models: true do expect(project).to receive(:expire_caches_before_rename) + expect(project).to receive(:expires_full_path_cache) + project.rename_repo end -- cgit v1.2.1 From 17ba052f5c9d7c390b350469d15ffc674a943b07 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 30 Jun 2017 15:23:46 +0800 Subject: Update wordings, allow only full path, add tests --- spec/models/ci/pipeline_spec.rb | 26 +++++++------------------- spec/models/project_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 5ed02031708..8d4d87def5e 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -748,47 +748,35 @@ describe Ci::Pipeline, models: true do end end - describe 'yaml config file resolution' do - let(:project) { FactoryGirl.build(:project) } + describe '#ci_yaml_file_path' do + let(:project) { create(:empty_project) } let(:pipeline) { create(:ci_empty_pipeline, project: project) } - it 'uses custom ci config file path when present' do + it 'returns the path from project' do allow(project).to receive(:ci_config_file) { 'custom/path' } - expect(pipeline.ci_yaml_file_path).to eq('custom/path/.gitlab-ci.yml') + expect(pipeline.ci_yaml_file_path).to eq('custom/path') end - it 'uses root when custom path is nil' do + it 'returns default when custom path is nil' do allow(project).to receive(:ci_config_file) { nil } expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') end - it 'uses root when custom path is empty' do + it 'returns default when custom path is empty' do allow(project).to receive(:ci_config_file) { '' } expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') end - it 'allows custom filename' do - allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.yml' } - - expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.yml') - end - - it 'custom filename must be yml' do - allow(project).to receive(:ci_config_file) { 'custom/path/.my-config.cnf' } - - expect(pipeline.ci_yaml_file_path).to eq('custom/path/.my-config.cnf/.gitlab-ci.yml') - end - it 'reports error if the file is not found' do allow(project).to receive(:ci_config_file) { 'custom' } pipeline.ci_yaml_file expect(pipeline.yaml_errors) - .to eq('Failed to load CI/CD config file at custom/.gitlab-ci.yml') + .to eq('Failed to load CI/CD config file at custom') end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index fb39357659c..349f9c3d7eb 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -144,6 +144,8 @@ describe Project, models: true do it { is_expected.to validate_length_of(:description).is_at_most(2000) } it { is_expected.to validate_length_of(:ci_config_file).is_at_most(255) } + it { is_expected.to allow_value('').for(:ci_config_file) } + it { is_expected.not_to allow_value('test/../foo').for(:ci_config_file) } it { is_expected.to validate_presence_of(:creator) } @@ -1491,6 +1493,28 @@ describe Project, models: true do end end + describe '#ci_config_file=' do + let(:project) { create(:empty_project) } + + it 'sets nil' do + project.update!(ci_config_file: nil) + + expect(project.ci_config_file).to be_nil + end + + it 'sets a string' do + project.update!(ci_config_file: 'foo/.gitlab_ci.yml') + + expect(project.ci_config_file).to eq('foo/.gitlab_ci.yml') + end + + it 'sets a string but remove all leading slashes' do + project.update!(ci_config_file: '///foo//.gitlab_ci.yml') + + expect(project.ci_config_file).to eq('foo//.gitlab_ci.yml') + end + end + describe 'Project import job' do let(:project) { create(:empty_project, import_url: generate(:url)) } -- cgit v1.2.1 From 057c3c4e31df9dc8b1866b185dbf6d89e2751e3c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 30 Jun 2017 16:14:48 +0800 Subject: Introduce CI_CONFIG_PATH --- spec/models/ci/build_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 488697f74eb..e5fd549f0d7 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1179,6 +1179,7 @@ describe Ci::Build, :models do { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true }, { key: 'CI_PROJECT_URL', value: project.web_url, public: true }, { key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true }, + { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, 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 } @@ -1469,6 +1470,16 @@ describe Ci::Build, :models do it { is_expected.to include(deployment_variable) } end + context 'when project has custom CI config path' do + let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: 'custom', public: true } } + + before do + project.update(ci_config_file: 'custom') + end + + it { is_expected.to include(ci_config_path) } + end + context 'returns variables in valid order' do let(:build_pre_var) { { key: 'build', value: 'value' } } let(:project_pre_var) { { key: 'project', value: 'value' } } -- cgit v1.2.1 From 7648f113814a78ffde802172197ba2b0074ec753 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 28 Jun 2017 17:33:48 +0200 Subject: Remove unnecessary contexts --- spec/models/environment_spec.rb | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'spec/models') diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index b0635c6a90a..0a2cd8c2957 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -120,28 +120,17 @@ describe Environment, models: true do let(:head_commit) { project.commit } let(:commit) { project.commit.parent } - context 'Gitaly find_ref_name feature disabled' do - it 'returns deployment id for the environment' do - expect(environment.first_deployment_for(commit)).to eq deployment1 - end + it 'returns deployment id for the environment' do + expect(environment.first_deployment_for(commit)).to eq deployment1 + end - it 'return nil when no deployment is found' do - expect(environment.first_deployment_for(head_commit)).to eq nil - end + it 'return nil when no deployment is found' do + expect(environment.first_deployment_for(head_commit)).to eq nil end - # TODO: Uncomment when feature is reenabled - # context 'Gitaly find_ref_name feature enabled' do - # before do - # allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:find_ref_name).and_return(true) - # end - # - # it 'calls GitalyClient' do - # expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:find_ref_name) - # - # environment.first_deployment_for(commit) - # end - # end + it 'returns a UTF-8 ref' do + expect(environment.first_deployment_for(commit).ref).to be_utf8 + end end describe '#environment_type' do -- cgit v1.2.1 From 9da3076944146444cb864d5db066a766c76b1935 Mon Sep 17 00:00:00 2001 From: Adam Niedzielski Date: Fri, 30 Jun 2017 14:47:53 +0200 Subject: Improve support for external issue references --- spec/models/project_services/jira_service_spec.rb | 6 +++--- spec/models/project_services/redmine_service_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index c86f56c55eb..4a1de76f099 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -64,12 +64,12 @@ describe JiraService, models: true do end end - describe '#reference_pattern' do + describe '.reference_pattern' do it_behaves_like 'allows project key on reference pattern' it 'does not allow # on the code' do - expect(subject.reference_pattern.match('#123')).to be_nil - expect(subject.reference_pattern.match('1#23#12')).to be_nil + expect(described_class.reference_pattern.match('#123')).to be_nil + expect(described_class.reference_pattern.match('1#23#12')).to be_nil end end diff --git a/spec/models/project_services/redmine_service_spec.rb b/spec/models/project_services/redmine_service_spec.rb index 6631d9040b1..441b3f896ca 100644 --- a/spec/models/project_services/redmine_service_spec.rb +++ b/spec/models/project_services/redmine_service_spec.rb @@ -31,11 +31,11 @@ describe RedmineService, models: true do end end - describe '#reference_pattern' do + describe '.reference_pattern' do it_behaves_like 'allows project key on reference pattern' it 'does allow # on the reference' do - expect(subject.reference_pattern.match('#123')[:issue]).to eq('123') + expect(described_class.reference_pattern.match('#123')[:issue]).to eq('123') end end end -- cgit v1.2.1 From 9c8075c4b95f090fc6f00c897f6bf097d29ee8bf Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 29 Jun 2017 23:26:23 -0700 Subject: Make Project#ensure_repository force create a repo In Geo, Project#ensure_repository is used to make sure that a Git repo is available to be fetched on a secondary. If a project were a fork, this directory would never be created. Closes gitlab-org/gitlab-ee#2800 --- spec/models/project_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1390848ff4a..0eeaf68a02a 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1357,6 +1357,19 @@ describe Project, models: true do project.ensure_repository end + + it 'creates the repository if it is a fork' do + expect(project).to receive(:forked?).and_return(true) + + allow(project).to receive(:repository_exists?) + .and_return(false) + + expect(shell).to receive(:add_repository) + .with(project.repository_storage_path, project.path_with_namespace) + .and_return(true) + + project.ensure_repository + end end describe '#user_can_push_to_empty_repo?' do -- cgit v1.2.1 From 1b0c6ffd512d0bee24964936da02e1b10d6a5a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 29 Jun 2017 18:03:17 +0200 Subject: Disable RSpec/BeforeAfterAll and enable RSpec/ImplicitExpect cops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/project_group_link_spec.rb | 12 ++++++------ spec/models/project_services/external_wiki_service_spec.rb | 4 ++-- spec/models/project_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_group_link_spec.rb b/spec/models/project_group_link_spec.rb index 4161b9158b1..d68d8b719cd 100644 --- a/spec/models/project_group_link_spec.rb +++ b/spec/models/project_group_link_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe ProjectGroupLink do describe "Associations" do - it { should belong_to(:group) } - it { should belong_to(:project) } + it { is_expected.to belong_to(:group) } + it { is_expected.to belong_to(:project) } end describe "Validation" do @@ -12,10 +12,10 @@ describe ProjectGroupLink do let(:project) { create(:project, group: group) } let!(:project_group_link) { create(:project_group_link, project: project) } - it { should validate_presence_of(:project_id) } - it { should validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) } - it { should validate_presence_of(:group) } - it { should validate_presence_of(:group_access) } + it { is_expected.to validate_presence_of(:project_id) } + it { is_expected.to validate_uniqueness_of(:group_id).scoped_to(:project_id).with_message(/already shared/) } + it { is_expected.to validate_presence_of(:group) } + it { is_expected.to validate_presence_of(:group_access) } it "doesn't allow a project to be shared with the group it is in" do project_group_link.group = group diff --git a/spec/models/project_services/external_wiki_service_spec.rb b/spec/models/project_services/external_wiki_service_spec.rb index 291fc645a1c..ef10df9e092 100644 --- a/spec/models/project_services/external_wiki_service_spec.rb +++ b/spec/models/project_services/external_wiki_service_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe ExternalWikiService, models: true do include ExternalWikiHelper describe "Associations" do - it { should belong_to :project } - it { should have_one :service_hook } + it { is_expected.to belong_to :project } + it { is_expected.to have_one :service_hook } end describe 'Validations' do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1390848ff4a..f9b702c54aa 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -823,13 +823,13 @@ describe Project, models: true do let(:avatar_path) { "/#{project.full_path}/avatar" } - it { should eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" } + it { is_expected.to eq "http://#{Gitlab.config.gitlab.host}#{avatar_path}" } end context 'when git repo is empty' do let(:project) { create(:empty_project) } - it { should eq nil } + it { is_expected.to eq nil } end end -- cgit v1.2.1 From ea9dd29a76477e73104764d2e7f937bb2ccce8c0 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 3 Jul 2017 12:38:01 -0300 Subject: Reset @full_path to nil when cache expires --- spec/models/concerns/routable_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index be82a601b36..36aedd2f701 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -135,11 +135,12 @@ describe Group, 'Routable' do describe '#expires_full_path_cache' do context 'with RequestStore active', :request_store do it 'expires the full_path cache' do - expect(group).to receive(:uncached_full_path).twice.and_call_original + expect(group.full_path).to eq('foo') - 3.times { group.full_path } + group.route.update(path: 'bar', name: 'bar') group.expires_full_path_cache - 3.times { group.full_path } + + expect(group.full_path).to eq('bar') end end end -- cgit v1.2.1 From 73f5b02b4fa275bbd3a5880144114ea69f594307 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 3 Jul 2017 14:37:20 -0300 Subject: Change the force flag to a keyword argument --- spec/models/project_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0eeaf68a02a..1a56f6f5c59 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1344,7 +1344,7 @@ describe Project, models: true do .with(project.repository_storage_path, project.path_with_namespace) .and_return(true) - expect(project).to receive(:create_repository) + expect(project).to receive(:create_repository).with(force: true) project.ensure_repository end -- cgit v1.2.1 From 63bf2457e40ffd465d9a5aeee9b26b1c82432f9d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:08:30 +0800 Subject: Follow feedback on the merge request --- spec/models/ci/pipeline_spec.rb | 25 ++----------------------- spec/models/project_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 8d4d87def5e..e36e9082036 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -748,30 +748,9 @@ describe Ci::Pipeline, models: true do end end - describe '#ci_yaml_file_path' do - let(:project) { create(:empty_project) } - let(:pipeline) { create(:ci_empty_pipeline, project: project) } - - it 'returns the path from project' do - allow(project).to receive(:ci_config_file) { 'custom/path' } - - expect(pipeline.ci_yaml_file_path).to eq('custom/path') - end - - it 'returns default when custom path is nil' do - allow(project).to receive(:ci_config_file) { nil } - - expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') - end - - it 'returns default when custom path is empty' do - allow(project).to receive(:ci_config_file) { '' } - - expect(pipeline.ci_yaml_file_path).to eq('.gitlab-ci.yml') - end - + describe '#ci_yaml_file' do it 'reports error if the file is not found' do - allow(project).to receive(:ci_config_file) { 'custom' } + allow(pipeline.project).to receive(:ci_config_file) { 'custom' } pipeline.ci_yaml_file diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 349f9c3d7eb..f06f7d6b54b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1493,6 +1493,30 @@ describe Project, models: true do end end + describe '#ci_config_file_for_pipeline' do + let(:project) { create(:empty_project) } + + subject { project.ci_config_file_for_pipeline } + + it 'returns the path from project' do + allow(project).to receive(:ci_config_file) { 'custom/path' } + + is_expected.to eq('custom/path') + end + + it 'returns default when custom path is nil' do + allow(project).to receive(:ci_config_file) { nil } + + is_expected.to eq('.gitlab-ci.yml') + end + + it 'returns default when custom path is empty' do + allow(project).to receive(:ci_config_file) { '' } + + is_expected.to eq('.gitlab-ci.yml') + end + end + describe '#ci_config_file=' do let(:project) { create(:empty_project) } -- cgit v1.2.1 From 4d9c2bad369d510877dff719d94a5f98b1ee4dfe Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:22:19 +0800 Subject: Fix config path --- 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 e5fd549f0d7..1553d6d3a9a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1179,7 +1179,7 @@ describe Ci::Build, :models do { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true }, { key: 'CI_PROJECT_URL', value: project.web_url, public: true }, { key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true }, - { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, public: true }, + { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, 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 } -- cgit v1.2.1 From 84e37683cb838337f84df387ec8e8251e167fa20 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:35:06 +0800 Subject: Make sure we remove null characters --- 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 f06f7d6b54b..4ef768123bd 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1532,8 +1532,8 @@ describe Project, models: true do expect(project.ci_config_file).to eq('foo/.gitlab_ci.yml') end - it 'sets a string but remove all leading slashes' do - project.update!(ci_config_file: '///foo//.gitlab_ci.yml') + it 'sets a string but remove all leading slashes and null characters' do + project.update!(ci_config_file: "///f\0oo/\0/.gitlab_ci.yml") expect(project.ci_config_file).to eq('foo//.gitlab_ci.yml') end -- cgit v1.2.1 From 1501a4f578fa947af66a981fd56885be8467d5b5 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Tue, 4 Jul 2017 11:48:25 +0100 Subject: Clean up the ForkedProjectLink specs --- spec/models/forked_project_link_spec.rb | 64 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'spec/models') diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 6e8d43f988c..4fd250bd4c6 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -2,53 +2,59 @@ require 'spec_helper' describe ForkedProjectLink, "add link on fork" do let(:project_from) { create(:project, :repository) } + let(:project_to) { fork_project(project_from, user) } let(:user) { create(:user) } let(:namespace) { user.namespace } before do - create(:project_member, :reporter, user: user, project: project_from) - @project_to = fork_project(project_from, user) + project_from.add_reporter(user) + end + + it 'project_from knows its forks' do + _ = project_to + + expect(project_from.forks.count).to eq(1) end it "project_to knows it is forked" do - expect(@project_to.forked?).to be_truthy + expect(project_to.forked?).to be_truthy end it "project knows who it is forked from" do - expect(@project_to.forked_from_project).to eq(project_from) + expect(project_to.forked_from_project).to eq(project_from) end -end -describe '#forked?' do - let(:forked_project_link) { build(:forked_project_link) } - let(:project_from) { create(:project, :repository) } - let(:project_to) { create(:project, forked_project_link: forked_project_link) } + describe '#forked?' do + let(:project_to) { create(:project, forked_project_link: forked_project_link) } + let(:forked_project_link) { build(:forked_project_link) } - before :each do - forked_project_link.forked_from_project = project_from - forked_project_link.forked_to_project = project_to - forked_project_link.save! - end + before do + forked_project_link.forked_from_project = project_from + forked_project_link.forked_to_project = project_to + forked_project_link.save! + end - it "project_to knows it is forked" do - expect(project_to.forked?).to be_truthy - end + it "project_to knows it is forked" do + expect(project_to.forked?).to be_truthy + end - it "project_from is not forked" do - expect(project_from.forked?).to be_falsey - end + it "project_from is not forked" do + expect(project_from.forked?).to be_falsey + end - it "project_to.destroy destroys fork_link" do - expect(forked_project_link).to receive(:destroy) - project_to.destroy + it "project_to.destroy destroys fork_link" do + expect(forked_project_link).to receive(:destroy) + + project_to.destroy + end end -end -def fork_project(from_project, user) - shell = double('gitlab_shell', fork_repository: true) + def fork_project(from_project, user) + service = Projects::ForkService.new(from_project, user) + shell = double('gitlab_shell', fork_repository: true) - service = Projects::ForkService.new(from_project, user) - allow(service).to receive(:gitlab_shell).and_return(shell) + allow(service).to receive(:gitlab_shell).and_return(shell) - service.execute + service.execute + end end -- cgit v1.2.1 From cb1f3423876f84861facc4c3631eeb4b453ceee6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 3 Jul 2017 11:31:37 +0100 Subject: Don't resolve fork relationships for projects pending delete --- spec/models/forked_project_link_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/models') diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 4fd250bd4c6..5c13cf584f9 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -24,6 +24,22 @@ describe ForkedProjectLink, "add link on fork" do expect(project_to.forked_from_project).to eq(project_from) end + context 'project_to is pending_delete' do + before do + project_to.update!(pending_delete: true) + end + + it { expect(project_from.forks.count).to eq(0) } + end + + context 'project_from is pending_delete' do + before do + project_from.update!(pending_delete: true) + end + + it { expect(project_to.forked_from_project).to be_nil } + end + describe '#forked?' do let(:project_to) { create(:project, forked_project_link: forked_project_link) } let(:forked_project_link) { build(:forked_project_link) } -- cgit v1.2.1 From 2c78c7f4cdb1fae2650563f80feb294d2b7e5d80 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 4 Jul 2017 17:08:41 +0000 Subject: Revert "Merge branch 'revert-12499' into 'master'" This reverts merge request !12557 --- spec/models/concerns/sortable_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/models/concerns/sortable_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb new file mode 100644 index 00000000000..d1e17c4f684 --- /dev/null +++ b/spec/models/concerns/sortable_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Sortable do + let(:relation) { Issue.all } + + describe '#where' do + it 'orders by id, descending' do + order_node = relation.where(iid: 1).order_values.first + expect(order_node).to be_a(Arel::Nodes::Descending) + expect(order_node.expr.name).to eq(:id) + end + end + + describe '#find_by' do + it 'does not order' do + expect(relation).to receive(:unscope).with(:order).and_call_original + + relation.find_by(iid: 1) + end + end +end -- cgit v1.2.1 From d278da48f837292491aaf81649afef1da3a1eb09 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 21 Jun 2017 18:25:01 +0900 Subject: pipeline_schedule_variables model/db --- spec/models/ci/build_spec.rb | 16 ++++++++++++++++ spec/models/ci/pipeline_schedule_spec.rb | 1 + spec/models/ci/pipeline_schedule_variable_spec.rb | 8 ++++++++ 3 files changed, 25 insertions(+) create mode 100644 spec/models/ci/pipeline_schedule_variable_spec.rb (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 7de5e2e3920..e66ea976323 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1373,6 +1373,22 @@ describe Ci::Build, :models do it { is_expected.to include(predefined_trigger_variable) } end + context 'when build was triggered by scheduled pipeline' do + let(:secret_variable) do + { key: 'SECRET_KEY', value: 'secret_value', public: false } + end + + let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + + before do + pipeline_schedule.pipelines << pipeline + create(:ci_pipeline_schedule_variable, + secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule)) + end + + it { is_expected.to include(secret_variable) } + end + context 'when yaml_variables are undefined' do before do build.yaml_variables = nil diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 56817baf79d..95c7112c90e 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -5,6 +5,7 @@ describe Ci::PipelineSchedule, models: true do it { is_expected.to belong_to(:owner) } it { is_expected.to have_many(:pipelines) } + it { is_expected.to have_many(:variables) } it { is_expected.to respond_to(:ref) } it { is_expected.to respond_to(:cron) } diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb new file mode 100644 index 00000000000..eb67792bf2f --- /dev/null +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +describe Ci::PipelineScheduleVariable, models: true do + subject { build(:ci_pipeline_schedule_variable) } + + it { is_expected.to be_kind_of(HasVariable) } + it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } +end -- cgit v1.2.1 From 51730b3a15ce03bd5de83a978647059ad182378c Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 16:55:27 +0900 Subject: zj nice catches --- spec/models/ci/build_spec.rb | 14 ++++++-------- spec/models/ci/pipeline_schedule_spec.rb | 11 +++++++++++ spec/models/ci/pipeline_schedule_variable_spec.rb | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index e66ea976323..4ed2635fb07 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1373,20 +1373,18 @@ describe Ci::Build, :models do it { is_expected.to include(predefined_trigger_variable) } end - context 'when build was triggered by scheduled pipeline' do - let(:secret_variable) do - { key: 'SECRET_KEY', value: 'secret_value', public: false } - end - + context 'when a job was triggered by a pipeline schedule' do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + let!(:pipeline_schedule_variable) do + create(:ci_pipeline_schedule_variable, key: 'SCHEDULE_VARIABLE_KEY', + pipeline_schedule: pipeline_schedule) + end before do pipeline_schedule.pipelines << pipeline - create(:ci_pipeline_schedule_variable, - secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule)) end - it { is_expected.to include(secret_variable) } + it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } end context 'when yaml_variables are undefined' do diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 95c7112c90e..2f826a91417 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -118,4 +118,15 @@ describe Ci::PipelineSchedule, models: true do end end end + + describe '#job_variables' do + let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } + let!(:pipeline_schedule_variables) do + create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule) + end + + subject { pipeline_schedule.job_variables } + + it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) } + end end diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb index eb67792bf2f..9c0b0153e03 100644 --- a/spec/models/ci/pipeline_schedule_variable_spec.rb +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -3,6 +3,6 @@ require 'spec_helper' describe Ci::PipelineScheduleVariable, models: true do subject { build(:ci_pipeline_schedule_variable) } - it { is_expected.to be_kind_of(HasVariable) } + it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } end -- cgit v1.2.1 From b6f41544d8a9ca4b13045b8f9d063367be17404f Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Sat, 1 Jul 2017 19:23:41 +0900 Subject: Fix spec. Add PipelineScheduleVariable for import_export --- spec/models/ci/build_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 4ed2635fb07..66784607835 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1375,8 +1375,10 @@ describe Ci::Build, :models do context 'when a job was triggered by a pipeline schedule' do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + let!(:pipeline_schedule_variable) do - create(:ci_pipeline_schedule_variable, key: 'SCHEDULE_VARIABLE_KEY', + create(:ci_pipeline_schedule_variable, + key: 'SCHEDULE_VARIABLE_KEY', pipeline_schedule: pipeline_schedule) end -- cgit v1.2.1 From 17f34e5a74cdfbf37e45b3db603cffb8035c8db4 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 3 Jul 2017 22:13:10 +0900 Subject: Fix spec --- spec/models/ci/build_spec.rb | 1 + spec/models/ci/pipeline_schedule_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 66784607835..5271b6660c8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1383,6 +1383,7 @@ describe Ci::Build, :models do end before do + pipeline_schedule.reload pipeline_schedule.pipelines << pipeline end diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 2f826a91417..34722ef1a69 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -127,6 +127,10 @@ describe Ci::PipelineSchedule, models: true do subject { pipeline_schedule.job_variables } + before do + pipeline_schedule.reload + end + it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) } end end -- cgit v1.2.1 From bbbd5521d2d177561efd6f8171394abef6ec90ff Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 4 Jul 2017 01:51:21 +0900 Subject: Improve spec --- spec/models/ci/build_spec.rb | 2 +- spec/models/ci/pipeline_schedule_spec.rb | 1 + 2 files 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 5271b6660c8..211356f415a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1383,8 +1383,8 @@ describe Ci::Build, :models do end before do - pipeline_schedule.reload pipeline_schedule.pipelines << pipeline + pipeline_schedule.reload end it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 34722ef1a69..54177bee5ce 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -121,6 +121,7 @@ describe Ci::PipelineSchedule, models: true do describe '#job_variables' do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } + let!(:pipeline_schedule_variables) do create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule) end -- cgit v1.2.1 From 06f01073696199da980a2101bc3eb77922131a8a Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 21 Jun 2017 18:25:01 +0900 Subject: pipeline_schedule_variables model/db --- spec/models/ci/build_spec.rb | 35 ++++++++++------------- spec/models/ci/pipeline_schedule_variable_spec.rb | 2 +- 2 files changed, 16 insertions(+), 21 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 211356f415a..c6a7791d64b 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -998,17 +998,13 @@ describe Ci::Build, :models do 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 + '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' }.each do |ref, slug| it "transforms #{ref} to #{slug}" do build.ref = ref @@ -1373,21 +1369,20 @@ describe Ci::Build, :models do it { is_expected.to include(predefined_trigger_variable) } end - context 'when a job was triggered by a pipeline schedule' do - let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } - - let!(:pipeline_schedule_variable) do - create(:ci_pipeline_schedule_variable, - key: 'SCHEDULE_VARIABLE_KEY', - pipeline_schedule: pipeline_schedule) + context 'when build was triggered by scheduled pipeline' do + let(:secret_variable) do + { key: 'SECRET_KEY', value: 'secret_value', public: false } end + let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + before do pipeline_schedule.pipelines << pipeline - pipeline_schedule.reload + create(:ci_pipeline_schedule_variable, + secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule)) end - it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } + it { is_expected.to include(secret_variable) } end context 'when yaml_variables are undefined' do diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb index 9c0b0153e03..eb67792bf2f 100644 --- a/spec/models/ci/pipeline_schedule_variable_spec.rb +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -3,6 +3,6 @@ require 'spec_helper' describe Ci::PipelineScheduleVariable, models: true do subject { build(:ci_pipeline_schedule_variable) } - it { is_expected.to include_module(HasVariable) } + it { is_expected.to be_kind_of(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } end -- cgit v1.2.1 From d65d66e08bf62491fc4a3da322d36dfb9014eaac Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 27 Jun 2017 16:55:27 +0900 Subject: zj nice catches --- spec/models/ci/build_spec.rb | 14 ++++++-------- spec/models/ci/pipeline_schedule_spec.rb | 5 ----- spec/models/ci/pipeline_schedule_variable_spec.rb | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index c6a7791d64b..8750cbcb13c 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1369,20 +1369,18 @@ describe Ci::Build, :models do it { is_expected.to include(predefined_trigger_variable) } end - context 'when build was triggered by scheduled pipeline' do - let(:secret_variable) do - { key: 'SECRET_KEY', value: 'secret_value', public: false } - end - + context 'when a job was triggered by a pipeline schedule' do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + let!(:pipeline_schedule_variable) do + create(:ci_pipeline_schedule_variable, key: 'SCHEDULE_VARIABLE_KEY', + pipeline_schedule: pipeline_schedule) + end before do pipeline_schedule.pipelines << pipeline - create(:ci_pipeline_schedule_variable, - secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule)) end - it { is_expected.to include(secret_variable) } + it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } end context 'when yaml_variables are undefined' do diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 54177bee5ce..2f826a91417 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -121,17 +121,12 @@ describe Ci::PipelineSchedule, models: true do describe '#job_variables' do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } - let!(:pipeline_schedule_variables) do create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule) end subject { pipeline_schedule.job_variables } - before do - pipeline_schedule.reload - end - it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) } end end diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb index eb67792bf2f..9c0b0153e03 100644 --- a/spec/models/ci/pipeline_schedule_variable_spec.rb +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -3,6 +3,6 @@ require 'spec_helper' describe Ci::PipelineScheduleVariable, models: true do subject { build(:ci_pipeline_schedule_variable) } - it { is_expected.to be_kind_of(HasVariable) } + it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } end -- cgit v1.2.1 From 324cfe0f9be8bd8eeb00736a670d3aaf4b5dedb9 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Sat, 1 Jul 2017 19:23:41 +0900 Subject: Fix spec. Add PipelineScheduleVariable for import_export --- spec/models/ci/build_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 8750cbcb13c..a4f29ce462f 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1371,8 +1371,10 @@ describe Ci::Build, :models do context 'when a job was triggered by a pipeline schedule' do let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } + let!(:pipeline_schedule_variable) do - create(:ci_pipeline_schedule_variable, key: 'SCHEDULE_VARIABLE_KEY', + create(:ci_pipeline_schedule_variable, + key: 'SCHEDULE_VARIABLE_KEY', pipeline_schedule: pipeline_schedule) end -- cgit v1.2.1 From 3acc91866bec2004f4dae542dae0d66a2921b4da Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 3 Jul 2017 22:13:10 +0900 Subject: Fix spec --- spec/models/ci/build_spec.rb | 1 + spec/models/ci/pipeline_schedule_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index a4f29ce462f..cb1a4cee467 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1379,6 +1379,7 @@ describe Ci::Build, :models do end before do + pipeline_schedule.reload pipeline_schedule.pipelines << pipeline end diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 2f826a91417..34722ef1a69 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -127,6 +127,10 @@ describe Ci::PipelineSchedule, models: true do subject { pipeline_schedule.job_variables } + before do + pipeline_schedule.reload + end + it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) } end end -- cgit v1.2.1 From 2f70f3fa35f4bce54350e87d75add4823d4b3ebe Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 4 Jul 2017 01:51:21 +0900 Subject: Improve spec --- spec/models/ci/build_spec.rb | 2 +- spec/models/ci/pipeline_schedule_spec.rb | 1 + 2 files 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 cb1a4cee467..42b86a77f17 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1379,8 +1379,8 @@ describe Ci::Build, :models do end before do - pipeline_schedule.reload pipeline_schedule.pipelines << pipeline + pipeline_schedule.reload end it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 34722ef1a69..54177bee5ce 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -121,6 +121,7 @@ describe Ci::PipelineSchedule, models: true do describe '#job_variables' do let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } + let!(:pipeline_schedule_variables) do create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule) end -- cgit v1.2.1 From 1bfa818a1f3ac9c40a8d4fc727cfe848efcef962 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 4 Jul 2017 17:45:07 +0900 Subject: zj nice catchies 3 --- spec/models/ci/pipeline_schedule_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 54177bee5ce..4c3aa986bf9 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -120,7 +120,7 @@ describe Ci::PipelineSchedule, models: true do end describe '#job_variables' do - let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) } + let!(:pipeline_schedule) { create(:ci_pipeline_schedule) } let!(:pipeline_schedule_variables) do create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule) -- cgit v1.2.1 From dbd0111390fd24da8782cadcd52471ad002e12da Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 5 Jul 2017 21:00:22 +0900 Subject: Revert unnecesarry changes --- spec/models/ci/build_spec.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 42b86a77f17..211356f415a 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -998,13 +998,17 @@ describe Ci::Build, :models do 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' + '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 -- cgit v1.2.1 From 9f7e5e45df9b7d99b97e40d1c08250925a408875 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Jul 2017 20:04:53 +0800 Subject: Add back Pipeline#ci_yaml_file_path due to all the troubles --- spec/models/ci/build_spec.rb | 2 +- spec/models/ci/pipeline_spec.rb | 22 ++++++++++++++++++++++ spec/models/project_spec.rb | 24 ------------------------ 3 files changed, 23 insertions(+), 25 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 1553d6d3a9a..e5fd549f0d7 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1179,7 +1179,7 @@ describe Ci::Build, :models do { key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true }, { key: 'CI_PROJECT_URL', value: project.web_url, public: true }, { key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true }, - { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true }, + { key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, 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 } diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index e36e9082036..a24b1e6c818 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -748,6 +748,28 @@ describe Ci::Pipeline, models: true do end end + describe '#ci_yaml_file_path' do + subject { pipeline.ci_yaml_file_path } + + it 'returns the path from project' do + allow(pipeline.project).to receive(:ci_config_file) { 'custom/path' } + + is_expected.to eq('custom/path') + end + + it 'returns default when custom path is nil' do + allow(pipeline.project).to receive(:ci_config_file) { nil } + + is_expected.to eq('.gitlab-ci.yml') + end + + it 'returns default when custom path is empty' do + allow(pipeline.project).to receive(:ci_config_file) { '' } + + is_expected.to eq('.gitlab-ci.yml') + end + end + describe '#ci_yaml_file' do it 'reports error if the file is not found' do allow(pipeline.project).to receive(:ci_config_file) { 'custom' } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 4ef768123bd..a682fa82bf0 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1493,30 +1493,6 @@ describe Project, models: true do end end - describe '#ci_config_file_for_pipeline' do - let(:project) { create(:empty_project) } - - subject { project.ci_config_file_for_pipeline } - - it 'returns the path from project' do - allow(project).to receive(:ci_config_file) { 'custom/path' } - - is_expected.to eq('custom/path') - end - - it 'returns default when custom path is nil' do - allow(project).to receive(:ci_config_file) { nil } - - is_expected.to eq('.gitlab-ci.yml') - end - - it 'returns default when custom path is empty' do - allow(project).to receive(:ci_config_file) { '' } - - is_expected.to eq('.gitlab-ci.yml') - end - end - describe '#ci_config_file=' do let(:project) { create(:empty_project) } -- cgit v1.2.1 From 9f5ac179d1ca4819006c66ae385ba7153f6c7e4f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Jul 2017 20:11:01 +0800 Subject: Rename ci_config_file to ci_config_path --- spec/models/ci/build_spec.rb | 2 +- spec/models/ci/pipeline_spec.rb | 8 ++++---- spec/models/project_spec.rb | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index e5fd549f0d7..f955d9c81b8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1474,7 +1474,7 @@ describe Ci::Build, :models do let(:ci_config_path) { { key: 'CI_CONFIG_PATH', value: 'custom', public: true } } before do - project.update(ci_config_file: 'custom') + project.update(ci_config_path: 'custom') end it { is_expected.to include(ci_config_path) } diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index a24b1e6c818..ba0696fa210 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -752,19 +752,19 @@ describe Ci::Pipeline, models: true do subject { pipeline.ci_yaml_file_path } it 'returns the path from project' do - allow(pipeline.project).to receive(:ci_config_file) { 'custom/path' } + allow(pipeline.project).to receive(:ci_config_path) { 'custom/path' } is_expected.to eq('custom/path') end it 'returns default when custom path is nil' do - allow(pipeline.project).to receive(:ci_config_file) { nil } + allow(pipeline.project).to receive(:ci_config_path) { nil } is_expected.to eq('.gitlab-ci.yml') end it 'returns default when custom path is empty' do - allow(pipeline.project).to receive(:ci_config_file) { '' } + allow(pipeline.project).to receive(:ci_config_path) { '' } is_expected.to eq('.gitlab-ci.yml') end @@ -772,7 +772,7 @@ describe Ci::Pipeline, models: true do describe '#ci_yaml_file' do it 'reports error if the file is not found' do - allow(pipeline.project).to receive(:ci_config_file) { 'custom' } + allow(pipeline.project).to receive(:ci_config_path) { 'custom' } pipeline.ci_yaml_file diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a682fa82bf0..6197a390da8 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -143,9 +143,9 @@ describe Project, models: true do it { is_expected.to validate_length_of(:description).is_at_most(2000) } - it { is_expected.to validate_length_of(:ci_config_file).is_at_most(255) } - it { is_expected.to allow_value('').for(:ci_config_file) } - it { is_expected.not_to allow_value('test/../foo').for(:ci_config_file) } + it { is_expected.to validate_length_of(:ci_config_path).is_at_most(255) } + it { is_expected.to allow_value('').for(:ci_config_path) } + it { is_expected.not_to allow_value('test/../foo').for(:ci_config_path) } it { is_expected.to validate_presence_of(:creator) } @@ -1493,25 +1493,25 @@ describe Project, models: true do end end - describe '#ci_config_file=' do + describe '#ci_config_path=' do let(:project) { create(:empty_project) } it 'sets nil' do - project.update!(ci_config_file: nil) + project.update!(ci_config_path: nil) - expect(project.ci_config_file).to be_nil + expect(project.ci_config_path).to be_nil end it 'sets a string' do - project.update!(ci_config_file: 'foo/.gitlab_ci.yml') + project.update!(ci_config_path: 'foo/.gitlab_ci.yml') - expect(project.ci_config_file).to eq('foo/.gitlab_ci.yml') + expect(project.ci_config_path).to eq('foo/.gitlab_ci.yml') end it 'sets a string but remove all leading slashes and null characters' do - project.update!(ci_config_file: "///f\0oo/\0/.gitlab_ci.yml") + project.update!(ci_config_path: "///f\0oo/\0/.gitlab_ci.yml") - expect(project.ci_config_file).to eq('foo//.gitlab_ci.yml') + expect(project.ci_config_path).to eq('foo//.gitlab_ci.yml') end end -- cgit v1.2.1 From d1e0b1b3a8404f3a7b54db09c46fb614ca3fcb93 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Mon, 3 Jul 2017 13:55:43 +0100 Subject: Allow creation of files and directories with spaces in web UI --- spec/models/repository_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index c69f0a495db..80b363355da 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -347,6 +347,16 @@ describe Repository, models: true do expect(blob.data).to eq('Changelog!') end + it 'creates new file with spaces in between successfully' do + expect do + repository.create_file(user, 'NEW FILE', 'File!', + message: 'Create NEW FILE', + branch_name: 'master') + end.to change { repository.commits('master').count }.by(1) + + expect(repository.blob_at('master', 'NEW FILE').data).to eq('File!') + end + it 'respects the autocrlf setting' do repository.create_file(user, 'hello.txt', "Hello,\r\nWorld", message: 'Add hello world', -- cgit v1.2.1 From 8a950baf5806ce630459b57bc88b79245c1a15ca Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 6 Jul 2017 01:24:20 +0900 Subject: Improve test on spec/models/ci/pipeline_schedule_spec.rb --- spec/models/ci/pipeline_schedule_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 4c3aa986bf9..6427deda31e 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -132,6 +132,6 @@ describe Ci::PipelineSchedule, models: true do pipeline_schedule.reload end - it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) } + it { is_expected.to contain_exactly(*pipeline_schedule_variables.map(&:to_runner_variable)) } end end -- cgit v1.2.1 From 1207d451ed934f3ce2d8c02130a8e6b2cac88a70 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Wed, 5 Jul 2017 17:01:38 +0100 Subject: Removes file_name_regex from Gitlab::Regex --- spec/models/repository_spec.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 80b363355da..af305e9b234 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -347,14 +347,15 @@ describe Repository, models: true do expect(blob.data).to eq('Changelog!') end - it 'creates new file with spaces in between successfully' do + it 'creates new file and dir when file_path has a forward slash' do expect do - repository.create_file(user, 'NEW FILE', 'File!', - message: 'Create NEW FILE', + repository.create_file(user, 'new_dir/new_file.txt', 'File!', + message: 'Create new_file with new_dir', branch_name: 'master') end.to change { repository.commits('master').count }.by(1) - expect(repository.blob_at('master', 'NEW FILE').data).to eq('File!') + expect(repository.tree('master', 'new_dir').path).to eq('new_dir') + expect(repository.blob_at('master', 'new_dir/new_file.txt').data).to eq('File!') end it 'respects the autocrlf setting' do -- cgit v1.2.1 From 1a581a6afcc3ac94dcc2208412bd80861dba84ab Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 5 Jul 2017 21:23:10 +0200 Subject: Use a previous approach for cycle analytics dummy pipeline --- spec/models/project_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ae16b497c2f..751ffb2220a 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1523,7 +1523,7 @@ describe Project, models: true do expect(project.ci_config_path).to eq('foo/.gitlab_ci.yml') end - it 'sets a string but remove all leading slashes and null characters' do + it 'sets a string but removes all leading slashes and null characters' do project.update!(ci_config_path: "///f\0oo/\0/.gitlab_ci.yml") expect(project.ci_config_path).to eq('foo//.gitlab_ci.yml') -- cgit v1.2.1 From e7acc88156116bbfc20d13b5d897492cc415ee38 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Jul 2017 15:55:40 +0800 Subject: Rename KUBECONFIG_FILE to KUBECONFIG --- spec/models/project_services/kubernetes_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index d4feae231bc..7ec2ea5ba95 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -221,7 +221,7 @@ describe KubernetesService, models: true, caching: true do { key: 'KUBE_URL', value: 'https://kube.domain.com', public: true }, { key: 'KUBE_TOKEN', value: 'token', public: false }, { key: 'KUBE_NAMESPACE', value: namespace, public: true }, - { key: 'KUBECONFIG_FILE', value: kubeconfig, public: false, file: true }, + { key: 'KUBECONFIG', value: kubeconfig, public: false, file: true }, { key: 'KUBE_CA_PEM', value: 'CA PEM DATA', public: true }, { key: 'KUBE_CA_PEM_FILE', value: 'CA PEM DATA', public: true, file: true } ) -- cgit v1.2.1 From d9435d61218f677395f3b53976a41ac5f361f24b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Jul 2017 15:45:38 +0800 Subject: Backports for ee-2112 https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2112 --- spec/models/ci/build_spec.rb | 7 ++++--- spec/models/ci/variable_spec.rb | 4 ---- spec/models/project_spec.rb | 12 ++++++------ 3 files changed, 10 insertions(+), 13 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index a7ba3a7c43e..2b10791ad6d 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1496,9 +1496,10 @@ describe Ci::Build, :models do allow(pipeline).to receive(:predefined_variables) { [pipeline_pre_var] } allow(build).to receive(:yaml_variables) { [build_yaml_var] } - allow(project).to receive(:secret_variables_for).with(build.ref) do - [create(:ci_variable, key: 'secret', value: 'value')] - end + allow(project).to receive(:secret_variables_for) + .with(ref: 'master', environment: nil) do + [create(:ci_variable, key: 'secret', value: 'value')] + end end it do diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 50f7c029af8..4ffbfa6c130 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -8,10 +8,6 @@ describe Ci::Variable, models: true do describe 'validations' do it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope) } - it { is_expected.to validate_length_of(:key).is_at_most(255) } - it { is_expected.to allow_value('foo').for(:key) } - it { is_expected.not_to allow_value('foo bar').for(:key) } - it { is_expected.not_to allow_value('foo/bar').for(:key) } end describe '.unprotected' do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index f50b4aea411..a9855cf343b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1875,7 +1875,12 @@ describe Project, models: true do create(:ci_variable, :protected, value: 'protected', project: project) end - subject { project.secret_variables_for('ref') } + subject { project.secret_variables_for(ref: 'ref') } + + before do + stub_application_setting( + default_branch_protection: Gitlab::Access::PROTECTION_NONE) + end shared_examples 'ref is protected' do it 'contains all the variables' do @@ -1884,11 +1889,6 @@ describe Project, models: true do end context 'when the ref is not protected' do - before do - stub_application_setting( - default_branch_protection: Gitlab::Access::PROTECTION_NONE) - end - it 'contains only the secret variables' do is_expected.to contain_exactly(secret_variable) end -- cgit v1.2.1 From c63e3221587daf9e7464f7d2079ca8ed3111f6ff Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 30 May 2017 13:54:59 +0200 Subject: Add many foreign keys to the projects table This removes the need for relying on Rails' "dependent" option for data removal, which is _incredibly_ slow (even when using :delete_all) when deleting large amounts of data. This also ensures data consistency is enforced on DB level and not on application level (something Rails is really bad at). This commit also includes various migrations to add foreign keys to tables that eventually point to "projects" to ensure no rows get orphaned upon removing a project. --- spec/models/concerns/issuable_spec.rb | 2 +- spec/models/forked_project_link_spec.rb | 6 +- spec/models/merge_request_spec.rb | 2 +- spec/models/project_spec.rb | 121 ++++++++++++++++++-------------- 4 files changed, 74 insertions(+), 57 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index ac9303370ab..505039c9d88 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -155,7 +155,7 @@ describe Issuable do end describe "#sort" do - let(:project) { build_stubbed(:empty_project) } + let(:project) { create(:empty_project) } context "by milestone due date" do # Correct order is: diff --git a/spec/models/forked_project_link_spec.rb b/spec/models/forked_project_link_spec.rb index 5c13cf584f9..38fbdd2536a 100644 --- a/spec/models/forked_project_link_spec.rb +++ b/spec/models/forked_project_link_spec.rb @@ -42,7 +42,7 @@ describe ForkedProjectLink, "add link on fork" do describe '#forked?' do let(:project_to) { create(:project, forked_project_link: forked_project_link) } - let(:forked_project_link) { build(:forked_project_link) } + let(:forked_project_link) { create(:forked_project_link) } before do forked_project_link.forked_from_project = project_from @@ -59,9 +59,9 @@ describe ForkedProjectLink, "add link on fork" do end it "project_to.destroy destroys fork_link" do - expect(forked_project_link).to receive(:destroy) - project_to.destroy + + expect(ForkedProjectLink.exists?(id: forked_project_link.id)).to eq(false) end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 587d4b83cb4..d91f1f1a11c 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -10,7 +10,7 @@ describe MergeRequest, models: true do it { is_expected.to belong_to(:source_project).class_name('Project') } it { is_expected.to belong_to(:merge_user).class_name("User") } it { is_expected.to belong_to(:assignee) } - it { is_expected.to have_many(:merge_request_diffs).dependent(:destroy) } + it { is_expected.to have_many(:merge_request_diffs) } end describe 'modules' do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index f50b4aea411..75fa2d2eb46 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -7,50 +7,50 @@ describe Project, models: true do it { is_expected.to belong_to(:creator).class_name('User') } it { is_expected.to have_many(:users) } it { is_expected.to have_many(:services) } - it { is_expected.to have_many(:events).dependent(:destroy) } - it { is_expected.to have_many(:merge_requests).dependent(:destroy) } - it { is_expected.to have_many(:issues).dependent(:destroy) } - it { is_expected.to have_many(:milestones).dependent(:destroy) } - it { is_expected.to have_many(:project_members).dependent(:destroy) } + it { is_expected.to have_many(:events) } + it { is_expected.to have_many(:merge_requests) } + it { is_expected.to have_many(:issues) } + it { is_expected.to have_many(:milestones) } + it { is_expected.to have_many(:project_members).dependent(:delete_all) } it { is_expected.to have_many(:users).through(:project_members) } - it { is_expected.to have_many(:requesters).dependent(:destroy) } - it { is_expected.to have_many(:notes).dependent(:destroy) } - it { is_expected.to have_many(:snippets).class_name('ProjectSnippet').dependent(:destroy) } - it { is_expected.to have_many(:deploy_keys_projects).dependent(:destroy) } + it { is_expected.to have_many(:requesters).dependent(:delete_all) } + it { is_expected.to have_many(:notes) } + it { is_expected.to have_many(:snippets).class_name('ProjectSnippet') } + it { is_expected.to have_many(:deploy_keys_projects) } it { is_expected.to have_many(:deploy_keys) } - it { is_expected.to have_many(:hooks).dependent(:destroy) } - it { is_expected.to have_many(:protected_branches).dependent(:destroy) } - it { is_expected.to have_one(:forked_project_link).dependent(:destroy) } - it { is_expected.to have_one(:slack_service).dependent(:destroy) } - it { is_expected.to have_one(:microsoft_teams_service).dependent(:destroy) } - it { is_expected.to have_one(:mattermost_service).dependent(:destroy) } - it { is_expected.to have_one(:pushover_service).dependent(:destroy) } - it { is_expected.to have_one(:asana_service).dependent(:destroy) } - it { is_expected.to have_many(:boards).dependent(:destroy) } - it { is_expected.to have_one(:campfire_service).dependent(:destroy) } - it { is_expected.to have_one(:drone_ci_service).dependent(:destroy) } - it { is_expected.to have_one(:emails_on_push_service).dependent(:destroy) } - it { is_expected.to have_one(:pipelines_email_service).dependent(:destroy) } - it { is_expected.to have_one(:irker_service).dependent(:destroy) } - it { is_expected.to have_one(:pivotaltracker_service).dependent(:destroy) } - it { is_expected.to have_one(:hipchat_service).dependent(:destroy) } - it { is_expected.to have_one(:flowdock_service).dependent(:destroy) } - it { is_expected.to have_one(:assembla_service).dependent(:destroy) } - it { is_expected.to have_one(:slack_slash_commands_service).dependent(:destroy) } - it { is_expected.to have_one(:mattermost_slash_commands_service).dependent(:destroy) } - it { is_expected.to have_one(:gemnasium_service).dependent(:destroy) } - it { is_expected.to have_one(:buildkite_service).dependent(:destroy) } - it { is_expected.to have_one(:bamboo_service).dependent(:destroy) } - it { is_expected.to have_one(:teamcity_service).dependent(:destroy) } - it { is_expected.to have_one(:jira_service).dependent(:destroy) } - it { is_expected.to have_one(:redmine_service).dependent(:destroy) } - it { is_expected.to have_one(:custom_issue_tracker_service).dependent(:destroy) } - it { is_expected.to have_one(:bugzilla_service).dependent(:destroy) } - it { is_expected.to have_one(:gitlab_issue_tracker_service).dependent(:destroy) } - it { is_expected.to have_one(:external_wiki_service).dependent(:destroy) } - it { is_expected.to have_one(:project_feature).dependent(:destroy) } - it { is_expected.to have_one(:statistics).class_name('ProjectStatistics').dependent(:delete) } - it { is_expected.to have_one(:import_data).class_name('ProjectImportData').dependent(:delete) } + it { is_expected.to have_many(:hooks) } + it { is_expected.to have_many(:protected_branches) } + it { is_expected.to have_one(:forked_project_link) } + it { is_expected.to have_one(:slack_service) } + it { is_expected.to have_one(:microsoft_teams_service) } + it { is_expected.to have_one(:mattermost_service) } + it { is_expected.to have_one(:pushover_service) } + it { is_expected.to have_one(:asana_service) } + it { is_expected.to have_many(:boards) } + it { is_expected.to have_one(:campfire_service) } + it { is_expected.to have_one(:drone_ci_service) } + it { is_expected.to have_one(:emails_on_push_service) } + it { is_expected.to have_one(:pipelines_email_service) } + it { is_expected.to have_one(:irker_service) } + it { is_expected.to have_one(:pivotaltracker_service) } + it { is_expected.to have_one(:hipchat_service) } + it { is_expected.to have_one(:flowdock_service) } + it { is_expected.to have_one(:assembla_service) } + it { is_expected.to have_one(:slack_slash_commands_service) } + it { is_expected.to have_one(:mattermost_slash_commands_service) } + it { is_expected.to have_one(:gemnasium_service) } + it { is_expected.to have_one(:buildkite_service) } + it { is_expected.to have_one(:bamboo_service) } + it { is_expected.to have_one(:teamcity_service) } + it { is_expected.to have_one(:jira_service) } + it { is_expected.to have_one(:redmine_service) } + it { is_expected.to have_one(:custom_issue_tracker_service) } + it { is_expected.to have_one(:bugzilla_service) } + it { is_expected.to have_one(:gitlab_issue_tracker_service) } + it { is_expected.to have_one(:external_wiki_service) } + it { is_expected.to have_one(:project_feature) } + it { is_expected.to have_one(:statistics).class_name('ProjectStatistics') } + it { is_expected.to have_one(:import_data).class_name('ProjectImportData') } it { is_expected.to have_one(:last_event).class_name('Event') } it { is_expected.to have_one(:forked_from_project).through(:forked_project_link) } it { is_expected.to have_many(:commit_statuses) } @@ -62,18 +62,18 @@ describe Project, models: true do it { is_expected.to have_many(:variables) } it { is_expected.to have_many(:triggers) } it { is_expected.to have_many(:pages_domains) } - it { is_expected.to have_many(:labels).class_name('ProjectLabel').dependent(:destroy) } - it { is_expected.to have_many(:users_star_projects).dependent(:destroy) } - it { is_expected.to have_many(:environments).dependent(:destroy) } - it { is_expected.to have_many(:deployments).dependent(:destroy) } - it { is_expected.to have_many(:todos).dependent(:destroy) } - it { is_expected.to have_many(:releases).dependent(:destroy) } - it { is_expected.to have_many(:lfs_objects_projects).dependent(:destroy) } - it { is_expected.to have_many(:project_group_links).dependent(:destroy) } - it { is_expected.to have_many(:notification_settings).dependent(:destroy) } + it { is_expected.to have_many(:labels).class_name('ProjectLabel') } + it { is_expected.to have_many(:users_star_projects) } + it { is_expected.to have_many(:environments) } + it { is_expected.to have_many(:deployments) } + it { is_expected.to have_many(:todos) } + it { is_expected.to have_many(:releases) } + it { is_expected.to have_many(:lfs_objects_projects) } + it { is_expected.to have_many(:project_group_links) } + it { is_expected.to have_many(:notification_settings).dependent(:delete_all) } it { is_expected.to have_many(:forks).through(:forked_project_links) } it { is_expected.to have_many(:uploads).dependent(:destroy) } - it { is_expected.to have_many(:pipeline_schedules).dependent(:destroy) } + it { is_expected.to have_many(:pipeline_schedules) } context 'after initialized' do it "has a project_feature" do @@ -2199,4 +2199,21 @@ describe Project, models: true do end end end + + describe '#remove_private_deploy_keys' do + it 'removes the private deploy keys of a project' do + project = create(:empty_project) + + private_key = create(:deploy_key, public: false) + public_key = create(:deploy_key, public: true) + + create(:deploy_keys_project, deploy_key: private_key, project: project) + create(:deploy_keys_project, deploy_key: public_key, project: project) + + project.remove_private_deploy_keys + + expect(project.deploy_keys.where(public: false).any?).to eq(false) + expect(project.deploy_keys.where(public: true).any?).to eq(true) + end + end end -- cgit v1.2.1 From dbb313c26f79e5bebf197af8eba24411fced51bb Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 6 Jul 2017 19:38:41 +0800 Subject: Encode certificate-authority-data in base64 --- spec/models/project_services/kubernetes_service_spec.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index 7ec2ea5ba95..5ba523a478a 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -202,10 +202,19 @@ describe KubernetesService, models: true, caching: true do describe '#predefined_variables' do let(:kubeconfig) do - File.read(expand_fixture_path('config/kubeconfig.yml')) - .gsub('TOKEN', 'token') - .gsub('PEM', 'CA PEM DATA') - .gsub('NAMESPACE', namespace) + config = + YAML.load(File.read(expand_fixture_path('config/kubeconfig.yml'))) + + config.dig('users', 0, 'user')['token'] = + 'token' + + config.dig('clusters', 0, 'cluster')['certificate-authority-data'] = + Base64.encode64('CA PEM DATA') + + config.dig('contexts', 0, 'context')['namespace'] = + namespace + + YAML.dump(config) end before do -- cgit v1.2.1 From aff5c9f3e5ecdd9eee2b2b60ab6367da878582fc Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 16 Jun 2017 15:00:58 +0100 Subject: Add table for merge request commits This is an ID-less table with just three columns: an association to the merge request diff the commit belongs to, the relative order of the commit within the merge request diff, and the commit SHA itself. Previously we stored much more information about the commits, so that we could display them even when they were deleted from the repo. Since 8.0, we ensure that those commits are kept around for as long as the target repo itself is, so we don't need to duplicate that data in the database. --- spec/models/ci/build_spec.rb | 2 +- spec/models/merge_request_diff_commit_spec.rb | 15 +++++++++++++++ spec/models/merge_request_diff_spec.rb | 6 +++--- spec/models/merge_request_spec.rb | 18 +++++++++--------- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 spec/models/merge_request_diff_commit_spec.rb (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 2b10791ad6d..431fcda165d 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -863,7 +863,7 @@ describe Ci::Build, :models do pipeline2 = create(:ci_pipeline, project: project) @build2 = create(:ci_build, pipeline: pipeline2) - allow(@merge_request).to receive(:commits_sha) + allow(@merge_request).to receive(:commit_shas) .and_return([pipeline.sha, pipeline2.sha]) allow(MergeRequest).to receive_message_chain(:includes, :where, :reorder).and_return([@merge_request]) end diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb new file mode 100644 index 00000000000..dbfd1526518 --- /dev/null +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +describe MergeRequestDiffCommit, type: :model do + let(:merge_request) { create(:merge_request) } + subject { merge_request.commits.first } + + describe '#to_hash' do + it 'returns the same results as Commit#to_hash, except for parent_ids' do + commit_from_repo = merge_request.project.repository.commit(subject.sha) + commit_from_repo_hash = commit_from_repo.to_hash.merge(parent_ids: []) + + expect(subject.to_hash).to eq(commit_from_repo_hash) + end + end +end diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index 4ad4abaa572..edc2f4bb9f0 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -98,7 +98,7 @@ describe MergeRequestDiff, models: true do end it 'saves empty state' do - allow_any_instance_of(MergeRequestDiff).to receive(:commits) + allow_any_instance_of(MergeRequestDiff).to receive_message_chain(:compare, :commits) .and_return([]) mr_diff = create(:merge_request).merge_request_diff @@ -107,14 +107,14 @@ describe MergeRequestDiff, models: true do end end - describe '#commits_sha' do + describe '#commit_shas' do it 'returns all commits SHA using serialized commits' do subject.st_commits = [ { id: 'sha1' }, { id: 'sha2' } ] - expect(subject.commits_sha).to eq(%w(sha1 sha2)) + expect(subject.commit_shas).to eq(%w(sha1 sha2)) end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index d91f1f1a11c..ea405fabff0 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -720,14 +720,14 @@ describe MergeRequest, models: true do subject { create :merge_request, :simple } end - describe '#commits_sha' do + describe '#commit_shas' do before do - allow(subject.merge_request_diff).to receive(:commits_sha) + allow(subject.merge_request_diff).to receive(:commit_shas) .and_return(['sha1']) end it 'delegates to merge request diff' do - expect(subject.commits_sha).to eq ['sha1'] + expect(subject.commit_shas).to eq ['sha1'] end end @@ -752,7 +752,7 @@ describe MergeRequest, models: true do describe '#all_pipelines' do shared_examples 'returning pipelines with proper ordering' do let!(:all_pipelines) do - subject.all_commits_sha.map do |sha| + subject.all_commit_shas.map do |sha| create(:ci_empty_pipeline, project: subject.source_project, sha: sha, @@ -794,16 +794,16 @@ describe MergeRequest, models: true do end end - describe '#all_commits_sha' do + describe '#all_commit_shas' do context 'when merge request is persisted' do - let(:all_commits_sha) do + let(:all_commit_shas) do subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq end shared_examples 'returning all SHA' do it 'returns all SHA from all merge_request_diffs' do expect(subject.merge_request_diffs.size).to eq(2) - expect(subject.all_commits_sha).to eq(all_commits_sha) + expect(subject.all_commit_shas).to eq(all_commit_shas) end end @@ -834,7 +834,7 @@ describe MergeRequest, models: true do end it 'returns commits from compare commits temporary data' do - expect(subject.all_commits_sha).to eq [commit, commit] + expect(subject.all_commit_shas).to eq [commit, commit] end end @@ -842,7 +842,7 @@ describe MergeRequest, models: true do subject { build(:merge_request) } it 'returns array with diff head sha element only' do - expect(subject.all_commits_sha).to eq [subject.diff_head_sha] + expect(subject.all_commit_shas).to eq [subject.diff_head_sha] end end end -- cgit v1.2.1 From 040eeb1039b4298ea56a670a0a4ae511288806d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 6 Jul 2017 18:57:02 +0200 Subject: Allow to enable the Performance Bar for a group from the admin area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/application_setting_spec.rb | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 166a4474abf..4b7281d593a 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -214,6 +214,151 @@ describe ApplicationSetting, models: true do end end + describe 'performance bar settings' do + before do + Flipper.unregister_groups + Flipper.register(:performance_team) + end + + after do + Flipper.unregister_groups + end + + describe 'performance_bar_allowed_group_id=' do + it 'does not persist an invalid group path' do + setting.performance_bar_allowed_group_id = 'foo' + + expect(setting.performance_bar_allowed_group_id).to be_nil + end + + context 'with a path to an existing group' do + let(:group) { create(:group) } + + it 'persists a valid group path and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + + setting.performance_bar_allowed_group_id = group.full_path + + expect(setting.performance_bar_allowed_group_id).to eq(group.id) + end + + context 'when the given path is the same' do + before do + setting.performance_bar_allowed_group_id = group.full_path + end + + it 'clears the cached allowed user IDs' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + + setting.performance_bar_allowed_group_id = group.full_path + end + end + end + end + + describe 'performance_bar_allowed_group' do + context 'with no performance_bar_allowed_group_id saved' do + it 'returns nil' do + expect(setting.performance_bar_allowed_group).to be_nil + end + end + + context 'with a performance_bar_allowed_group_id saved' do + let(:group) { create(:group) } + + before do + setting.performance_bar_allowed_group_id = group.full_path + end + + it 'returns the group' do + expect(setting.performance_bar_allowed_group).to eq(group) + end + end + end + + describe 'performance_bar_enabled?' do + context 'with the Performance Bar is enabled globally' do + before do + Feature.enable(:performance_bar) + end + + it 'returns true' do + expect(setting).to be_performance_bar_enabled + end + end + + context 'with the Performance Bar is enabled for the performance_team group' do + before do + Feature.enable_group(:performance_bar, :performance_team) + end + + it 'returns true' do + expect(setting).to be_performance_bar_enabled + end + end + + context 'with the Performance Bar is enabled for a specific user' do + before do + Feature.enable(:performance_team, create(:user)) + end + + it 'returns false' do + expect(setting).not_to be_performance_bar_enabled + end + end + end + + describe 'performance_bar_enabled=' do + context 'when the performance bar is enabled' do + before do + Feature.enable(:performance_bar) + end + + context 'when passing true' do + it 'does not clear allowed user IDs cache' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true + + expect(setting).to be_performance_bar_enabled + end + end + + context 'when passing false' do + it 'disables the performance bar and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false + + expect(setting).not_to be_performance_bar_enabled + end + end + end + + context 'when the performance bar is disabled' do + before do + Feature.disable(:performance_bar) + end + + context 'when passing true' do + it 'enables the performance bar and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true + + expect(setting).to be_performance_bar_enabled + end + end + + context 'when passing false' do + it 'does not clear allowed user IDs cache' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false + + expect(setting).not_to be_performance_bar_enabled + end + end + end + end + end + describe 'usage ping settings' do context 'when the usage ping is disabled in gitlab.yml' do before do -- cgit v1.2.1 From d195db17e9ff62c3dbfb8ba03dacadf965b1fb8b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Thu, 6 Jul 2017 14:21:08 -0500 Subject: Don't show auxiliary blob viewer for README when there is no wiki --- spec/models/blob_viewer/readme_spec.rb | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 spec/models/blob_viewer/readme_spec.rb (limited to 'spec/models') diff --git a/spec/models/blob_viewer/readme_spec.rb b/spec/models/blob_viewer/readme_spec.rb new file mode 100644 index 00000000000..02679dbb544 --- /dev/null +++ b/spec/models/blob_viewer/readme_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe BlobViewer::Readme, model: true do + include FakeBlobHelpers + + let(:project) { create(:project, :repository) } + let(:blob) { fake_blob(path: 'README.md') } + subject { described_class.new(blob) } + + describe '#render_error' do + context 'when there is no wiki' do + it 'returns :no_wiki' do + expect(subject.render_error).to eq(:no_wiki) + end + end + + context 'when there is an external wiki' do + before do + project.has_external_wiki = true + end + + it 'returns nil' do + expect(subject.render_error).to be_nil + end + end + + context 'when there is a local wiki' do + before do + project.wiki_enabled = true + end + + context 'when the wiki is empty' do + it 'returns :no_wiki' do + expect(subject.render_error).to eq(:no_wiki) + end + end + + context 'when the wiki is not empty' do + before do + WikiPages::CreateService.new(project, project.owner, title: 'home', content: 'Home page').execute + end + + it 'returns nil' do + expect(subject.render_error).to be_nil + end + end + end + end +end -- cgit v1.2.1 From 97611c88fcbae6b025750e6ebf2061a3d87d9753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Fri, 7 Jul 2017 02:34:51 +0200 Subject: Don't use Flipper for the Performance Bar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The implementation now simply rely on the `performance_bar_allowed_group_id` Application Setting. Signed-off-by: Rémy Coutable --- spec/models/application_setting_spec.rb | 111 +++++++++++++++++--------------- 1 file changed, 60 insertions(+), 51 deletions(-) (limited to 'spec/models') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 4b7281d593a..fb485d0b2c6 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -215,20 +215,27 @@ describe ApplicationSetting, models: true do end describe 'performance bar settings' do - before do - Flipper.unregister_groups - Flipper.register(:performance_team) - end + describe 'performance_bar_allowed_group_id=' do + context 'with a blank path' do + before do + setting.performance_bar_allowed_group_id = create(:group).full_path + end - after do - Flipper.unregister_groups - end + it 'persists nil for a "" path and clears allowed user IDs cache' do + expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) - describe 'performance_bar_allowed_group_id=' do - it 'does not persist an invalid group path' do - setting.performance_bar_allowed_group_id = 'foo' + setting.performance_bar_allowed_group_id = '' + + expect(setting.performance_bar_allowed_group_id).to be_nil + end + end + + context 'with an invalid path' do + it 'does not persist an invalid group path' do + setting.performance_bar_allowed_group_id = 'foo' - expect(setting.performance_bar_allowed_group_id).to be_nil + expect(setting.performance_bar_allowed_group_id).to be_nil + end end context 'with a path to an existing group' do @@ -243,14 +250,28 @@ describe ApplicationSetting, models: true do end context 'when the given path is the same' do - before do - setting.performance_bar_allowed_group_id = group.full_path + context 'with a blank path' do + before do + setting.performance_bar_allowed_group_id = nil + end + + it 'clears the cached allowed user IDs' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + + setting.performance_bar_allowed_group_id = '' + end end - it 'clears the cached allowed user IDs' do - expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + context 'with a valid path' do + before do + setting.performance_bar_allowed_group_id = group.full_path + end + + it 'clears the cached allowed user IDs' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) - setting.performance_bar_allowed_group_id = group.full_path + setting.performance_bar_allowed_group_id = group.full_path + end end end end @@ -276,83 +297,71 @@ describe ApplicationSetting, models: true do end end - describe 'performance_bar_enabled?' do - context 'with the Performance Bar is enabled globally' do - before do - Feature.enable(:performance_bar) - end - - it 'returns true' do - expect(setting).to be_performance_bar_enabled - end - end + describe 'performance_bar_enabled' do + context 'with the Performance Bar is enabled' do + let(:group) { create(:group) } - context 'with the Performance Bar is enabled for the performance_team group' do before do - Feature.enable_group(:performance_bar, :performance_team) + setting.performance_bar_allowed_group_id = group.full_path end it 'returns true' do - expect(setting).to be_performance_bar_enabled - end - end - - context 'with the Performance Bar is enabled for a specific user' do - before do - Feature.enable(:performance_team, create(:user)) - end - - it 'returns false' do - expect(setting).not_to be_performance_bar_enabled + expect(setting.performance_bar_enabled).to be_truthy end end end describe 'performance_bar_enabled=' do context 'when the performance bar is enabled' do + let(:group) { create(:group) } + before do - Feature.enable(:performance_bar) + setting.performance_bar_allowed_group_id = group.full_path end context 'when passing true' do it 'does not clear allowed user IDs cache' do expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true - expect(setting).to be_performance_bar_enabled + expect(setting.performance_bar_allowed_group_id).to eq(group.id) + expect(setting.performance_bar_enabled).to be_truthy end end context 'when passing false' do it 'disables the performance bar and clears allowed user IDs cache' do expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false - expect(setting).not_to be_performance_bar_enabled + expect(setting.performance_bar_allowed_group_id).to be_nil + expect(setting.performance_bar_enabled).to be_falsey end end end context 'when the performance bar is disabled' do - before do - Feature.disable(:performance_bar) - end - context 'when passing true' do - it 'enables the performance bar and clears allowed user IDs cache' do - expect(Gitlab::PerformanceBar).to receive(:expire_allowed_user_ids_cache) + it 'does nothing and does not clear allowed user IDs cache' do + expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = true - expect(setting).to be_performance_bar_enabled + expect(setting.performance_bar_allowed_group_id).to be_nil + expect(setting.performance_bar_enabled).to be_falsey end end context 'when passing false' do - it 'does not clear allowed user IDs cache' do + it 'does nothing and does not clear allowed user IDs cache' do expect(Gitlab::PerformanceBar).not_to receive(:expire_allowed_user_ids_cache) + setting.performance_bar_enabled = false - expect(setting).not_to be_performance_bar_enabled + expect(setting.performance_bar_allowed_group_id).to be_nil + expect(setting.performance_bar_enabled).to be_falsey end end end -- cgit v1.2.1 From 5b0954759cc24bdba97be89bb117c5440174f859 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 4 May 2017 03:51:55 +0900 Subject: Basic BE change Fix static-snalysis Move the precedence of group secure variable before project secure variable. Allow project_id to be null. Separate Ci::VariableProject and Ci::VariableGroup Add the forgotton files Add migration file to update type of ci_variables Fix form_for fpr VariableProject Fix test Change the table structure according to the yorik advice Add necessary migration files. Remove unnecessary migration spec. Revert safe_model_attributes.yml Fix models Fix spec Avoid self.variable. Use becomes for correct routing. Use unique index on group_id and key Add null: false for t.timestamps Fix schema version Rename VariableProject and VariableGroup to ProjectVariable and GroupVariable Rename the rest of them Add the rest of files Basic BE change Fix static-snalysis Move the precedence of group secure variable before project secure variable. Allow project_id to be null. Separate Ci::VariableProject and Ci::VariableGroup Add the forgotton files Add migration file to update type of ci_variables Fix form_for fpr VariableProject Fix test Change the table structure according to the yorik advice Add necessary migration files. Remove unnecessary migration spec. Revert safe_model_attributes.yml Fix models Fix spec Avoid self.variable. Use becomes for correct routing. Use unique index on group_id and key Add null: false for t.timestamps Fix schema version Rename VariableProject and VariableGroup to ProjectVariable and GroupVariable Rename the rest of them Add the rest of files Implement CURD Rename codes related to VariableGroup and VariableProject FE part Remove unneccesary changes Make Fe code up-to-date Add protected flag to migration file Protected group variables essential package Update schema Improve doc Fix logic and spec for models Fix logic and spec for controllers Fix logic and spec for views(pre feature) Add feature spec Fixed bugs. placeholder. reveal button. doc. Add changelog Remove unnecessary comment godfat nice catches Improve secret_variables_for arctecture Fix spec Fix StaticAnlysys & path_regex spec Revert "Improve secret_variables_for arctecture" This reverts commit c3216ca212322ecf6ca534cb12ce75811a4e77f1. Use ayufan suggestion for secret_variables_for Use find instead of find_by Fix spec message for variable is invalid Fix spec remove variable.group_id = group.id godffat spec nitpicks Use include Gitlab::Routing.url_helpers for presenter spec --- spec/models/ci/build_spec.rb | 53 +++++++++++++++++++++++++++++++ spec/models/ci/group_variable_spec.rb | 31 ++++++++++++++++++ spec/models/ci/variable_spec.rb | 3 +- spec/models/group_spec.rb | 59 +++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 spec/models/ci/group_variable_spec.rb (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 431fcda165d..cf6d356c524 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1356,6 +1356,59 @@ describe Ci::Build, :models do end end + context 'when group secret variable is defined' do + let(:secret_variable) do + { key: 'SECRET_KEY', value: 'secret_value', public: false } + end + + let(:group) { create(:group, :access_requestable) } + + before do + build.project.update(group: group) + + create(:ci_group_variable, + secret_variable.slice(:key, :value).merge(group: group)) + end + + it { is_expected.to include(secret_variable) } + end + + context 'when group protected variable is defined' do + let(:protected_variable) do + { key: 'PROTECTED_KEY', value: 'protected_value', public: false } + end + + let(:group) { create(:group, :access_requestable) } + + before do + build.project.update(group: group) + + create(:ci_group_variable, + :protected, + protected_variable.slice(:key, :value).merge(group: group)) + end + + context 'when the branch is protected' do + before do + create(:protected_branch, project: build.project, name: build.ref) + end + + it { is_expected.to include(protected_variable) } + end + + context 'when the tag is protected' do + before do + create(:protected_tag, project: build.project, name: build.ref) + end + + it { is_expected.to include(protected_variable) } + end + + context 'when the ref is not protected' do + it { is_expected.not_to include(protected_variable) } + end + end + context 'when build is for triggers' do let(:trigger) { create(:ci_trigger, project: project) } let(:trigger_request) { create(:ci_trigger_request_with_variables, pipeline: pipeline, trigger: trigger) } diff --git a/spec/models/ci/group_variable_spec.rb b/spec/models/ci/group_variable_spec.rb new file mode 100644 index 00000000000..24b914face9 --- /dev/null +++ b/spec/models/ci/group_variable_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Ci::GroupVariable, models: true do + subject { build(:ci_group_variable) } + + it { is_expected.to include_module(HasVariable) } + it { is_expected.to include_module(Presentable) } + it { is_expected.to validate_uniqueness_of(:key).scoped_to(:group_id) } + + describe '.unprotected' do + subject { described_class.unprotected } + + context 'when variable is protected' do + before do + create(:ci_group_variable, :protected) + end + + it 'returns nothing' do + is_expected.to be_empty + end + end + + context 'when variable is not protected' do + let(:variable) { create(:ci_group_variable, protected: false) } + + it 'returns the variable' do + is_expected.to contain_exactly(variable) + end + end + end +end diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 4ffbfa6c130..890ffaae494 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -3,10 +3,9 @@ require 'spec_helper' describe Ci::Variable, models: true do subject { build(:ci_variable) } - let(:secret_value) { 'secret' } - describe 'validations' do it { is_expected.to include_module(HasVariable) } + it { is_expected.to include_module(Presentable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope) } end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 4de1683b21c..dab33aa4418 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -13,6 +13,7 @@ describe Group, models: true do it { is_expected.to have_many(:shared_projects).through(:project_group_links) } it { is_expected.to have_many(:notification_settings).dependent(:destroy) } it { is_expected.to have_many(:labels).class_name('GroupLabel') } + it { is_expected.to have_many(:variables).class_name('Ci::GroupVariable') } it { is_expected.to have_many(:uploads).dependent(:destroy) } it { is_expected.to have_one(:chat_team) } @@ -418,4 +419,62 @@ describe Group, models: true do expect(calls).to eq 2 end end + + describe '#secret_variables_for' do + let(:project) { create(:empty_project, group: group) } + + let!(:secret_variable) do + create(:ci_group_variable, value: 'secret', group: group) + end + + let!(:protected_variable) do + create(:ci_group_variable, :protected, value: 'protected', group: group) + end + + subject { group.secret_variables_for('ref', project) } + + shared_examples 'ref is protected' do + it 'contains all the variables' do + is_expected.to contain_exactly(secret_variable, protected_variable) + end + end + + context 'when the ref is not protected' do + before do + stub_application_setting( + default_branch_protection: Gitlab::Access::PROTECTION_NONE) + end + + it 'contains only the secret variables' do + is_expected.to contain_exactly(secret_variable) + end + end + + context 'when the ref is a protected branch' do + before do + create(:protected_branch, name: 'ref', project: project) + end + + it_behaves_like 'ref is protected' + end + + context 'when the ref is a protected tag' do + before do + create(:protected_tag, name: 'ref', project: project) + end + + it_behaves_like 'ref is protected' + end + + context 'when group has a child' do + let!(:group_child) { create(:group, :access_requestable, parent: group) } + let!(:variable_child) { create(:ci_group_variable, group: group_child) } + + subject { group_child.secret_variables_for('ref', project) } + + it 'returns all variables belong to the group and parent groups' do + is_expected.to contain_exactly(secret_variable, protected_variable, variable_child) + end + end + end end -- cgit v1.2.1 From 5cb45b6a44a2cefff4f9cd7d5fd0b98b51416e94 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 5 Jul 2017 17:55:48 +0900 Subject: Add CASE When Clause for saving order when using where IN --- spec/models/group_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'spec/models') diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index dab33aa4418..399020953e8 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -466,14 +466,21 @@ describe Group, models: true do it_behaves_like 'ref is protected' end - context 'when group has a child' do - let!(:group_child) { create(:group, :access_requestable, parent: group) } + context 'when group has children' do + let!(:group_child) { create(:group, parent: group) } let!(:variable_child) { create(:ci_group_variable, group: group_child) } - - subject { group_child.secret_variables_for('ref', project) } + let!(:group_child_3) { create(:group, parent: group_child_2) } + let!(:variable_child_3) { create(:ci_group_variable, group: group_child_3) } + let!(:group_child_2) { create(:group, parent: group_child) } + let!(:variable_child_2) { create(:ci_group_variable, group: group_child_2) } it 'returns all variables belong to the group and parent groups' do - is_expected.to contain_exactly(secret_variable, protected_variable, variable_child) + expected_array1 = [protected_variable, secret_variable] + expected_array2 = [variable_child, variable_child_2, variable_child_3] + got_array = group_child_3.secret_variables_for('ref', project).to_a + + expect(got_array.shift(2)).to contain_exactly(*expected_array1) + expect(got_array).to eq(expected_array2) end end end -- cgit v1.2.1 From 1ee9f7db83fb0e33b9cffbf437d20db343afd8a3 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 7 Jul 2017 16:27:42 +0900 Subject: Remove a spec: validate_uniqueness_of for key --- spec/models/ci/pipeline_schedule_variable_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb index 9c0b0153e03..0de76a57b7f 100644 --- a/spec/models/ci/pipeline_schedule_variable_spec.rb +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -4,5 +4,4 @@ describe Ci::PipelineScheduleVariable, models: true do subject { build(:ci_pipeline_schedule_variable) } it { is_expected.to include_module(HasVariable) } - it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } end -- cgit v1.2.1 From 38fd773bd3bb7ff479ca3d607da6966139e262e3 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 7 Jul 2017 10:57:34 +0100 Subject: Fix ShaAttribute concern when there is no table When this is added to a new model, it would fail before the migrations were run - including when trying to run migrations in production mode! --- spec/models/concerns/sha_attribute_spec.rb | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 9e37c2b20c4..610793ee557 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -13,15 +13,34 @@ describe ShaAttribute do end describe '#sha_attribute' do - it 'defines a SHA attribute for a binary column' do - expect(model).to receive(:attribute) - .with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute)) + context' when the table exists' do + before do + allow(model).to receive(:table_exists?).and_return(true) + end - model.sha_attribute(:sha1) + it 'defines a SHA attribute for a binary column' do + expect(model).to receive(:attribute) + .with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute)) + + model.sha_attribute(:sha1) + end + + it 'raises ArgumentError when the column type is not :binary' do + expect { model.sha_attribute(:name) }.to raise_error(ArgumentError) + end end - it 'raises ArgumentError when the column type is not :binary' do - expect { model.sha_attribute(:name) }.to raise_error(ArgumentError) + context' when the table does not exist' do + before do + allow(model).to receive(:table_exists?).and_return(false) + end + + it 'does nothing' do + expect(model).not_to receive(:columns) + expect(model).not_to receive(:attribute) + + model.sha_attribute(:name) + end end end end -- cgit v1.2.1 From 4c0864fd9e14cda78cacdfbbc2f3072b699ebb9b Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 7 Jul 2017 12:56:09 +0100 Subject: Speed up `all_commit_shas` for new merge requests For merge requests created after 9.4, we have a `merge_request_diff_commits` table we can get all the SHAs from very quickly. We just need to exclude these when we load from the legacy format, by ignoring diffs with no serialised commits. Once these have been migrated in the background, every MR will see this improvement. --- spec/models/merge_request_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index ea405fabff0..1eadc28869f 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -803,7 +803,7 @@ describe MergeRequest, models: true do shared_examples 'returning all SHA' do it 'returns all SHA from all merge_request_diffs' do expect(subject.merge_request_diffs.size).to eq(2) - expect(subject.all_commit_shas).to eq(all_commit_shas) + expect(subject.all_commit_shas).to match_array(all_commit_shas) end end -- cgit v1.2.1 From ff78af152cc3054a7bb76af718943dca7a69a3c5 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 7 Jul 2017 14:49:05 +0200 Subject: Added EachBatch for iterating tables in batches This module provides a class method called `each_batch` that can be used to iterate tables in batches in a more efficient way compared to Rails' `in_batches` method. This commit also includes a RuboCop cop to blacklist the use of `in_batches` in favour of this new method. --- spec/models/concerns/each_batch_spec.rb | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 spec/models/concerns/each_batch_spec.rb (limited to 'spec/models') diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb new file mode 100644 index 00000000000..951690a217b --- /dev/null +++ b/spec/models/concerns/each_batch_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe EachBatch do + describe '.each_batch' do + let(:model) do + Class.new(ActiveRecord::Base) do + include EachBatch + + self.table_name = 'users' + end + end + + before do + 5.times { create(:user, updated_at: 1.day.ago) } + end + + it 'yields an ActiveRecord::Relation when a block is given' do + model.each_batch do |relation| + expect(relation).to be_a_kind_of(ActiveRecord::Relation) + end + end + + it 'yields a batch index as the second argument' do + model.each_batch do |_, index| + expect(index).to eq(1) + end + end + + it 'accepts a custom batch size' do + amount = 0 + + model.each_batch(of: 1) { amount += 1 } + + expect(amount).to eq(5) + end + + it 'does not include ORDER BYs in the yielded relations' do + model.each_batch do |relation| + expect(relation.to_sql).not_to include('ORDER BY') + end + end + + it 'allows updating of the yielded relations' do + time = Time.now + + model.each_batch do |relation| + relation.update_all(updated_at: time) + end + + expect(model.where(updated_at: time).count).to eq(5) + end + end +end -- cgit v1.2.1 From b5f596c3ffb655b6e4fee127fa9336c829198b5b Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 7 Jul 2017 15:08:49 +0000 Subject: Native group milestones --- spec/models/milestone_spec.rb | 44 ++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'spec/models') diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 45953023a36..2649d04bee3 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -6,9 +6,6 @@ describe Milestone, models: true do allow(subject).to receive(:set_iid).and_return(false) end - it { is_expected.to validate_presence_of(:title) } - it { is_expected.to validate_presence_of(:project) } - describe 'start_date' do it 'adds an error when start_date is greated then due_date' do milestone = build(:milestone, start_date: Date.tomorrow, due_date: Date.yesterday) @@ -37,17 +34,42 @@ describe Milestone, models: true do end end - describe "unique milestone title per project" do - it "does not accept the same title in a project twice" do - new_milestone = Milestone.new(project: milestone.project, title: milestone.title) - expect(new_milestone).not_to be_valid + describe "unique milestone title" do + context "per project" do + it "does not accept the same title in a project twice" do + new_milestone = Milestone.new(project: milestone.project, title: milestone.title) + expect(new_milestone).not_to be_valid + end + + it "accepts the same title in another project" do + project = create(:empty_project) + new_milestone = Milestone.new(project: project, title: milestone.title) + + expect(new_milestone).to be_valid + end end - it "accepts the same title in another project" do - project = build(:empty_project) - new_milestone = Milestone.new(project: project, title: milestone.title) + context "per group" do + let(:group) { create(:group) } + let(:milestone) { create(:milestone, group: group) } + + before do + project.update(group: group) + end + + it "does not accept the same title in a group twice" do + new_milestone = Milestone.new(group: group, title: milestone.title) + + expect(new_milestone).not_to be_valid + end - expect(new_milestone).to be_valid + it "does not accept the same title of a child project milestone" do + create(:milestone, project: group.projects.first) + + new_milestone = Milestone.new(group: group, title: milestone.title) + + expect(new_milestone).not_to be_valid + end end end -- cgit v1.2.1 From c81928cfa757b6f42debd6d1c3b6cdb860fc14f5 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 7 Jul 2017 10:43:37 -0500 Subject: Include new URL helpers retroactively into includers of Gitlab::Routing --- spec/models/project_services/jira_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 4a1de76f099..105afed1337 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe JiraService, models: true do - include Gitlab::Routing.url_helpers + include Gitlab::Routing describe "Associations" do it { is_expected.to belong_to :project } -- cgit v1.2.1 From 1271349d7410f7f28c7ce0ef96b807f4cebbd20f Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Fri, 7 Jul 2017 17:34:08 +0100 Subject: Fix typo in SHA attribute spec --- spec/models/concerns/sha_attribute_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 610793ee557..87403969fe0 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -30,7 +30,7 @@ describe ShaAttribute do end end - context' when the table does not exist' do + context 'when the table does not exist' do before do allow(model).to receive(:table_exists?).and_return(false) end -- cgit v1.2.1 From 33039ffdb5b6b9c9f9b0ca53b2084ab37cba60ec Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 7 Jul 2017 11:06:31 -0700 Subject: Fix another typo in SHA attribute spec --- spec/models/concerns/sha_attribute_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 87403969fe0..21893e0cbaa 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -13,7 +13,7 @@ describe ShaAttribute do end describe '#sha_attribute' do - context' when the table exists' do + context 'when the table exists' do before do allow(model).to receive(:table_exists?).and_return(true) end -- cgit v1.2.1 From 09aec2124608977e088c93ada969132c79525d2a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 7 Jul 2017 14:34:04 -0400 Subject: Mark a subgroup-related spec as PostgreSQL-only Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/34847 --- spec/models/group_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec/models') diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 399020953e8..066d7b9307f 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -466,13 +466,13 @@ describe Group, models: true do it_behaves_like 'ref is protected' end - context 'when group has children' do - let!(:group_child) { create(:group, parent: group) } - let!(:variable_child) { create(:ci_group_variable, group: group_child) } - let!(:group_child_3) { create(:group, parent: group_child_2) } - let!(:variable_child_3) { create(:ci_group_variable, group: group_child_3) } - let!(:group_child_2) { create(:group, parent: group_child) } - let!(:variable_child_2) { create(:ci_group_variable, group: group_child_2) } + context 'when group has children', :postgresql do + let(:group_child) { create(:group, parent: group) } + let(:group_child_2) { create(:group, parent: group_child) } + let(:group_child_3) { create(:group, parent: group_child_2) } + let(:variable_child) { create(:ci_group_variable, group: group_child) } + let(:variable_child_2) { create(:ci_group_variable, group: group_child_2) } + let(:variable_child_3) { create(:ci_group_variable, group: group_child_3) } it 'returns all variables belong to the group and parent groups' do expected_array1 = [protected_variable, secret_variable] -- cgit v1.2.1