diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 18:08:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-29 18:08:47 +0000 |
commit | 6b9d3a4e8351e662c4586b24bb152de78ae9e3bf (patch) | |
tree | 883e9db60c047c54418fc1d2b1c5517f97e0f185 /spec | |
parent | 23288f62da73fb0e30d8e7ce306665e8fda1b932 (diff) | |
download | gitlab-ce-6b9d3a4e8351e662c4586b24bb152de78ae9e3bf.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
28 files changed, 263 insertions, 133 deletions
diff --git a/spec/config/application_spec.rb b/spec/config/application_spec.rb index 01ed81964c3..994cea4c84f 100644 --- a/spec/config/application_spec.rb +++ b/spec/config/application_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' describe Gitlab::Application do # rubocop:disable RSpec/FilePath using RSpec::Parameterized::TableSyntax - FILTERED_PARAM = ActionDispatch::Http::ParameterFilter::FILTERED + FILTERED_PARAM = ActiveSupport::ParameterFilter::FILTERED context 'when parameters are logged' do describe 'rails does not leak confidential parameters' do diff --git a/spec/controllers/concerns/metrics_dashboard_spec.rb b/spec/controllers/concerns/metrics_dashboard_spec.rb index 6ab02057412..466021d6ecd 100644 --- a/spec/controllers/concerns/metrics_dashboard_spec.rb +++ b/spec/controllers/concerns/metrics_dashboard_spec.rb @@ -23,7 +23,7 @@ describe MetricsDashboard do routes.draw { get "metrics_dashboard" => "anonymous#metrics_dashboard" } response = get :metrics_dashboard, format: :json - JSON.parse(response.parsed_body) + response.parsed_body end context 'when no parameters are provided' do diff --git a/spec/controllers/concerns/send_file_upload_spec.rb b/spec/controllers/concerns/send_file_upload_spec.rb index 4110be721ad..3cfb7b5a488 100644 --- a/spec/controllers/concerns/send_file_upload_spec.rb +++ b/spec/controllers/concerns/send_file_upload_spec.rb @@ -59,11 +59,9 @@ describe SendFileUpload do let(:params) { { disposition: 'inline', attachment: filename } } it 'sends a file with inline disposition' do - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file expected_params = { filename: 'test.png', - disposition: "inline; filename*=UTF-8''test.png" + disposition: 'inline' } expect(controller).to receive(:send_file).with(uploader.path, expected_params) @@ -76,34 +74,16 @@ describe SendFileUpload do let(:params) { { attachment: filename } } it 'sends a file with content-type of text/plain' do - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file expected_params = { content_type: 'text/plain', filename: 'test.js', - disposition: "attachment; filename*=UTF-8''test.js" + disposition: 'attachment' } expect(controller).to receive(:send_file).with(uploader.path, expected_params) subject end - context 'with non-ASCII encoded filename' do - let(:filename) { 'ใในใ.txt' } - - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file - it 'sends content-disposition for non-ASCII encoded filenames' do - expected_params = { - filename: filename, - disposition: "attachment; filename*=UTF-8''%E3%83%86%E3%82%B9%E3%83%88.txt" - } - expect(controller).to receive(:send_file).with(uploader.path, expected_params) - - subject - end - end - context 'with a proxied file in object storage' do before do stub_uploads_object_storage(uploader: uploader_class) diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index 7aaaa363faa..c59983d5138 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -138,14 +138,14 @@ describe Projects::ArtifactsController do let(:filename) { job.artifacts_file.filename } it 'sends the artifacts file' do - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file expect(controller).to receive(:send_file) .with( job.artifacts_file.file.path, - hash_including(disposition: %Q(attachment; filename*=UTF-8''#{filename}))).and_call_original + hash_including(disposition: 'attachment', filename: filename)).and_call_original download_artifact + + expect(response.headers['Content-Disposition']).to eq(%Q(attachment; filename="#{filename}"; filename*=UTF-8''#{filename})) end end @@ -170,13 +170,13 @@ describe Projects::ArtifactsController do end it 'sends the codequality report' do - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file expect(controller).to receive(:send_file) .with(job.job_artifacts_codequality.file.path, - hash_including(disposition: %Q(attachment; filename*=UTF-8''#{filename}))).and_call_original + hash_including(disposition: 'attachment', filename: filename)).and_call_original download_artifact(file_type: file_type) + + expect(response.headers['Content-Disposition']).to eq(%Q(attachment; filename="#{filename}"; filename*=UTF-8''#{filename})) end end diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 6abb58e1aa6..a03fabad2de 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -127,13 +127,13 @@ describe Projects::ReleasesController do sign_in(user) end - let!(:release) { create(:release, project: project) } + let(:release) { create(:release, project: project) } let(:tag) { CGI.escape(release.tag) } it_behaves_like 'successful request' context 'when tag name contains slash' do - let!(:release) { create(:release, project: project, tag: 'awesome/v1.0') } + let(:release) { create(:release, project: project, tag: 'awesome/v1.0') } let(:tag) { CGI.escape(release.tag) } it_behaves_like 'successful request' @@ -145,7 +145,6 @@ describe Projects::ReleasesController do end context 'when release does not exist' do - let!(:release) { } let(:tag) { 'non-existent-tag' } it_behaves_like 'not found' @@ -158,6 +157,47 @@ describe Projects::ReleasesController do end end + describe 'GET #show' do + subject do + get :show, params: { namespace_id: project.namespace, project_id: project, tag: tag } + end + + before do + sign_in(user) + end + + let(:release) { create(:release, project: project) } + let(:tag) { CGI.escape(release.tag) } + + it_behaves_like 'successful request' + + context 'when tag name contains slash' do + let(:release) { create(:release, project: project, tag: 'awesome/v1.0') } + let(:tag) { CGI.escape(release.tag) } + + it_behaves_like 'successful request' + + it 'is accesible at a URL encoded path' do + expect(project_release_path(project, release)) + .to eq("/#{project.namespace.path}/#{project.name}/-/releases/awesome%252Fv1.0") + end + end + + context 'when feature flag `release_show_page` is disabled' do + before do + stub_feature_flags(release_show_page: false) + end + + it_behaves_like 'not found' + end + + context 'when release does not exist' do + let(:tag) { 'non-existent-tag' } + + it_behaves_like 'not found' + end + end + describe 'GET #evidence' do let_it_be(:tag_name) { "v1.1.0-evidence" } let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) } diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index 69e2c085659..f42d0560e80 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -649,7 +649,7 @@ describe UploadsController do get :show, params: { model: 'appearance', mounted_as: 'favicon', id: appearance.id, filename: 'dk.png' } expect(response).to have_gitlab_http_status(:ok) - expect(response.header['Content-Disposition']).to end_with 'filename="dk.png"' + expect(response.header['Content-Disposition']).to include('filename="dk.png"') end end diff --git a/spec/features/merge_request/user_sees_merge_widget_spec.rb b/spec/features/merge_request/user_sees_merge_widget_spec.rb index 17754400b91..d12843d7150 100644 --- a/spec/features/merge_request/user_sees_merge_widget_spec.rb +++ b/spec/features/merge_request/user_sees_merge_widget_spec.rb @@ -604,7 +604,7 @@ describe 'Merge request > User sees merge widget', :js do click_button 'addTest' expect(page).to have_content('6.66') - expect(page).to have_content(sample_java_failed_message.gsub!(/\s+/, ' ').strip) + expect(page).to have_content(sample_java_failed_message.gsub(/\s+/, ' ').strip) end end end @@ -649,7 +649,7 @@ describe 'Merge request > User sees merge widget', :js do click_button 'Test#sum when a is 1 and b is 3 returns summary' expect(page).to have_content('2.22') - expect(page).to have_content(sample_rspec_failed_message.gsub!(/\s+/, ' ').strip) + expect(page).to have_content(sample_rspec_failed_message.gsub(/\s+/, ' ').strip) end end end diff --git a/spec/features/projects/artifacts/user_downloads_artifacts_spec.rb b/spec/features/projects/artifacts/user_downloads_artifacts_spec.rb index 254ebfb839a..fb70076fcf1 100644 --- a/spec/features/projects/artifacts/user_downloads_artifacts_spec.rb +++ b/spec/features/projects/artifacts/user_downloads_artifacts_spec.rb @@ -9,7 +9,7 @@ describe "User downloads artifacts" do shared_examples "downloading" do it "downloads the zip" do - expect(page.response_headers["Content-Disposition"]).to eq(%Q{attachment; filename*=UTF-8''#{job.artifacts_file.filename}; filename="#{job.artifacts_file.filename}"}) + expect(page.response_headers['Content-Disposition']).to eq(%Q{attachment; filename="#{job.artifacts_file.filename}"; filename*=UTF-8''#{job.artifacts_file.filename}}) expect(page.response_headers['Content-Transfer-Encoding']).to eq("binary") expect(page.response_headers['Content-Type']).to eq("application/zip") expect(page.source.b).to eq(job.artifacts_file.file.read.b) diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index f9ff076a416..a17793bc6d6 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -346,7 +346,7 @@ describe 'Jobs', :clean_gitlab_redis_shared_state do artifact_request = requests.find { |req| req.url.match(%r{artifacts/download}) } - expect(artifact_request.response_headers["Content-Disposition"]).to eq(%Q{attachment; filename*=UTF-8''#{job.artifacts_file.filename}; filename="#{job.artifacts_file.filename}"}) + expect(artifact_request.response_headers['Content-Disposition']).to eq(%Q{attachment; filename="#{job.artifacts_file.filename}"; filename*=UTF-8''#{job.artifacts_file.filename}}) expect(artifact_request.response_headers['Content-Transfer-Encoding']).to eq("binary") expect(artifact_request.response_headers['Content-Type']).to eq("image/gif") expect(artifact_request.body).to eq(job.artifacts_file.file.read.b) diff --git a/spec/frontend/vue_shared/components/changed_file_icon_spec.js b/spec/frontend/vue_shared/components/changed_file_icon_spec.js index 5d2aec6734f..8258eb8204c 100644 --- a/spec/frontend/vue_shared/components/changed_file_icon_spec.js +++ b/spec/frontend/vue_shared/components/changed_file_icon_spec.js @@ -3,8 +3,7 @@ import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue'; import Icon from '~/vue_shared/components/icon.vue'; const changedFile = () => ({ changed: true }); -const stagedFile = () => ({ changed: false, staged: true }); -const changedAndStagedFile = () => ({ changed: true, staged: true }); +const stagedFile = () => ({ changed: true, staged: true }); const newFile = () => ({ changed: true, tempFile: true }); const unchangedFile = () => ({ changed: false, tempFile: false, staged: false, deleted: false }); @@ -55,11 +54,10 @@ describe('Changed file icon', () => { }); describe.each` - file | iconName | tooltipText | desc - ${changedFile()} | ${'file-modified'} | ${'Unstaged modification'} | ${'with file changed'} - ${stagedFile()} | ${'file-modified-solid'} | ${'Staged modification'} | ${'with file staged'} - ${changedAndStagedFile()} | ${'file-modified'} | ${'Unstaged and staged modification'} | ${'with file changed and staged'} - ${newFile()} | ${'file-addition'} | ${'Unstaged addition'} | ${'with file new'} + file | iconName | tooltipText | desc + ${changedFile()} | ${'file-modified'} | ${'Unstaged modification'} | ${'with file changed'} + ${stagedFile()} | ${'file-modified-solid'} | ${'Staged modification'} | ${'with file staged'} + ${newFile()} | ${'file-addition'} | ${'Unstaged addition'} | ${'with file new'} `('$desc', ({ file, iconName, tooltipText }) => { beforeEach(() => { factory({ file }); diff --git a/spec/javascripts/editor/editor_lite_spec.js b/spec/javascripts/editor/editor_lite_spec.js new file mode 100644 index 00000000000..154daccf82d --- /dev/null +++ b/spec/javascripts/editor/editor_lite_spec.js @@ -0,0 +1,111 @@ +import { editor as monacoEditor, Uri } from 'monaco-editor'; +import Editor from '~/editor/editor_lite'; + +describe('Base editor', () => { + let editorEl; + let editor; + const blobContent = 'Foo Bar'; + const blobPath = 'test.md'; + const uri = new Uri('gitlab', false, blobPath); + const fakeModel = { foo: 'bar' }; + + beforeEach(() => { + setFixtures('<div id="editor" data-editor-loading></div>'); + editorEl = document.getElementById('editor'); + editor = new Editor(); + }); + + afterEach(() => { + editor.dispose(); + editorEl.remove(); + }); + + it('initializes Editor with basic properties', () => { + expect(editor).toBeDefined(); + expect(editor.editorEl).toBe(null); + expect(editor.blobContent).toEqual(''); + expect(editor.blobPath).toEqual(''); + }); + + it('removes `editor-loading` data attribute from the target DOM element', () => { + editor.createInstance({ el: editorEl }); + + expect(editorEl.dataset.editorLoading).toBeUndefined(); + }); + + describe('instance of the Editor', () => { + let modelSpy; + let instanceSpy; + let setModel; + let dispose; + + beforeEach(() => { + setModel = jasmine.createSpy(); + dispose = jasmine.createSpy(); + modelSpy = spyOn(monacoEditor, 'createModel').and.returnValue(fakeModel); + instanceSpy = spyOn(monacoEditor, 'create').and.returnValue({ + setModel, + dispose, + }); + }); + + it('does nothing if no dom element is supplied', () => { + editor.createInstance(); + + expect(editor.editorEl).toBe(null); + expect(editor.blobContent).toEqual(''); + expect(editor.blobPath).toEqual(''); + + expect(modelSpy).not.toHaveBeenCalled(); + expect(instanceSpy).not.toHaveBeenCalled(); + expect(setModel).not.toHaveBeenCalled(); + }); + + it('creates model to be supplied to Monaco editor', () => { + editor.createInstance({ el: editorEl, blobPath, blobContent }); + + expect(modelSpy).toHaveBeenCalledWith(blobContent, undefined, uri); + expect(setModel).toHaveBeenCalledWith(fakeModel); + }); + + it('initializes the instance on a supplied DOM node', () => { + editor.createInstance({ el: editorEl }); + + expect(editor.editorEl).not.toBe(null); + expect(instanceSpy).toHaveBeenCalledWith(editorEl, jasmine.anything()); + }); + }); + + describe('implementation', () => { + beforeEach(() => { + editor.createInstance({ el: editorEl, blobPath, blobContent }); + }); + + afterEach(() => { + editor.model.dispose(); + }); + + it('correctly proxies value from the model', () => { + expect(editor.getValue()).toEqual(blobContent); + }); + + it('is capable of changing the language of the model', () => { + const blobRenamedPath = 'test.js'; + + expect(editor.model.getLanguageIdentifier().language).toEqual('markdown'); + editor.updateModelLanguage(blobRenamedPath); + + expect(editor.model.getLanguageIdentifier().language).toEqual('javascript'); + }); + + it('falls back to plaintext if there is no language associated with an extension', () => { + const blobRenamedPath = 'test.myext'; + const spy = spyOn(console, 'error'); + + editor.updateModelLanguage(blobRenamedPath); + + expect(spy).not.toHaveBeenCalled(); + expect(editor.model.getLanguageIdentifier().language).toEqual('plaintext'); + }); + }); +}); diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 3797e794985..7a8e79fecb1 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -1541,7 +1541,7 @@ describe Gitlab::Database::MigrationHelpers do self.table_name = 'issues' self.inheritance_column = :_type_disabled - belongs_to :project + belongs_to :project, class_name: "::Project" has_internal_id :iid, scope: :project, diff --git a/spec/lib/gitlab/query_limiting/middleware_spec.rb b/spec/lib/gitlab/query_limiting/middleware_spec.rb index f996ea38bb9..f397843df54 100644 --- a/spec/lib/gitlab/query_limiting/middleware_spec.rb +++ b/spec/lib/gitlab/query_limiting/middleware_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::QueryLimiting::Middleware do :controller, action_name: 'show', class: double(:class, name: 'UsersController'), - content_type: 'text/html' + media_type: 'text/html' ) } @@ -39,7 +39,7 @@ describe Gitlab::QueryLimiting::Middleware do :controller, action_name: 'show', class: double(:class, name: 'UsersController'), - content_type: 'application/json' + media_type: 'application/json' ) } diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 1e8598a457c..470b67afe07 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -302,7 +302,11 @@ describe MergeRequest do it 'returns empty requests' do latest_merge_request_diff = merge_request.merge_request_diffs.create - latest_merge_request_diff.merge_request_diff_commits.where(sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0').delete_all + + MergeRequestDiffCommit.where( + merge_request_diff_id: latest_merge_request_diff, + sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0' + ).delete_all expect(by_commit_sha).to be_empty end diff --git a/spec/presenters/project_presenter_spec.rb b/spec/presenters/project_presenter_spec.rb index 620ef3ff21a..26fa3803651 100644 --- a/spec/presenters/project_presenter_spec.rb +++ b/spec/presenters/project_presenter_spec.rb @@ -297,7 +297,7 @@ describe ProjectPresenter do is_link: false, label: a_string_including("New file"), link: presenter.project_new_blob_path(project, 'master'), - class_modifier: 'success' + class_modifier: 'missing' ) end diff --git a/spec/requests/api/issues/post_projects_issues_spec.rb b/spec/requests/api/issues/post_projects_issues_spec.rb index bbe0683c275..6597a3ab3ba 100644 --- a/spec/requests/api/issues/post_projects_issues_spec.rb +++ b/spec/requests/api/issues/post_projects_issues_spec.rb @@ -389,7 +389,7 @@ describe API::Issues do end 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 expect_next_instance_of(AkismetService) do |akismet_service| diff --git a/spec/requests/api/issues/put_projects_issues_spec.rb b/spec/requests/api/issues/put_projects_issues_spec.rb index 39ac53899da..e6fec2fa1fc 100644 --- a/spec/requests/api/issues/put_projects_issues_spec.rb +++ b/spec/requests/api/issues/put_projects_issues_spec.rb @@ -194,7 +194,7 @@ describe API::Issues do end 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 expect_next_instance_of(AkismetService) do |akismet_service| diff --git a/spec/rubocop/cop/include_action_view_context_spec.rb b/spec/rubocop/cop/include_action_view_context_spec.rb deleted file mode 100644 index c888555b54f..00000000000 --- a/spec/rubocop/cop/include_action_view_context_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../rubocop/cop/include_action_view_context' - -describe RuboCop::Cop::IncludeActionViewContext do - include CopHelper - - subject(:cop) { described_class.new } - - context 'when `ActionView::Context` is included' do - let(:source) { 'include ActionView::Context' } - let(:correct_source) { 'include ::Gitlab::ActionViewOutput::Context' } - - it 'registers an offense' do - inspect_source(source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - expect(cop.highlights).to eq(['ActionView::Context']) - end - end - - it 'autocorrects to the right version' do - autocorrected = autocorrect_source(source) - - expect(autocorrected).to eq(correct_source) - end - end - - context 'when `ActionView::Context` is not included' do - it 'registers no offense' do - inspect_source('include Context') - - aggregate_failures do - expect(cop.offenses.size).to eq(0) - end - end - end -end 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' } diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb index fd5ad9451f7..4f11f8c6b24 100644 --- a/spec/support/helpers/javascript_fixtures_helpers.rb +++ b/spec/support/helpers/javascript_fixtures_helpers.rb @@ -62,7 +62,7 @@ module JavaScriptFixturesHelpers fixture = response.body fixture.force_encoding("utf-8") - response_mime_type = Mime::Type.lookup(response.content_type) + response_mime_type = Mime::Type.lookup(response.media_type) if response_mime_type.html? doc = Nokogiri::HTML::DocumentFragment.parse(fixture) diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 68f71494771..5eb70f534d8 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -21,7 +21,7 @@ module MigrationsHelpers end def migration_context - ActiveRecord::MigrationContext.new(migrations_paths) + ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration) end def migrations diff --git a/spec/support/helpers/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb index 0dc6e851190..6a832ca97d1 100644 --- a/spec/support/helpers/stub_configuration.rb +++ b/spec/support/helpers/stub_configuration.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'active_support/core_ext/hash/transform_values' require 'active_support/hash_with_indifferent_access' require 'active_support/dependencies' diff --git a/spec/support/shared_examples/controllers/repository_lfs_file_load_shared_examples.rb b/spec/support/shared_examples/controllers/repository_lfs_file_load_shared_examples.rb index b8967bc8df3..fadf428125a 100644 --- a/spec/support/shared_examples/controllers/repository_lfs_file_load_shared_examples.rb +++ b/spec/support/shared_examples/controllers/repository_lfs_file_load_shared_examples.rb @@ -41,13 +41,11 @@ RSpec.shared_examples 'a controller that can serve LFS files' do |options = {}| it 'serves the file' do lfs_uploader = LfsObjectUploader.new(lfs_object) - # Notice the filename= is omitted from the disposition; this is because - # Rails 5 will append this header in send_file expect(controller).to receive(:send_file) .with( File.join(lfs_uploader.root, lfs_uploader.store_dir, lfs_uploader.filename), filename: filename, - disposition: %Q(attachment; filename*=UTF-8''#{filename})) + disposition: 'attachment') subject diff --git a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb index 66a6c073445..1f229d6b783 100644 --- a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb +++ b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb @@ -50,3 +50,38 @@ RSpec.shared_examples 'raises error for users with insufficient permissions' do it_behaves_like 'misconfigured dashboard service response', :unauthorized end end + +RSpec.shared_examples 'valid dashboard cloning process' do |dashboard_template, sequence| + context "dashboard template: #{dashboard_template}" do + let(:dashboard) { dashboard_template } + 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_content_hash.to_yaml + } + end + + 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 + end + + context 'user has defined custom metrics' do + it 'uses external service to includes them into new file content', :aggregate_failures do + service_instance = double(::Gitlab::Metrics::Dashboard::Processor) + expect(::Gitlab::Metrics::Dashboard::Processor).to receive(:new).with(project, file_content_hash, sequence, {}).and_return(service_instance) + expect(service_instance).to receive(:process).and_return(file_content_hash) + expect(::Files::CreateService).to receive(:new).with(project, user, dashboard_attrs).and_return(double(execute: { status: :success })) + + service_call + end + end + end +end |