From 5ba0ad3da6594180ec12d9166f925d9b1a27dce6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 4 May 2020 09:09:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/gitlab/ci/config/entry/trigger_spec.rb | 13 ----- spec/models/project_ci_cd_setting_spec.rb | 12 ---- .../with_lock_retries_disallowed_method_spec.rb | 68 ++++++++++++++++++++++ ...th_lock_retries_without_ddl_transaction_spec.rb | 46 --------------- .../gitlab/jira_import/import_issue_worker_spec.rb | 22 ++++++- 5 files changed, 89 insertions(+), 72 deletions(-) create mode 100644 spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb delete mode 100644 spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb (limited to 'spec') diff --git a/spec/lib/gitlab/ci/config/entry/trigger_spec.rb b/spec/lib/gitlab/ci/config/entry/trigger_spec.rb index 752c3f59a95..dfd9807583c 100644 --- a/spec/lib/gitlab/ci/config/entry/trigger_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/trigger_spec.rb @@ -114,19 +114,6 @@ describe Gitlab::Ci::Config::Entry::Trigger do .to match /config contains unknown keys: branch/ end end - - context 'when feature flag is off' do - before do - stub_feature_flags(ci_parent_child_pipeline: false) - end - - let(:config) { { include: 'path/to/config.yml' } } - - it 'is returns an error if include is used' do - expect(subject.errors.first) - .to match /config must specify project/ - end - end end context 'when config contains unknown keys' do diff --git a/spec/models/project_ci_cd_setting_spec.rb b/spec/models/project_ci_cd_setting_spec.rb index 312cbbb0948..86115a61aa7 100644 --- a/spec/models/project_ci_cd_setting_spec.rb +++ b/spec/models/project_ci_cd_setting_spec.rb @@ -54,17 +54,5 @@ describe ProjectCiCdSetting do expect(project.reload.ci_cd_settings.default_git_depth).to eq(0) end - - context 'when feature flag :ci_set_project_default_git_depth is disabled' do - let(:project) { create(:project) } - - before do - stub_feature_flags(ci_set_project_default_git_depth: { enabled: false } ) - end - - it 'does not set default value for new records' do - expect(project.ci_cd_settings.default_git_depth).to eq(nil) - end - end end end diff --git a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb new file mode 100644 index 00000000000..48570c1c8d8 --- /dev/null +++ b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/with_lock_retries_disallowed_method' + +describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod do + include CopHelper + + subject(:cop) { described_class.new } + + context 'in migration' do + before do + allow(cop).to receive(:in_migration?).and_return(true) + end + + it 'registers an offense when `with_lock_retries` block has disallowed method' do + inspect_source('def change; with_lock_retries { disallowed_method }; end') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + + it 'registers an offense when `with_lock_retries` block has disallowed methods' do + source = <<~HEREDOC + def change + with_lock_retries do + disallowed_method + + create_table do |t| + t.text :text + end + + other_disallowed_method + + add_column :users, :name + end + end + HEREDOC + + inspect_source(source) + + aggregate_failures do + expect(cop.offenses.size).to eq(2) + expect(cop.offenses.map(&:line)).to eq([3, 9]) + end + end + + it 'registers no offense when `with_lock_retries` has only allowed method' do + inspect_source('def up; with_lock_retries { add_foreign_key :foo, :bar }; end') + + expect(cop.offenses.size).to eq(0) + end + end + + context 'outside of migration' do + it 'registers no offense' do + inspect_source('def change; with_lock_retries { disallowed_method }; end') + + expect(cop.offenses.size).to eq(0) + end + end +end diff --git a/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb deleted file mode 100644 index b42a4a14c67..00000000000 --- a/spec/rubocop/cop/migration/with_lock_retries_without_ddl_transaction_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../../rubocop/cop/migration/with_lock_retries_without_ddl_transaction' - -describe RuboCop::Cop::Migration::WithLockRetriesWithoutDdlTransaction do - include CopHelper - - let(:valid_source) { 'class MigrationClass < ActiveRecord::Migration[6.0]; def up; with_lock_retries {}; end; end' } - let(:invalid_source) { 'class MigrationClass < ActiveRecord::Migration[6.0]; disable_ddl_transaction!; def up; with_lock_retries {}; end; end' } - - subject(:cop) { described_class.new } - - context 'in migration' do - before do - allow(cop).to receive(:in_migration?).and_return(true) - end - - it 'registers an offense when `with_lock_retries` is used with `disable_ddl_transaction!` method' do - inspect_source(invalid_source) - - aggregate_failures do - expect(cop.offenses.size).to eq(1) - expect(cop.offenses.map(&:line)).to eq([1]) - end - end - - it 'registers no offense when `with_lock_retries` is used inside an `up` method' do - inspect_source(valid_source) - - expect(cop.offenses.size).to eq(0) - end - end - - context 'outside of migration' do - it 'registers no offense' do - inspect_source(invalid_source) - - expect(cop.offenses.size).to eq(0) - end - end -end diff --git a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb index 36af65a3a06..2de609761e2 100644 --- a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb @@ -19,9 +19,12 @@ describe Gitlab::JiraImport::ImportIssueWorker do subject { described_class.new } describe '#perform', :clean_gitlab_redis_cache do + let(:assignee_ids) { [user.id] } let(:issue_attrs) do build(:issue, project_id: project.id, title: 'jira issue') - .as_json.merge('label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id]).compact + .as_json.merge( + 'label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id], 'assignee_ids' => assignee_ids + ).compact end context 'when any exception raised while inserting to DB' do @@ -67,6 +70,23 @@ describe Gitlab::JiraImport::ImportIssueWorker do expect(issue.title).to eq('jira issue') expect(issue.project).to eq(project) expect(issue.labels).to match_array([label, jira_issue_label_1, jira_issue_label_2]) + expect(issue.assignees).to eq([user]) + end + + context 'when assignee_ids is nil' do + let(:assignee_ids) { nil } + + it 'creates an issue without assignee' do + expect(Issue.last.assignees).to be_empty + end + end + + context 'when assignee_ids is an empty array' do + let(:assignee_ids) { [] } + + it 'creates an issue without assignee' do + expect(Issue.last.assignees).to be_empty + end end end end -- cgit v1.2.3