From cdcc196c1fb602303a4fae36a584005ef212b9c8 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 26 Aug 2017 11:17:47 +0200 Subject: Make it possible to access deployment details from pipeline --- spec/models/ci/pipeline_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index ac75c6501ee..eea494a22b6 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -27,6 +27,14 @@ describe Ci::Pipeline, :mailer do it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :short_sha } + describe '#project_deployment_variables' do + it 'delegates deployment variables to project' do + expect(pipeline) + .to delegate_method(:deployment_variables) + .to(:project).with_prefix + end + end + describe '#source' do context 'when creating new pipeline' do let(:pipeline) do -- cgit v1.2.1 From ae99f74b77fc0f49a9efd5f71119e7de4e313629 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 26 Aug 2017 11:18:18 +0200 Subject: Improve kubernetes service specs readability --- spec/models/project_services/kubernetes_service_spec.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 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 b1743cd608e..537cdadd528 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -203,18 +203,13 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do describe '#predefined_variables' do let(:kubeconfig) do - config = - YAML.load(File.read(expand_fixture_path('config/kubeconfig.yml'))) - - config.dig('users', 0, 'user')['token'] = - 'token' - + config_file = expand_fixture_path('config/kubeconfig.yml') + config = YAML.load(File.read(config_file)) + config.dig('users', 0, 'user')['token'] = 'token' + config.dig('contexts', 0, 'context')['namespace'] = namespace config.dig('clusters', 0, 'cluster')['certificate-authority-data'] = Base64.encode64('CA PEM DATA') - config.dig('contexts', 0, 'context')['namespace'] = - namespace - YAML.dump(config) end -- cgit v1.2.1 From 326dc7da3bb7e6537095277dc8ee8ae880774b62 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 26 Aug 2017 12:45:36 +0200 Subject: Check if kubernetes required before creating a job --- spec/models/ci/pipeline_spec.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index eea494a22b6..b298b0b1354 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -542,6 +542,46 @@ describe Ci::Pipeline, :mailer do end end + context 'when kubernetes is configured' do + let(:project) { create(:kubernetes_project) } + + before do + create(:ci_variable, key: 'KUBE_DOMAIN', + protected: false, + project: project) + end + + describe '#variables' do + it 'returns kubernetes-related variables' do + variables = pipeline.variables.map { |v| v.fetch(:key) } + + expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN' + end + end + + describe '#has_kubernetes_available?' do + it 'returns true' do + expect(pipeline).to have_kubernetes_available + end + end + end + + context 'when kubernetes is not configured' do + describe '#variables' do + it 'does not return kubernetes related variables' do + variables = pipeline.variables.map { |v| v.fetch(:key) } + + expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN' + end + end + + describe '#has_kubernetes_available?' do + it 'returns false' do + expect(pipeline).not_to have_kubernetes_available + end + end + end + describe '#has_stage_seeds?' do context 'when pipeline has stage seeds' do subject { build(:ci_pipeline_with_one_job) } -- cgit v1.2.1 From 59e5393827e9e9eddb9bb0a960f1cda1f6d9511d Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Wed, 23 Aug 2017 19:54:14 +0900 Subject: Fuzzy search issuable title or description --- spec/models/concerns/issuable_spec.rb | 42 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index dfbe1a7c192..37f6fd3a25b 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -66,56 +66,76 @@ describe Issuable do end describe ".search" do - let!(:searchable_issue) { create(:issue, title: "Searchable issue") } + let!(:searchable_issue) { create(:issue, title: "Searchable awesome issue") } - it 'returns notes with a matching title' do + it 'returns issues with a matching title' do expect(issuable_class.search(searchable_issue.title)) .to eq([searchable_issue]) end - it 'returns notes with a partially matching title' do + it 'returns issues with a partially matching title' do expect(issuable_class.search('able')).to eq([searchable_issue]) end - it 'returns notes with a matching title regardless of the casing' do + it 'returns issues with a matching title regardless of the casing' do expect(issuable_class.search(searchable_issue.title.upcase)) .to eq([searchable_issue]) end + + it 'returns issues with a fuzzy matching title' do + expect(issuable_class.search('searchable issue')).to eq([searchable_issue]) + end + + it 'returns all issues with a query shorter than 3 chars' do + expect(issuable_class.search('zz')).to eq(issuable_class.all) + end end describe ".full_search" do let!(:searchable_issue) do - create(:issue, title: "Searchable issue", description: 'kittens') + create(:issue, title: "Searchable awesome issue", description: 'Many cute kittens') end - it 'returns notes with a matching title' do + it 'returns issues with a matching title' do expect(issuable_class.full_search(searchable_issue.title)) .to eq([searchable_issue]) end - it 'returns notes with a partially matching title' do + it 'returns issues with a partially matching title' do expect(issuable_class.full_search('able')).to eq([searchable_issue]) end - it 'returns notes with a matching title regardless of the casing' do + it 'returns issues with a matching title regardless of the casing' do expect(issuable_class.full_search(searchable_issue.title.upcase)) .to eq([searchable_issue]) end - it 'returns notes with a matching description' do + it 'returns issues with a fuzzy matching title' do + expect(issuable_class.full_search('searchable issue')).to eq([searchable_issue]) + end + + it 'returns issues with a matching description' do expect(issuable_class.full_search(searchable_issue.description)) .to eq([searchable_issue]) end - it 'returns notes with a partially matching description' do + it 'returns issues with a partially matching description' do expect(issuable_class.full_search(searchable_issue.description)) .to eq([searchable_issue]) end - it 'returns notes with a matching description regardless of the casing' do + it 'returns issues with a matching description regardless of the casing' do expect(issuable_class.full_search(searchable_issue.description.upcase)) .to eq([searchable_issue]) end + + it 'returns issues with a fuzzy matching description' do + expect(issuable_class.full_search('many kittens')).to eq([searchable_issue]) + end + + it 'returns all issues with a query shorter than 3 chars' do + expect(issuable_class.search('zz')).to eq(issuable_class.all) + end end describe '.to_ability_name' do -- cgit v1.2.1 From 96a7e1628a895dcc39e6299052cb78e62d59459d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 31 Aug 2017 13:24:03 +0200 Subject: Refactor context variables in pipeline model class --- spec/models/ci/pipeline_spec.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index b298b0b1354..11838b1ee07 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -27,14 +27,6 @@ describe Ci::Pipeline, :mailer do it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :short_sha } - describe '#project_deployment_variables' do - it 'delegates deployment variables to project' do - expect(pipeline) - .to delegate_method(:deployment_variables) - .to(:project).with_prefix - end - end - describe '#source' do context 'when creating new pipeline' do let(:pipeline) do @@ -551,9 +543,9 @@ describe Ci::Pipeline, :mailer do project: project) end - describe '#variables' do + describe '#context_variables' do it 'returns kubernetes-related variables' do - variables = pipeline.variables.map { |v| v.fetch(:key) } + variables = pipeline.context_variables.map { |v| v.fetch(:key) } expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN' end @@ -567,9 +559,9 @@ describe Ci::Pipeline, :mailer do end context 'when kubernetes is not configured' do - describe '#variables' do + describe '#context_variables' do it 'does not return kubernetes related variables' do - variables = pipeline.variables.map { |v| v.fetch(:key) } + variables = pipeline.context_variables.map { |v| v.fetch(:key) } expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN' end -- cgit v1.2.1 From 8ad690b0d4f9db528c40e7f523e6f8219c944d48 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 23 Aug 2017 17:14:21 +0200 Subject: Prepare GitOperationService for move to Gitlab::Git --- spec/models/repository_spec.rb | 62 +++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 40 deletions(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 34e1a955309..a7736185c84 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -886,7 +886,7 @@ describe Repository, models: true do context 'when pre hooks were successful' do it 'runs without errors' do expect_any_instance_of(Gitlab::Git::HooksService).to receive(:execute) - .with(committer, repository, old_rev, blank_sha, 'refs/heads/feature') + .with(committer, repository.raw_repository, old_rev, blank_sha, 'refs/heads/feature') expect { repository.rm_branch(user, 'feature') }.not_to raise_error end @@ -932,20 +932,20 @@ describe Repository, models: true do service = Gitlab::Git::HooksService.new expect(Gitlab::Git::HooksService).to receive(:new).and_return(service) expect(service).to receive(:execute) - .with(committer, target_repository, old_rev, new_rev, updating_ref) + .with(committer, target_repository.raw_repository, old_rev, new_rev, updating_ref) .and_yield(service).and_return(true) end it 'runs without errors' do expect do - GitOperationService.new(committer, repository).with_branch('feature') do + GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end end.not_to raise_error end it 'ensures the autocrlf Git option is set to :input' do - service = GitOperationService.new(committer, repository) + service = GitOperationService.new(committer, repository.raw_repository) expect(service).to receive(:update_autocrlf_option) @@ -956,7 +956,7 @@ describe Repository, models: true do it 'updates the head' do expect(repository.find_branch('feature').dereferenced_target.id).to eq(old_rev) - GitOperationService.new(committer, repository).with_branch('feature') do + GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end @@ -971,13 +971,13 @@ describe Repository, models: true do let(:updating_ref) { 'refs/heads/master' } it 'fetch_ref and create the branch' do - expect(target_project.repository).to receive(:fetch_ref) + expect(target_project.repository.raw_repository).to receive(:fetch_ref) .and_call_original - GitOperationService.new(committer, target_repository) + GitOperationService.new(committer, target_repository.raw_repository) .with_branch( 'master', - start_project: project, + start_repository: project.repository.raw_repository, start_branch_name: 'feature') { new_rev } expect(target_repository.branch_names).to contain_exactly('master') @@ -990,8 +990,8 @@ describe Repository, models: true do it 'does not fetch_ref and just pass the commit' do expect(target_repository).not_to receive(:fetch_ref) - GitOperationService.new(committer, target_repository) - .with_branch('feature', start_project: project) { new_rev } + GitOperationService.new(committer, target_repository.raw_repository) + .with_branch('feature', start_repository: project.repository.raw_repository) { new_rev } end end end @@ -1000,7 +1000,7 @@ describe Repository, models: true do let(:target_project) { create(:project, :empty_repo) } before do - expect(target_project.repository).to receive(:run_git) + expect(target_project.repository.raw_repository).to receive(:run_git) end it 'raises Rugged::ReferenceError' do @@ -1009,9 +1009,9 @@ describe Repository, models: true do end expect do - GitOperationService.new(committer, target_project.repository) + GitOperationService.new(committer, target_project.repository.raw_repository) .with_branch('feature', - start_project: project, + start_repository: project.repository.raw_repository, &:itself) end.to raise_reference_error end @@ -1031,7 +1031,7 @@ describe Repository, models: true do repository.add_branch(user, branch, old_rev) expect do - GitOperationService.new(committer, repository).with_branch(branch) do + GitOperationService.new(committer, repository.raw_repository).with_branch(branch) do new_rev end end.not_to raise_error @@ -1049,7 +1049,7 @@ describe Repository, models: true do # Updating 'master' to new_rev would lose the commits on 'master' that # are not contained in new_rev. This should not be allowed. expect do - GitOperationService.new(committer, repository).with_branch(branch) do + GitOperationService.new(committer, repository.raw_repository).with_branch(branch) do new_rev end end.to raise_error(Repository::CommitError) @@ -1061,31 +1061,13 @@ describe Repository, models: true do allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) expect do - GitOperationService.new(committer, repository).with_branch('feature') do + GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end end.to raise_error(Gitlab::Git::HooksService::PreReceiveError) end end - context 'when target branch is different from source branch' do - before do - allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, '']) - end - - it 'expires branch cache' do - expect(repository).not_to receive(:expire_exists_cache) - expect(repository).not_to receive(:expire_root_ref_cache) - expect(repository).not_to receive(:expire_emptiness_caches) - expect(repository).to receive(:expire_branches_cache) - - GitOperationService.new(committer, repository) - .with_branch('new-feature') do - new_rev - end - end - end - context 'when repository is empty' do before do allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, '']) @@ -1139,7 +1121,7 @@ describe Repository, models: true do describe 'when there are no branches' do before do - allow(repository).to receive(:branch_count).and_return(0) + allow(repository.raw_repository).to receive(:branch_count).and_return(0) end it { is_expected.to eq(false) } @@ -1147,7 +1129,7 @@ describe Repository, models: true do describe 'when there are branches' do it 'returns true' do - expect(repository).to receive(:branch_count).and_return(3) + expect(repository.raw_repository).to receive(:branch_count).and_return(3) expect(subject).to eq(true) end @@ -1161,7 +1143,7 @@ describe Repository, models: true do end it 'sets autocrlf to :input' do - GitOperationService.new(nil, repository).send(:update_autocrlf_option) + GitOperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) expect(repository.raw_repository.autocrlf).to eq(:input) end @@ -1176,7 +1158,7 @@ describe Repository, models: true do expect(repository.raw_repository).not_to receive(:autocrlf=) .with(:input) - GitOperationService.new(nil, repository).send(:update_autocrlf_option) + GitOperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) end end end @@ -1759,14 +1741,14 @@ describe Repository, models: true do describe '#update_ref' do it 'can create a ref' do - GitOperationService.new(nil, repository).send(:update_ref, 'refs/heads/foobar', 'refs/heads/master', Gitlab::Git::BLANK_SHA) + GitOperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/foobar', 'refs/heads/master', Gitlab::Git::BLANK_SHA) expect(repository.find_branch('foobar')).not_to be_nil end it 'raises CommitError when the ref update fails' do expect do - GitOperationService.new(nil, repository).send(:update_ref, 'refs/heads/master', 'refs/heads/master', Gitlab::Git::BLANK_SHA) + GitOperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/master', 'refs/heads/master', Gitlab::Git::BLANK_SHA) end.to raise_error(Repository::CommitError) end end -- cgit v1.2.1 From 0aadf36b4a0d6f1dd1f25f7c54815782bab3596b Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 1 Sep 2017 11:51:55 +0200 Subject: Restore with_branch cache spec --- spec/models/repository_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index a7736185c84..95e11c4af20 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1068,6 +1068,24 @@ describe Repository, models: true do end end + context 'when target branch is different from source branch' do + before do + allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, '']) + end + + it 'expires branch cache' do + expect(repository).not_to receive(:expire_exists_cache) + expect(repository).not_to receive(:expire_root_ref_cache) + expect(repository).not_to receive(:expire_emptiness_caches) + expect(repository).to receive(:expire_branches_cache) + + repository.with_branch(user, 'new-feature') do + new_rev + end + end + end + + context 'when repository is empty' do before do allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, '']) -- cgit v1.2.1 From e81229805d887ad5809db6de982fa35543761d00 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 1 Sep 2017 11:59:27 +0200 Subject: Remove empty line --- spec/models/repository_spec.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 95e11c4af20..ff56ddf0e5e 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1085,7 +1085,6 @@ describe Repository, models: true do end end - context 'when repository is empty' do before do allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([true, '']) -- cgit v1.2.1 From 129d6bf2de3195263553e706d1ecbb04ebb71441 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 1 Sep 2017 12:49:28 +0200 Subject: Fix whitespace --- spec/models/repository_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index ff56ddf0e5e..0c2dcb98ca2 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1080,7 +1080,7 @@ describe Repository, models: true do expect(repository).to receive(:expire_branches_cache) repository.with_branch(user, 'new-feature') do - new_rev + new_rev end end end -- cgit v1.2.1 From 73d0cafbe4acf5a14ec196c3cfb38be4e84b67d9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 1 Sep 2017 12:58:22 +0200 Subject: Check if service active when using CI/CD kubernetes policy --- spec/models/ci/pipeline_spec.rb | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 7898bdbe2ff..cf4896ff188 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -546,42 +546,18 @@ describe Ci::Pipeline, :mailer do end end - context 'when kubernetes is configured' do - let(:project) { create(:kubernetes_project) } + describe '#has_kubernetes_active?' do + context 'when kubernetes is configured' do + let(:project) { create(:kubernetes_project) } - before do - create(:ci_variable, key: 'KUBE_DOMAIN', - protected: false, - project: project) - end - - describe '#context_variables' do - it 'returns kubernetes-related variables' do - variables = pipeline.context_variables.map { |v| v.fetch(:key) } - - expect(variables).to include 'KUBECONFIG', 'KUBE_DOMAIN' - end - end - - describe '#has_kubernetes_available?' do it 'returns true' do - expect(pipeline).to have_kubernetes_available - end - end - end - - context 'when kubernetes is not configured' do - describe '#context_variables' do - it 'does not return kubernetes related variables' do - variables = pipeline.context_variables.map { |v| v.fetch(:key) } - - expect(variables).not_to include 'KUBECONFIG', 'KUBE_DOMAIN' + expect(pipeline).to have_kubernetes_active end end - describe '#has_kubernetes_available?' do + context 'when kubernetes is not configured' do it 'returns false' do - expect(pipeline).not_to have_kubernetes_available + expect(pipeline).not_to have_kubernetes_active end end end -- cgit v1.2.1 From fc4fb6e4d212d5cf406a08c96ba8c423477a5408 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 1 Sep 2017 13:03:43 +0200 Subject: Change CI/CD kubernetes policy keyword to `active` --- spec/models/ci/pipeline_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index cf4896ff188..84656ffe0b9 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -547,7 +547,7 @@ describe Ci::Pipeline, :mailer do end describe '#has_kubernetes_active?' do - context 'when kubernetes is configured' do + context 'when kubernetes is active' do let(:project) { create(:kubernetes_project) } it 'returns true' do @@ -555,7 +555,7 @@ describe Ci::Pipeline, :mailer do end end - context 'when kubernetes is not configured' do + context 'when kubernetes is not active' do it 'returns false' do expect(pipeline).not_to have_kubernetes_active end -- cgit v1.2.1 From 6cdaa27a537662732cb089bdd3483d76a5a56a9a Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 1 Sep 2017 12:11:59 +0200 Subject: Move GitOperationService to Gitlab::Git --- spec/models/repository_spec.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 0c2dcb98ca2..9d6690a9efc 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -938,14 +938,14 @@ describe Repository, models: true do it 'runs without errors' do expect do - GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do + Gitlab::Git::OperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end end.not_to raise_error end it 'ensures the autocrlf Git option is set to :input' do - service = GitOperationService.new(committer, repository.raw_repository) + service = Gitlab::Git::OperationService.new(committer, repository.raw_repository) expect(service).to receive(:update_autocrlf_option) @@ -956,7 +956,7 @@ describe Repository, models: true do it 'updates the head' do expect(repository.find_branch('feature').dereferenced_target.id).to eq(old_rev) - GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do + Gitlab::Git::OperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end @@ -974,7 +974,7 @@ describe Repository, models: true do expect(target_project.repository.raw_repository).to receive(:fetch_ref) .and_call_original - GitOperationService.new(committer, target_repository.raw_repository) + Gitlab::Git::OperationService.new(committer, target_repository.raw_repository) .with_branch( 'master', start_repository: project.repository.raw_repository, @@ -990,7 +990,7 @@ describe Repository, models: true do it 'does not fetch_ref and just pass the commit' do expect(target_repository).not_to receive(:fetch_ref) - GitOperationService.new(committer, target_repository.raw_repository) + Gitlab::Git::OperationService.new(committer, target_repository.raw_repository) .with_branch('feature', start_repository: project.repository.raw_repository) { new_rev } end end @@ -1009,7 +1009,7 @@ describe Repository, models: true do end expect do - GitOperationService.new(committer, target_project.repository.raw_repository) + Gitlab::Git::OperationService.new(committer, target_project.repository.raw_repository) .with_branch('feature', start_repository: project.repository.raw_repository, &:itself) @@ -1031,7 +1031,7 @@ describe Repository, models: true do repository.add_branch(user, branch, old_rev) expect do - GitOperationService.new(committer, repository.raw_repository).with_branch(branch) do + Gitlab::Git::OperationService.new(committer, repository.raw_repository).with_branch(branch) do new_rev end end.not_to raise_error @@ -1049,10 +1049,10 @@ describe Repository, models: true do # Updating 'master' to new_rev would lose the commits on 'master' that # are not contained in new_rev. This should not be allowed. expect do - GitOperationService.new(committer, repository.raw_repository).with_branch(branch) do + Gitlab::Git::OperationService.new(committer, repository.raw_repository).with_branch(branch) do new_rev end - end.to raise_error(Repository::CommitError) + end.to raise_error(Gitlab::Git::CommitError) end end @@ -1061,7 +1061,7 @@ describe Repository, models: true do allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, '']) expect do - GitOperationService.new(committer, repository.raw_repository).with_branch('feature') do + Gitlab::Git::OperationService.new(committer, repository.raw_repository).with_branch('feature') do new_rev end end.to raise_error(Gitlab::Git::HooksService::PreReceiveError) @@ -1160,7 +1160,7 @@ describe Repository, models: true do end it 'sets autocrlf to :input' do - GitOperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) + Gitlab::Git::OperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) expect(repository.raw_repository.autocrlf).to eq(:input) end @@ -1175,7 +1175,7 @@ describe Repository, models: true do expect(repository.raw_repository).not_to receive(:autocrlf=) .with(:input) - GitOperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) + Gitlab::Git::OperationService.new(nil, repository.raw_repository).send(:update_autocrlf_option) end end end @@ -1758,15 +1758,15 @@ describe Repository, models: true do describe '#update_ref' do it 'can create a ref' do - GitOperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/foobar', 'refs/heads/master', Gitlab::Git::BLANK_SHA) + Gitlab::Git::OperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/foobar', 'refs/heads/master', Gitlab::Git::BLANK_SHA) expect(repository.find_branch('foobar')).not_to be_nil end it 'raises CommitError when the ref update fails' do expect do - GitOperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/master', 'refs/heads/master', Gitlab::Git::BLANK_SHA) - end.to raise_error(Repository::CommitError) + Gitlab::Git::OperationService.new(nil, repository.raw_repository).send(:update_ref, 'refs/heads/master', 'refs/heads/master', Gitlab::Git::BLANK_SHA) + end.to raise_error(Gitlab::Git::CommitError) end end -- cgit v1.2.1 From 75130a41ba19b80ac7b2300721915787ac4681bf Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 24 Aug 2017 17:08:32 +0900 Subject: Remove CreateTriggerRequestService and forbit to save variables on Ci::TriggerRequest --- spec/models/ci/trigger_request_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/models/ci/trigger_request_spec.rb (limited to 'spec/models') diff --git a/spec/models/ci/trigger_request_spec.rb b/spec/models/ci/trigger_request_spec.rb new file mode 100644 index 00000000000..32d6f835c73 --- /dev/null +++ b/spec/models/ci/trigger_request_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Ci::TriggerRequest do + describe 'validation' do + it 'be invalid if saving a variable' do + trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } ) + + expect(trigger.valid?).to be_falsey + end + + it 'be valid if not saving a variable' do + trigger = build(:ci_trigger_request) + + expect(trigger.valid?).to be_truthy + end + end +end -- cgit v1.2.1 From acc7497855167d4f6ba481422112645a1a04a885 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Sat, 26 Aug 2017 04:04:57 +0900 Subject: Revert autheticate! in Trigger API --- 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 3fe3ec17d36..c0ac4816ae1 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1492,7 +1492,7 @@ describe Ci::Build do 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) } + let(:trigger_request) { create(:ci_trigger_request_with_variables, pipeline: pipeline, trigger: trigger) } # TODO: let(:user_trigger_variable) do { key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1', public: false } end -- cgit v1.2.1 From cff104ec4b0dd2c53ed907ab7ca423b7c587dee8 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 28 Aug 2017 23:29:28 +0900 Subject: Fix spec --- 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 c0ac4816ae1..3fe3ec17d36 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1492,7 +1492,7 @@ describe Ci::Build do 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) } # TODO: + let(:trigger_request) { create(:ci_trigger_request_with_variables, pipeline: pipeline, trigger: trigger) } let(:user_trigger_variable) do { key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1', public: false } end -- cgit v1.2.1 From d614c431055286eaab3b82e810186ac19a2c4fd7 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 1 Sep 2017 00:17:56 +0900 Subject: Fix trigger_request.variables --- spec/models/ci/trigger_request_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/trigger_request_spec.rb b/spec/models/ci/trigger_request_spec.rb index 32d6f835c73..7dcf3528f73 100644 --- a/spec/models/ci/trigger_request_spec.rb +++ b/spec/models/ci/trigger_request_spec.rb @@ -5,13 +5,13 @@ describe Ci::TriggerRequest do it 'be invalid if saving a variable' do trigger = build(:ci_trigger_request, variables: { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } ) - expect(trigger.valid?).to be_falsey + expect(trigger).not_to be_valid end it 'be valid if not saving a variable' do trigger = build(:ci_trigger_request) - expect(trigger.valid?).to be_truthy + expect(trigger).to be_valid end end end -- cgit v1.2.1 From 3ae2038176b27673b06a040873fdbe19c94d67d3 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Sat, 2 Sep 2017 02:37:11 +0900 Subject: Remove ci_trigger_request_with_variables --- spec/models/ci/build_spec.rb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 3fe3ec17d36..08d22f166e4 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1492,10 +1492,12 @@ describe Ci::Build do 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) } + let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) } + let(:user_trigger_variable) do - { key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1', public: false } + { key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1', public: false } end + let(:predefined_trigger_variable) do { key: 'CI_PIPELINE_TRIGGERED', value: 'true', public: true } end @@ -1504,8 +1506,26 @@ describe Ci::Build do build.trigger_request = trigger_request end - it { is_expected.to include(user_trigger_variable) } - it { is_expected.to include(predefined_trigger_variable) } + shared_examples 'returns variables for triggers' do + it { is_expected.to include(user_trigger_variable) } + it { is_expected.to include(predefined_trigger_variable) } + end + + context 'when variables are stored in trigger_request' do + before do + trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) + end + + it_behaves_like 'returns variables for triggers' + end + + context 'when variables are stored in pipeline_variables' do + before do + create(:ci_pipeline_variable, pipeline: pipeline, key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1') + end + + it_behaves_like 'returns variables for triggers' + end end context 'when pipeline has a variable' do -- cgit v1.2.1 From fa6b9acaf9759c58353f8407ff20a7d02b8edf92 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 4 Sep 2017 17:17:36 +0900 Subject: trigger_variables should consider trigger_request existstance always --- spec/models/ci/build_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 08d22f166e4..137c460cce8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1690,6 +1690,44 @@ describe Ci::Build do end end + describe '#trigger_variables' do + let(:build) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) } + let(:trigger) { create(:ci_trigger, project: project) } + let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) } + + subject { build.trigger_variables } + + it { is_expected.to eq(true) } + + context 'when variable is stored in ci_pipeline_variables' do + let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline) } + + context 'when pipeline is triggered by trigger API' do + it 'returns variables' do + is_expected.to eq([pipeline_variable.to_runner_variable]) + end + end + + context 'when pipeline is not triggered by trigger API' do + let(:build) { create(:ci_build, pipeline: pipeline) } + + it 'does not return variables' do + is_expected.to eq([]) + end + end + end + + context 'when variable is stored in ci_trigger_requests.variables' do + before do + trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) + end + + it 'returns variables' do + is_expected.to eq(trigger_request.user_variables) + end + end + end + describe 'state transition: any => [:pending]' do let(:build) { create(:ci_build, :created) } -- cgit v1.2.1 From 5b88bd81f52b454c80c54bef9951bdb8cf607238 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Mon, 4 Sep 2017 22:21:47 +0900 Subject: Move trigger_variables to presenter --- spec/models/ci/build_spec.rb | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 137c460cce8..08d22f166e4 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1690,44 +1690,6 @@ describe Ci::Build do end end - describe '#trigger_variables' do - let(:build) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) } - let(:trigger) { create(:ci_trigger, project: project) } - let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) } - - subject { build.trigger_variables } - - it { is_expected.to eq(true) } - - context 'when variable is stored in ci_pipeline_variables' do - let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline) } - - context 'when pipeline is triggered by trigger API' do - it 'returns variables' do - is_expected.to eq([pipeline_variable.to_runner_variable]) - end - end - - context 'when pipeline is not triggered by trigger API' do - let(:build) { create(:ci_build, pipeline: pipeline) } - - it 'does not return variables' do - is_expected.to eq([]) - end - end - end - - context 'when variable is stored in ci_trigger_requests.variables' do - before do - trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) - end - - it 'returns variables' do - is_expected.to eq(trigger_request.user_variables) - end - end - end - describe 'state transition: any => [:pending]' do let(:build) { create(:ci_build, :created) } -- cgit v1.2.1 From dcf09d11447c264f4b4028ea80eea2be913c2f5b Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 31 Aug 2017 03:20:54 +0900 Subject: Implement `failure_reason` on `ci_builds` --- spec/models/ci/build_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 3fe3ec17d36..2f39a9b4b0f 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1710,4 +1710,24 @@ describe Ci::Build do end end end + + describe 'set failure_reason when drop' do + let(:build) { create(:ci_build, :created) } + + before do + build.drop!(reason) + end + + context 'when failure_reason is nil' do + let(:reason) { } + + it { expect(build).to be_no_error } + end + + context 'when failure_reason is script_error' do + let(:reason) { :script_error } + + it { expect(build).to be_failed_by_missing_dependency } + end + end end -- cgit v1.2.1 From 1d7c0390722c96aa66af5b26f5a826b97293dcd6 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 31 Aug 2017 22:03:41 +0900 Subject: Fix enum lists --- spec/models/ci/build_spec.rb | 20 -------------------- spec/models/commit_status_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'spec/models') diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 2f39a9b4b0f..3fe3ec17d36 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1710,24 +1710,4 @@ describe Ci::Build do end end end - - describe 'set failure_reason when drop' do - let(:build) { create(:ci_build, :created) } - - before do - build.drop!(reason) - end - - context 'when failure_reason is nil' do - let(:reason) { } - - it { expect(build).to be_no_error } - end - - context 'when failure_reason is script_error' do - let(:reason) { :script_error } - - it { expect(build).to be_failed_by_missing_dependency } - end - end end diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index f7583645e69..4fd330ab7dc 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -443,4 +443,24 @@ describe CommitStatus do end end end + + describe 'set failure_reason when drop' do + let(:build) { create(:ci_build, :created) } + + before do + build.drop!(reason) + end + + context 'when failure_reason is nil' do + let(:reason) { } + + it { expect(build).to be_unknown_failure } + end + + context 'when failure_reason is job_failure' do + let(:reason) { :job_failure } + + it { expect(build).to be_job_failure } + end + end end -- cgit v1.2.1 From 68f6c61cf621db82ac98d561782590b1866fcf6f Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 1 Sep 2017 16:52:11 +0900 Subject: - Allow runner API to pass failure_reason - Fix spec --- spec/models/commit_status_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 4fd330ab7dc..f5c1db79823 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -445,22 +445,20 @@ describe CommitStatus do end describe 'set failure_reason when drop' do - let(:build) { create(:ci_build, :created) } + let(:commit_status) { create(:commit_status, :created) } - before do - build.drop!(reason) - end + subject { commit_status.drop!(reason); commit_status } context 'when failure_reason is nil' do let(:reason) { } - it { expect(build).to be_unknown_failure } + it { is_expected.to be_unknown_failure } end context 'when failure_reason is job_failure' do let(:reason) { :job_failure } - it { expect(build).to be_job_failure } + it { is_expected.to be_job_failure } end end end -- cgit v1.2.1 From e8e8ae4d7df1de71d9f52e774607ac1ba4cce1cc Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 1 Sep 2017 22:01:26 +0900 Subject: Fix spec --- spec/models/commit_status_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index f5c1db79823..0a6b0023dea 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -447,7 +447,10 @@ describe CommitStatus do describe 'set failure_reason when drop' do let(:commit_status) { create(:commit_status, :created) } - subject { commit_status.drop!(reason); commit_status } + subject do + commit_status.drop!(reason) + commit_status + end context 'when failure_reason is nil' do let(:reason) { } -- cgit v1.2.1 From 38d9b4d77d85e26f827ff9640243494adc8597ed Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 5 Sep 2017 15:10:34 +0900 Subject: Use script_failure. Add runner_system_failure. Improve spec. --- spec/models/commit_status_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/models') diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 0a6b0023dea..858ec831200 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -458,10 +458,10 @@ describe CommitStatus do it { is_expected.to be_unknown_failure } end - context 'when failure_reason is job_failure' do - let(:reason) { :job_failure } + context 'when failure_reason is script_failure' do + let(:reason) { :script_failure } - it { is_expected.to be_job_failure } + it { is_expected.to be_script_failure } end end end -- cgit v1.2.1 From 64855c8e30c53004b2e2c2a65f131f8ab7efa41c Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Thu, 24 Aug 2017 14:21:30 +0200 Subject: match the committer's email against the gpg key the updated verification of a gpg signature requires the committer's email to also match the user's and the key's emails. --- spec/models/gpg_key_spec.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index e48f20bf53b..d436aee6ea3 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -99,14 +99,14 @@ describe GpgKey do end describe '#verified?' do - it 'returns true one of the email addresses in the key belongs to the user' do + it 'returns true if one of the email addresses in the key belongs to the user' do user = create :user, email: 'bette.cartwright@example.com' gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user expect(gpg_key.verified?).to be_truthy end - it 'returns false if one of the email addresses in the key does not belong to the user' do + it 'returns false if none of the email addresses in the key does not belong to the user' do user = create :user, email: 'someone.else@example.com' gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user @@ -114,6 +114,32 @@ describe GpgKey do end end + describe 'verified_and_belongs_to_email?' do + it 'returns false if none of the email addresses in the key does not belong to the user' do + user = create :user, email: 'someone.else@example.com' + gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user + + expect(gpg_key.verified?).to be_falsey + expect(gpg_key.verified_and_belongs_to_email?('someone.else@example.com')).to be_falsey + end + + it 'returns false if one of the email addresses in the key belongs to the user and does not match the provided email' do + user = create :user, email: 'bette.cartwright@example.com' + gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user + + expect(gpg_key.verified?).to be_truthy + expect(gpg_key.verified_and_belongs_to_email?('bette.cartwright@example.net')).to be_falsey + end + + it 'returns true if one of the email addresses in the key belongs to the user and matches the provided email' do + user = create :user, email: 'bette.cartwright@example.com' + gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key, user: user + + expect(gpg_key.verified?).to be_truthy + expect(gpg_key.verified_and_belongs_to_email?('bette.cartwright@example.com')).to be_truthy + end + end + describe 'notification', :mailer do let(:user) { create(:user) } -- cgit v1.2.1 From 98016ef7f395303682f472414b2f109ff8a598f5 Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Mon, 28 Aug 2017 12:27:18 +0200 Subject: add User##verified_email? method --- spec/models/user_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models') diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b70ab5581ac..fd83a58ed9f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2102,4 +2102,18 @@ describe User do end end end + + describe '#verified_email?' do + it 'returns true when the email is the primary email' do + user = build :user, email: 'email@example.com' + + expect(user.verified_email?('email@example.com')).to be true + end + + it 'returns false when the email is not the primary email' do + user = build :user, email: 'email@example.com' + + expect(user.verified_email?('other_email@example.com')).to be false + end + end end -- cgit v1.2.1 From 978252a3fa99414446ce887cd28bf2db5b223d44 Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Wed, 30 Aug 2017 13:27:40 +0200 Subject: use new #verification_status --- spec/models/gpg_key_spec.rb | 8 ++++---- spec/models/gpg_signature_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index d436aee6ea3..9c99c3e5c08 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -155,15 +155,15 @@ describe GpgKey do describe '#revoke' do it 'invalidates all associated gpg signatures and destroys the key' do gpg_key = create :gpg_key - gpg_signature = create :gpg_signature, valid_signature: true, gpg_key: gpg_key + gpg_signature = create :gpg_signature, verification_status: :verified, gpg_key: gpg_key unrelated_gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key - unrelated_gpg_signature = create :gpg_signature, valid_signature: true, gpg_key: unrelated_gpg_key + unrelated_gpg_signature = create :gpg_signature, verification_status: :verified, gpg_key: unrelated_gpg_key gpg_key.revoke expect(gpg_signature.reload).to have_attributes( - valid_signature: false, + verification_status: 'unknown_key', gpg_key: nil ) @@ -171,7 +171,7 @@ describe GpgKey do # unrelated signature is left untouched expect(unrelated_gpg_signature.reload).to have_attributes( - valid_signature: true, + verification_status: 'verified', gpg_key: unrelated_gpg_key ) diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb index c58fd46762a..d77eeda4a79 100644 --- a/spec/models/gpg_signature_spec.rb +++ b/spec/models/gpg_signature_spec.rb @@ -25,4 +25,34 @@ RSpec.describe GpgSignature do gpg_signature.commit end end + + describe '#verified?' do + it 'returns true when `verification_status` is not set, but `valid_signature` is true' do + signature = create :gpg_signature, valid_signature: true, verification_status: nil + + expect(signature.verified?).to be true + expect(signature.reload.verified?).to be true + end + + it 'returns true when `verification_status` is set to :verified' do + signature = create :gpg_signature, verification_status: :verified + + expect(signature.verified?).to be true + expect(signature.reload.verified?).to be true + end + + it 'returns false when `verification_status` is set to :unknown_key' do + signature = create :gpg_signature, verification_status: :unknown_key + + expect(signature.verified?).to be false + expect(signature.reload.verified?).to be false + end + + it 'returns false when `verification_status` is not set, but `valid_signature` is false' do + signature = create :gpg_signature, valid_signature: false, verification_status: nil + + expect(signature.verified?).to be false + expect(signature.reload.verified?).to be false + end + end end -- cgit v1.2.1 From b62c1620ea8d4260bb60303d4825a214c7ed56ee Mon Sep 17 00:00:00 2001 From: Alexis Reigel Date: Thu, 31 Aug 2017 20:43:24 +0200 Subject: drop backwards compatibility for valid_signature --- spec/models/gpg_signature_spec.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'spec/models') diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb index d77eeda4a79..c58fd46762a 100644 --- a/spec/models/gpg_signature_spec.rb +++ b/spec/models/gpg_signature_spec.rb @@ -25,34 +25,4 @@ RSpec.describe GpgSignature do gpg_signature.commit end end - - describe '#verified?' do - it 'returns true when `verification_status` is not set, but `valid_signature` is true' do - signature = create :gpg_signature, valid_signature: true, verification_status: nil - - expect(signature.verified?).to be true - expect(signature.reload.verified?).to be true - end - - it 'returns true when `verification_status` is set to :verified' do - signature = create :gpg_signature, verification_status: :verified - - expect(signature.verified?).to be true - expect(signature.reload.verified?).to be true - end - - it 'returns false when `verification_status` is set to :unknown_key' do - signature = create :gpg_signature, verification_status: :unknown_key - - expect(signature.verified?).to be false - expect(signature.reload.verified?).to be false - end - - it 'returns false when `verification_status` is not set, but `valid_signature` is false' do - signature = create :gpg_signature, valid_signature: false, verification_status: nil - - expect(signature.verified?).to be false - expect(signature.reload.verified?).to be false - end - end end -- cgit v1.2.1 From 66cfb901c0df6eb5741721e901b66fbe82e183ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= Date: Tue, 5 Sep 2017 11:03:24 -0500 Subject: Optimize SQL queries used in Groups::GroupMembersController#create The following optimizations were performed: - Add new association to GroupMember and ProjectMember This new association will allow us to check if a user is a member of a Project or Group through a single query instead of two. - Optimize retrieving of Members when adding multiple Users --- spec/models/group_spec.rb | 19 +++---------------- spec/models/member_spec.rb | 9 +++++++++ spec/models/project_spec.rb | 19 +++---------------- 3 files changed, 15 insertions(+), 32 deletions(-) (limited to 'spec/models') diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index f9cd12c0ff3..f36d6eeb327 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -9,6 +9,7 @@ describe Group do it { is_expected.to have_many(:users).through(:group_members) } it { is_expected.to have_many(:owners).through(:group_members) } it { is_expected.to have_many(:requesters).dependent(:destroy) } + it { is_expected.to have_many(:members_and_requesters) } it { is_expected.to have_many(:project_group_links).dependent(:destroy) } it { is_expected.to have_many(:shared_projects).through(:project_group_links) } it { is_expected.to have_many(:notification_settings).dependent(:destroy) } @@ -25,22 +26,8 @@ describe Group do group.add_developer(developer) end - describe '#members' do - it 'includes members and exclude requesters' do - member_user_ids = group.members.pluck(:user_id) - - expect(member_user_ids).to include(developer.id) - expect(member_user_ids).not_to include(requester.id) - end - end - - describe '#requesters' do - it 'does not include requesters' do - requester_user_ids = group.requesters.pluck(:user_id) - - expect(requester_user_ids).to include(requester.id) - expect(requester_user_ids).not_to include(developer.id) - end + it_behaves_like 'members and requesters associations' do + let(:namespace) { group } end end end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 87513e18b25..a07ce05a865 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -409,6 +409,15 @@ describe Member do expect(members).to be_a Array expect(members).to be_empty end + + it 'supports differents formats' do + list = ['joe@local.test', admin, user1.id, user2.id.to_s] + + members = described_class.add_users(source, list, :master) + + expect(members.size).to eq(4) + expect(members.first).to be_invite + end end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index be1ae295f75..1f7c6a82b91 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -74,6 +74,7 @@ describe Project do 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) } + it { is_expected.to have_many(:members_and_requesters) } context 'after initialized' do it "has a project_feature" do @@ -90,22 +91,8 @@ describe Project do project.team << [developer, :developer] end - describe '#members' do - it 'includes members and exclude requesters' do - member_user_ids = project.members.pluck(:user_id) - - expect(member_user_ids).to include(developer.id) - expect(member_user_ids).not_to include(requester.id) - end - end - - describe '#requesters' do - it 'does not include requesters' do - requester_user_ids = project.requesters.pluck(:user_id) - - expect(requester_user_ids).to include(requester.id) - expect(requester_user_ids).not_to include(developer.id) - end + it_behaves_like 'members and requesters associations' do + let(:namespace) { project } end end -- cgit v1.2.1 From e8f29569bcb4a2d732a2c00b34958f58d5622836 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 5 Sep 2017 16:49:05 +0100 Subject: Resolve outdated diff discussions on push --- spec/models/merge_request_spec.rb | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'spec/models') diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index f5d079c27c4..d80d5657c42 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1262,7 +1262,6 @@ describe MergeRequest do describe "#reload_diff" do let(:discussion) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject).to_discussion } - let(:commit) { subject.project.commit(sample_commit.id) } it "does not change existing merge request diff" do @@ -1280,9 +1279,19 @@ describe MergeRequest do subject.reload_diff end - it "updates diff discussion positions" do - old_diff_refs = subject.diff_refs + it "calls update_diff_discussion_positions" do + expect(subject).to receive(:update_diff_discussion_positions) + + subject.reload_diff + end + end + describe '#update_diff_discussion_positions' do + let(:discussion) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject).to_discussion } + let(:commit) { subject.project.commit(sample_commit.id) } + let(:old_diff_refs) { subject.diff_refs } + + before do # Update merge_request_diff so that #diff_refs will return commit.diff_refs allow(subject).to receive(:create_merge_request_diff) do subject.merge_request_diffs.create( @@ -1293,7 +1302,9 @@ describe MergeRequest do subject.merge_request_diff(true) end + end + it "updates diff discussion positions" do expect(Discussions::UpdateDiffPositionService).to receive(:new).with( subject.project, subject.author, @@ -1305,7 +1316,26 @@ describe MergeRequest do expect_any_instance_of(Discussions::UpdateDiffPositionService).to receive(:execute).with(discussion).and_call_original expect_any_instance_of(DiffNote).to receive(:save).once - subject.reload_diff(subject.author) + subject.update_diff_discussion_positions(old_diff_refs: old_diff_refs, + new_diff_refs: commit.diff_refs, + current_user: subject.author) + end + + context 'when resolve_outdated_diff_discussions is set' do + before do + discussion + + subject.project.update!(resolve_outdated_diff_discussions: true) + end + + it 'calls MergeRequests::ResolvedDiscussionNotificationService' do + expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService) + .to receive(:execute).with(subject) + + subject.update_diff_discussion_positions(old_diff_refs: old_diff_refs, + new_diff_refs: commit.diff_refs, + current_user: subject.author) + end end end -- cgit v1.2.1 From b40941db14091bce20fd5edc9bb04b82a7eb21b9 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 5 Sep 2017 18:51:08 +0100 Subject: Fix note resolution specs --- spec/models/concerns/resolvable_note_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'spec/models') diff --git a/spec/models/concerns/resolvable_note_spec.rb b/spec/models/concerns/resolvable_note_spec.rb index d00faa4f8be..91591017587 100644 --- a/spec/models/concerns/resolvable_note_spec.rb +++ b/spec/models/concerns/resolvable_note_spec.rb @@ -189,8 +189,8 @@ describe Note, ResolvableNote do allow(subject).to receive(:resolvable?).and_return(false) end - it "returns nil" do - expect(subject.resolve!(current_user)).to be_nil + it "returns false" do + expect(subject.resolve!(current_user)).to be_falsey end it "doesn't set resolved_at" do @@ -224,8 +224,8 @@ describe Note, ResolvableNote do subject.resolve!(user) end - it "returns nil" do - expect(subject.resolve!(current_user)).to be_nil + it "returns false" do + expect(subject.resolve!(current_user)).to be_falsey end it "doesn't change resolved_at" do @@ -279,8 +279,8 @@ describe Note, ResolvableNote do allow(subject).to receive(:resolvable?).and_return(false) end - it "returns nil" do - expect(subject.unresolve!).to be_nil + it "returns false" do + expect(subject.unresolve!).to be_falsey end end @@ -320,8 +320,8 @@ describe Note, ResolvableNote do end context "when not resolved" do - it "returns nil" do - expect(subject.unresolve!).to be_nil + it "returns false" do + expect(subject.unresolve!).to be_falsey end end end -- cgit v1.2.1