diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 00:07:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 00:07:43 +0300 |
commit | 015663b70f1bcdae4483e38c2beac884f92da5b8 (patch) | |
tree | 6dd5a59c7f9a27c3cca22801ca30bf3dd8f9b401 /spec | |
parent | 5eb11b697d7ee280b0b5c2ff9a1850a3b5e9b7e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
6 files changed, 192 insertions, 96 deletions
diff --git a/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb b/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb new file mode 100644 index 00000000000..a836253f9e1 --- /dev/null +++ b/spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Projects::ErrorTracking::StackTracesController do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + before do + sign_in(user) + project.add_maintainer(user) + end + + describe 'GET #index' do + let(:issue_id) { 1234 } + let(:issue_stack_trace_service) { spy(:issue_stack_trace_service) } + + subject(:get_stack_trace) do + get :index, params: { namespace_id: project.namespace, project_id: project, issue_id: issue_id, format: :json } + end + + before do + expect(ErrorTracking::IssueLatestEventService) + .to receive(:new).with(project, user, issue_id: issue_id.to_s) + .and_return(issue_stack_trace_service) + expect(issue_stack_trace_service).to receive(:execute).and_return(service_response) + + get_stack_trace + end + + context 'awaiting data' do + let(:service_response) { { status: :error, http_status: :no_content }} + + it 'responds with no data' do + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'service result is successful' do + let(:service_response) { { status: :success, latest_event: error_event } } + let(:error_event) { build(:error_tracking_error_event) } + + it 'responds with success' do + expect(response).to have_gitlab_http_status(:ok) + end + + it 'responds with error' do + expect(response).to match_response_schema('error_tracking/issue_stack_trace') + end + + it 'highlights stack trace source code' do + expect(json_response['error']).to eq( + Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate(error_event).as_json + ) + end + end + + context 'service result is erroneous' do + let(:error_message) { 'error message' } + + context 'without http_status' do + let(:service_response) { { status: :error, message: error_message } } + + it 'responds with bad request' do + expect(response).to have_gitlab_http_status(:bad_request) + end + + it 'responds with error message' do + expect(json_response['message']).to eq(error_message) + end + end + + context 'with explicit http_status' do + let(:http_status) { :no_content } + let(:service_response) { { status: :error, message: error_message, http_status: http_status } } + + it 'responds with custom http status' do + expect(response).to have_gitlab_http_status(http_status) + end + + it 'responds with error message' do + expect(json_response['message']).to eq(error_message) + end + end + end + end +end diff --git a/spec/controllers/projects/error_tracking_controller_spec.rb b/spec/controllers/projects/error_tracking_controller_spec.rb index b1f7c7178c1..d0f248437b4 100644 --- a/spec/controllers/projects/error_tracking_controller_spec.rb +++ b/spec/controllers/projects/error_tracking_controller_spec.rb @@ -266,102 +266,6 @@ describe Projects::ErrorTrackingController do end end - describe 'GET #stack_trace' do - let_it_be(:issue_id) { 1234 } - - let(:issue_stack_trace_service) { spy(:issue_stack_trace_service) } - - let(:permitted_params) do - ActionController::Parameters.new( - { issue_id: issue_id.to_s } - ).permit! - end - - subject(:get_stack_trace) do - get :stack_trace, params: issue_params(issue_id: issue_id, format: :json) - end - - before do - expect(ErrorTracking::IssueLatestEventService) - .to receive(:new).with(project, user, permitted_params) - .and_return(issue_stack_trace_service) - end - - describe 'format json' do - context 'awaiting data' do - before do - expect(issue_stack_trace_service).to receive(:execute) - .and_return(status: :error, http_status: :no_content) - end - - it 'returns no data' do - get_stack_trace - - expect(response).to have_gitlab_http_status(:no_content) - end - end - - context 'service result is successful' do - before do - expect(issue_stack_trace_service).to receive(:execute) - .and_return(status: :success, latest_event: error_event) - - get_stack_trace - end - - let(:error_event) { build(:error_tracking_error_event) } - - it 'returns an error' do - expect(response).to have_gitlab_http_status(:ok) - expect(response).to match_response_schema('error_tracking/issue_stack_trace') - end - - it 'highlights stack trace source code' do - expect(json_response['error']).to eq( - Gitlab::ErrorTracking::StackTraceHighlightDecorator.decorate(error_event).as_json - ) - end - end - - context 'service result is erroneous' do - let(:error_message) { 'error message' } - - context 'without http_status' do - before do - expect(issue_stack_trace_service).to receive(:execute) - .and_return(status: :error, message: error_message) - end - - it 'returns 400 with message' do - get_stack_trace - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['message']).to eq(error_message) - end - end - - context 'with explicit http_status' do - let(:http_status) { :no_content } - - before do - expect(issue_stack_trace_service).to receive(:execute).and_return( - status: :error, - message: error_message, - http_status: http_status - ) - end - - it 'returns http_status with message' do - get_stack_trace - - expect(response).to have_gitlab_http_status(http_status) - expect(json_response['message']).to eq(error_message) - end - end - end - end - end - private def issue_params(opts = {}) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index a0c85863150..a67475e47a3 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -206,6 +206,15 @@ describe ApplicationHelper do end end + context 'when @snippet is set' do + it 'returns the passed path' do + snippet = create(:snippet) + assign(:snippet, snippet) + + expect(helper.external_storage_url_or_path('/foo/bar', project)).to eq('/foo/bar') + end + end + context 'when external storage is enabled' do let(:user) { create(:user, static_object_token: 'hunter1') } diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index cac6908f4b4..9c8d53b0ed7 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -325,6 +325,25 @@ describe Gitlab::Database::MigrationHelpers do end end end + + describe 'validate option' do + let(:args) { [:projects, :users] } + let(:options) { { column: :user_id, on_delete: nil } } + + context 'when validate is supplied with a falsey value' do + it_behaves_like 'skips validation', validate: false + it_behaves_like 'skips validation', validate: nil + end + + context 'when validate is supplied with a truthy value' do + it_behaves_like 'performs validation', validate: true + it_behaves_like 'performs validation', validate: :whatever + end + + context 'when validate is not supplied' do + it_behaves_like 'performs validation', {} + end + end end end diff --git a/spec/migrations/backfill_operations_feature_flags_active_spec.rb b/spec/migrations/backfill_operations_feature_flags_active_spec.rb new file mode 100644 index 00000000000..ad69b776052 --- /dev/null +++ b/spec/migrations/backfill_operations_feature_flags_active_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20191213184609_backfill_operations_feature_flags_active.rb') + +describe BackfillOperationsFeatureFlagsActive, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:flags) { table(:operations_feature_flags) } + + def setup + namespace = namespaces.create!(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + + project + end + + it 'executes successfully when there are no flags in the table' do + setup + + disable_migrations_output { migrate! } + + expect(flags.count).to eq(0) + end + + it 'updates active to true' do + project = setup + flag = flags.create!(project_id: project.id, name: 'test_flag', active: false) + + disable_migrations_output { migrate! } + + expect(flag.reload.active).to eq(true) + end + + it 'updates active to true for multiple flags' do + project = setup + flag_a = flags.create!(project_id: project.id, name: 'test_flag', active: false) + flag_b = flags.create!(project_id: project.id, name: 'other_flag', active: false) + + disable_migrations_output { migrate! } + + expect(flag_a.reload.active).to eq(true) + expect(flag_b.reload.active).to eq(true) + end + + it 'leaves active true if it is already true' do + project = setup + flag = flags.create!(project_id: project.id, name: 'test_flag', active: true) + + disable_migrations_output { migrate! } + + expect(flag.reload.active).to eq(true) + end +end diff --git a/spec/support/shared_examples/migration_helpers_examples.rb b/spec/support/shared_examples/migration_helpers_examples.rb new file mode 100644 index 00000000000..3587297a2d7 --- /dev/null +++ b/spec/support/shared_examples/migration_helpers_examples.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +shared_examples 'skips validation' do |validation_option| + it 'skips validation' do + expect(model).not_to receive(:disable_statement_timeout) + expect(model).to receive(:execute).with(/ADD CONSTRAINT/) + expect(model).not_to receive(:execute).with(/VALIDATE CONSTRAINT/) + + model.add_concurrent_foreign_key(*args, **options.merge(validation_option)) + end +end + +shared_examples 'performs validation' do |validation_option| + it 'performs validation' do + expect(model).to receive(:disable_statement_timeout).and_call_original + expect(model).to receive(:execute).with(/statement_timeout/) + expect(model).to receive(:execute).ordered.with(/NOT VALID/) + expect(model).to receive(:execute).ordered.with(/VALIDATE CONSTRAINT/) + expect(model).to receive(:execute).with(/RESET ALL/) + + model.add_concurrent_foreign_key(*args, **options.merge(validation_option)) + end +end |