diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 21:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 21:08:47 +0300 |
commit | 6b9d3a4e8351e662c4586b24bb152de78ae9e3bf (patch) | |
tree | 883e9db60c047c54418fc1d2b1c5517f97e0f185 /spec/services | |
parent | 23288f62da73fb0e30d8e7ce306665e8fda1b932 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/akismet_service_spec.rb | 1 | ||||
-rw-r--r-- | spec/services/issues/create_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/metrics/dashboard/clone_dashboard_service_spec.rb | 27 | ||||
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 38 | ||||
-rw-r--r-- | spec/services/spam/spam_check_service_spec.rb (renamed from spec/services/spam_check_service_spec.rb) | 2 |
5 files changed, 40 insertions, 30 deletions
diff --git a/spec/services/akismet_service_spec.rb b/spec/services/akismet_service_spec.rb index 4f1c23b701b..355ff1611a0 100644 --- a/spec/services/akismet_service_spec.rb +++ b/spec/services/akismet_service_spec.rb @@ -19,7 +19,6 @@ describe AkismetService do end shared_examples 'no activity if Akismet is not enabled' do |method_call| - # if the method name is `submit`, it requires an argument, so add it before do stub_application_setting(akismet_enabled: false) end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index bb68a8dcbbb..3246578c743 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -385,7 +385,7 @@ describe Issues::CreateService do context 'when recaptcha was not verified' do before do - expect_next_instance_of(SpamCheckService) do |spam_service| + expect_next_instance_of(Spam::SpamCheckService) do |spam_service| expect(spam_service).to receive_messages(check_for_spam?: true) end end diff --git a/spec/services/metrics/dashboard/clone_dashboard_service_spec.rb b/spec/services/metrics/dashboard/clone_dashboard_service_spec.rb index 274d594fd68..20583ff77e9 100644 --- a/spec/services/metrics/dashboard/clone_dashboard_service_spec.rb +++ b/spec/services/metrics/dashboard/clone_dashboard_service_spec.rb @@ -5,6 +5,8 @@ require 'spec_helper' describe Metrics::Dashboard::CloneDashboardService, :use_clean_rails_memory_store_caching do include MetricsDashboardHelpers + STAGES = ::Gitlab::Metrics::Dashboard::Stages + set(:user) { create(:user) } set(:project) { create(:project, :repository) } set(:environment) { create(:environment, project: project) } @@ -16,6 +18,7 @@ describe Metrics::Dashboard::CloneDashboardService, :use_clean_rails_memory_stor let(:branch) { "dashboard_new_branch" } let(:dashboard) { 'config/prometheus/common_metrics.yml' } let(:file_name) { 'custom_dashboard.yml' } + let(:file_content_hash) { YAML.safe_load(File.read(dashboard)) } let(:params) do { dashboard: dashboard, @@ -25,17 +28,6 @@ describe Metrics::Dashboard::CloneDashboardService, :use_clean_rails_memory_stor } end - let(:dashboard_attrs) do - { - commit_message: commit_message, - branch_name: branch, - start_branch: project.default_branch, - encoding: 'text', - file_path: ".gitlab/dashboards/#{file_name}", - file_content: File.read(dashboard) - } - end - context 'user does not have push right to repository' do it_behaves_like 'misconfigured dashboard service response', :forbidden, %q(You can't commit to this project) end @@ -72,11 +64,12 @@ describe Metrics::Dashboard::CloneDashboardService, :use_clean_rails_memory_stor start_branch: project.default_branch, encoding: 'text', file_path: ".gitlab/dashboards/custom_dashboard.yml", - file_content: File.read(dashboard) + file_content: file_content_hash.to_yaml } end it 'strips target file name to safe value', :aggregate_failures do + allow(::Gitlab::Metrics::Dashboard::Processor).to receive(:new).and_return(double(process: file_content_hash)) service_instance = instance_double(::Files::CreateService) expect(::Files::CreateService).to receive(:new).with(project, user, dashboard_attrs).and_return(service_instance) expect(service_instance).to receive(:execute).and_return(status: :success) @@ -86,14 +79,12 @@ describe Metrics::Dashboard::CloneDashboardService, :use_clean_rails_memory_stor end context 'valid parameters' do - it 'delegates commit creation to Files::CreateService', :aggregate_failures do - service_instance = instance_double(::Files::CreateService) - expect(::Files::CreateService).to receive(:new).with(project, user, dashboard_attrs).and_return(service_instance) - expect(service_instance).to receive(:execute).and_return(status: :success) - - service_call + before do + allow(::Gitlab::Metrics::Dashboard::Processor).to receive(:new).and_return(double(process: file_content_hash)) end + it_behaves_like 'valid dashboard cloning process', ::Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH, [STAGES::CommonMetricsInserter, STAGES::ProjectMetricsInserter, STAGES::Sorter] + context 'selected branch already exists' do let(:branch) { 'existing_branch' } diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index 298867f483b..fe31dafdd03 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -47,11 +47,12 @@ describe Projects::TransferService do end end - it 'disk path has moved' do + it 'moves the disk path', :aggregate_failures do old_path = project.repository.disk_path old_full_path = project.repository.full_path transfer_project(project, user, group) + project.reload_repository! expect(project.repository.disk_path).not_to eq(old_path) expect(project.repository.full_path).not_to eq(old_full_path) @@ -298,22 +299,41 @@ describe Projects::TransferService do end context 'when hashed storage in use' do - let(:hashed_project) { create(:project, :repository, namespace: user.namespace) } + let!(:hashed_project) { create(:project, :repository, namespace: user.namespace) } + let!(:old_disk_path) { hashed_project.repository.disk_path } before do group.add_owner(user) end - it 'does not move the directory' do - old_path = hashed_project.repository.disk_path - old_full_path = hashed_project.repository.full_path + it 'does not move the disk path', :aggregate_failures do + new_full_path = "#{group.full_path}/#{hashed_project.path}" transfer_project(hashed_project, user, group) - project.reload + hashed_project.reload_repository! - expect(hashed_project.repository.disk_path).to eq(old_path) - expect(hashed_project.repository.full_path).to eq(old_full_path) - expect(hashed_project.disk_path).to eq(old_path) + expect(hashed_project.repository).to have_attributes( + disk_path: old_disk_path, + full_path: new_full_path + ) + expect(hashed_project.disk_path).to eq(old_disk_path) + end + + it 'does not move the disk path when the transfer fails', :aggregate_failures do + old_full_path = hashed_project.full_path + + expect_next_instance_of(described_class) do |service| + allow(service).to receive(:execute_system_hooks).and_raise('foo') + end + expect { transfer_project(hashed_project, user, group) }.to raise_error('foo') + + hashed_project.reload_repository! + + expect(hashed_project.repository).to have_attributes( + disk_path: old_disk_path, + full_path: old_full_path + ) + expect(hashed_project.disk_path).to eq(old_disk_path) end end diff --git a/spec/services/spam_check_service_spec.rb b/spec/services/spam/spam_check_service_spec.rb index a58c8d9cfd8..5e06d14b8bc 100644 --- a/spec/services/spam_check_service_spec.rb +++ b/spec/services/spam/spam_check_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SpamCheckService do +describe Spam::SpamCheckService do let(:fake_ip) { '1.2.3.4' } let(:fake_user_agent) { 'fake-user-agent' } let(:fake_referrer) { 'fake-http-referrer' } |