summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
commit983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch)
treeb153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/support
parenta2bddee2cdb38673df0e004d5b32d9f77797de64 (diff)
downloadgitlab-ce-983a0bba5d2a042c4a3bbb22432ec192c7501d82.tar.gz
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/helpers/api_helpers.rb11
-rw-r--r--spec/support/helpers/migrations_helpers.rb3
-rw-r--r--spec/support/import_export/configuration_helper.rb4
-rw-r--r--spec/support/matchers/exclude_matcher.rb3
-rw-r--r--spec/support/shared_examples/controllers/deploy_token_shared_examples.rb14
-rw-r--r--spec/support/shared_examples/models/diff_positionable_note_shared_examples.rb1
-rw-r--r--spec/support/shared_examples/quick_actions/merge_request/merge_quick_action_shared_examples.rb19
-rw-r--r--spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb8
-rw-r--r--spec/support/sidekiq_middleware.rb16
9 files changed, 69 insertions, 10 deletions
diff --git a/spec/support/helpers/api_helpers.rb b/spec/support/helpers/api_helpers.rb
index b1e6078c4f2..eb9594a4fb6 100644
--- a/spec/support/helpers/api_helpers.rb
+++ b/spec/support/helpers/api_helpers.rb
@@ -40,6 +40,17 @@ module ApiHelpers
end
end
+ def basic_auth_header(user = nil)
+ return { 'HTTP_AUTHORIZATION' => user } unless user.respond_to?(:username)
+
+ {
+ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(
+ user.username,
+ create(:personal_access_token, user: user).token
+ )
+ }
+ end
+
def expect_empty_array_response
expect_successful_response_with_paginated_array
expect(json_response.length).to eq(0)
diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb
index 5eb70f534d8..2c31a608b35 100644
--- a/spec/support/helpers/migrations_helpers.rb
+++ b/spec/support/helpers/migrations_helpers.rb
@@ -80,6 +80,9 @@ module MigrationsHelpers
allow(ActiveRecord::Base.connection)
.to receive(:active?)
.and_return(false)
+ allow(Gitlab::Runtime)
+ .to receive(:rake?)
+ .and_return(true)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
diff --git a/spec/support/import_export/configuration_helper.rb b/spec/support/import_export/configuration_helper.rb
index 4fe619225bb..4330c4314a8 100644
--- a/spec/support/import_export/configuration_helper.rb
+++ b/spec/support/import_export/configuration_helper.rb
@@ -44,8 +44,8 @@ module ConfigurationHelper
import_export_config = config_hash(config)
excluded_attributes = import_export_config[:excluded_attributes][relation_name.to_sym]
included_attributes = import_export_config[:included_attributes][relation_name.to_sym]
- attributes = attributes - JSON[excluded_attributes.to_json] if excluded_attributes
- attributes = attributes & JSON[included_attributes.to_json] if included_attributes
+ attributes = attributes - JSON.parse(excluded_attributes.to_json) if excluded_attributes
+ attributes = attributes & JSON.parse(included_attributes.to_json) if included_attributes
attributes
end
diff --git a/spec/support/matchers/exclude_matcher.rb b/spec/support/matchers/exclude_matcher.rb
new file mode 100644
index 00000000000..29ee251a466
--- /dev/null
+++ b/spec/support/matchers/exclude_matcher.rb
@@ -0,0 +1,3 @@
+# frozen_string_literal: true
+
+RSpec::Matchers.define_negated_matcher :exclude, :include
diff --git a/spec/support/shared_examples/controllers/deploy_token_shared_examples.rb b/spec/support/shared_examples/controllers/deploy_token_shared_examples.rb
index 791eb0b68e0..bd4eeff81a0 100644
--- a/spec/support/shared_examples/controllers/deploy_token_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/deploy_token_shared_examples.rb
@@ -1,12 +1,13 @@
# frozen_string_literal: true
RSpec.shared_examples 'a created deploy token' do
+ let(:read_repository) { '1' }
let(:deploy_token_params) do
{
name: 'deployer_token',
expires_at: 1.month.from_now.to_date.to_s,
username: 'deployer',
- read_repository: '1',
+ read_repository: read_repository,
deploy_token_type: deploy_token_type
}
end
@@ -19,4 +20,15 @@ RSpec.shared_examples 'a created deploy token' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
+
+ context 'when no scope is selected' do
+ let(:read_repository) { '0' }
+
+ it 'creates a variable with a errored deploy token' do
+ expect { create_deploy_token }.not_to change { DeployToken.active.count }
+
+ expect(assigns(:new_deploy_token)).to be_a(DeployToken)
+ expect(assigns(:new_deploy_token).errors.full_messages.first).to eq('Scopes can\'t be blank')
+ end
+ end
end
diff --git a/spec/support/shared_examples/models/diff_positionable_note_shared_examples.rb b/spec/support/shared_examples/models/diff_positionable_note_shared_examples.rb
index 38a9f1fe098..aa8979603b6 100644
--- a/spec/support/shared_examples/models/diff_positionable_note_shared_examples.rb
+++ b/spec/support/shared_examples/models/diff_positionable_note_shared_examples.rb
@@ -13,6 +13,7 @@ RSpec.shared_examples 'a valid diff positionable note' do |factory_on_commit|
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
+ line_range: nil,
diff_refs: diff_refs
)
end
diff --git a/spec/support/shared_examples/quick_actions/merge_request/merge_quick_action_shared_examples.rb b/spec/support/shared_examples/quick_actions/merge_request/merge_quick_action_shared_examples.rb
index fa163b54405..e0edbc5637a 100644
--- a/spec/support/shared_examples/quick_actions/merge_request/merge_quick_action_shared_examples.rb
+++ b/spec/support/shared_examples/quick_actions/merge_request/merge_quick_action_shared_examples.rb
@@ -10,10 +10,27 @@ RSpec.shared_examples 'merge quick action' do
it 'merges the MR', :sidekiq_might_not_need_inline do
add_note("/merge")
- expect(page).to have_content 'Scheduled to merge this merge request when the pipeline succeeds.'
+ expect(page).to have_content 'Merged this merge request.'
expect(merge_request.reload).to be_merged
end
+
+ context 'when auto merge is avialable' do
+ before do
+ create(:ci_pipeline, :detached_merge_request_pipeline,
+ project: project, merge_request: merge_request)
+ merge_request.update_head_pipeline
+ end
+
+ it 'schedules to merge the MR' do
+ add_note("/merge")
+
+ expect(page).to have_content "Scheduled to merge this merge request (Merge when pipeline succeeds)."
+
+ expect(merge_request.reload).to be_auto_merge_enabled
+ expect(merge_request.reload).not_to be_merged
+ end
+ end
end
context 'when the head diff changes in the meanwhile' do
diff --git a/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb b/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb
index 583475678f1..3d25b9076ad 100644
--- a/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/diff_discussions_shared_examples.rb
@@ -22,12 +22,18 @@ RSpec.shared_examples 'diff discussions API' do |parent_type, noteable_type, id_
expect(json_response['id']).to eq(diff_note.discussion_id)
expect(json_response['notes'].first['body']).to eq(diff_note.note)
expect(json_response['notes'].first['position']).to eq(diff_note.position.to_h.stringify_keys)
+ expect(json_response['notes'].first['line_range']).to eq(nil)
end
end
describe "POST /#{parent_type}/:id/#{noteable_type}/:noteable_id/discussions" do
it "creates a new diff note" do
- position = diff_note.position.to_h
+ line_range = {
+ "start_line_code" => Gitlab::Git.diff_line_code(diff_note.position.file_path, 1, 1),
+ "end_line_code" => Gitlab::Git.diff_line_code(diff_note.position.file_path, 2, 2)
+ }
+
+ position = diff_note.position.to_h.merge({ line_range: line_range })
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user),
params: { body: 'hi!', position: position }
diff --git a/spec/support/sidekiq_middleware.rb b/spec/support/sidekiq_middleware.rb
index f6694713101..1380f4394d8 100644
--- a/spec/support/sidekiq_middleware.rb
+++ b/spec/support/sidekiq_middleware.rb
@@ -2,6 +2,17 @@
require 'sidekiq/testing'
+# rubocop:disable RSpec/ModifySidekiqMiddleware
+module SidekiqMiddleware
+ def with_sidekiq_server_middleware(&block)
+ Sidekiq::Testing.server_middleware.clear
+ Sidekiq::Testing.server_middleware(&block)
+ ensure
+ Sidekiq::Testing.server_middleware.clear
+ end
+end
+# rubocop:enable RSpec/ModifySidekiqMiddleware
+
# If Sidekiq::Testing.inline! is used, SQL transactions done inside
# Sidekiq worker are included in the SQL query limit (in a real
# deployment sidekiq worker is executed separately). To avoid
@@ -20,8 +31,3 @@ class DisableQueryLimit
end
end
end
-
-Sidekiq::Testing.server_middleware do |chain|
- chain.add Gitlab::SidekiqStatus::ServerMiddleware
- chain.add DisableQueryLimit
-end