summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/rubocop
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/active_record_association_reload_spec.rb12
-rw-r--r--spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb4
-rw-r--r--spec/rubocop/cop/default_scope_spec.rb48
-rw-r--r--spec/rubocop/cop/destroy_all_spec.rb6
-rw-r--r--spec/rubocop/cop/filename_length_spec.rb5
-rw-r--r--spec/rubocop/cop/gitlab/bulk_insert_spec.rb19
-rw-r--r--spec/rubocop/cop/gitlab/change_timezone_spec.rb2
-rw-r--r--spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb12
-rw-r--r--spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb14
-rw-r--r--spec/rubocop/cop/inject_enterprise_edition_module_spec.rb14
-rw-r--r--spec/rubocop/cop/migration/add_index_spec.rb4
-rw-r--r--spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb21
-rw-r--r--spec/rubocop/cop/migration/drop_table_spec.rb62
-rw-r--r--spec/rubocop/cop/migration/prevent_strings_spec.rb21
-rw-r--r--spec/rubocop/cop/migration/update_large_table_spec.rb91
-rw-r--r--spec/rubocop/cop/performance/ar_count_each_spec.rb3
-rw-r--r--spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb3
-rw-r--r--spec/rubocop/cop/performance/readlines_each_spec.rb3
-rw-r--r--spec/rubocop/cop/put_group_routes_under_scope_spec.rb6
-rw-r--r--spec/rubocop/cop/put_project_routes_under_scope_spec.rb6
-rw-r--r--spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb86
-rw-r--r--spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb3
-rw-r--r--spec/rubocop/cop/rspec/top_level_describe_path_spec.rb10
-rw-r--r--spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb13
-rw-r--r--spec/rubocop/cop/scalability/cron_worker_context_spec.rb15
-rw-r--r--spec/rubocop/cop/scalability/file_uploads_spec.rb11
-rw-r--r--spec/rubocop/cop/scalability/idempotent_worker_spec.rb7
27 files changed, 250 insertions, 251 deletions
diff --git a/spec/rubocop/cop/active_record_association_reload_spec.rb b/spec/rubocop/cop/active_record_association_reload_spec.rb
index 3cd7a35f12f..d9c8069f0c3 100644
--- a/spec/rubocop/cop/active_record_association_reload_spec.rb
+++ b/spec/rubocop/cop/active_record_association_reload_spec.rb
@@ -11,7 +11,7 @@ describe RuboCop::Cop::ActiveRecordAssociationReload do
context 'when using ActiveRecord::Base' do
it 'registers an offense on reload usage' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
users = User.all
users.reload
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
@@ -19,7 +19,7 @@ describe RuboCop::Cop::ActiveRecordAssociationReload do
end
it 'does not register an offense on reset usage' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
users = User.all
users.reset
PATTERN
@@ -28,7 +28,7 @@ describe RuboCop::Cop::ActiveRecordAssociationReload do
context 'when using ActiveRecord::Relation' do
it 'registers an offense on reload usage' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
user = User.new
user.reload
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
@@ -36,7 +36,7 @@ describe RuboCop::Cop::ActiveRecordAssociationReload do
end
it 'does not register an offense on reset usage' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
user = User.new
user.reset
PATTERN
@@ -45,14 +45,14 @@ describe RuboCop::Cop::ActiveRecordAssociationReload do
context 'when using on self' do
it 'registers an offense on reload usage' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
reload
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
PATTERN
end
it 'does not register an offense on reset usage' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
reset
PATTERN
end
diff --git a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
index c9eb61ccc72..207c3420fbd 100644
--- a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
+++ b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
@@ -14,14 +14,14 @@ describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do
end
it 'registers an offense when redirect has a leading slash' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
root to: redirect("/-/route")
^^^^^^^^^^^^^^^^^^^^ Do not use a leading "/" in route redirects
PATTERN
end
it 'does not register an offense when redirect does not have a leading slash' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
root to: redirect("-/route")
PATTERN
end
diff --git a/spec/rubocop/cop/default_scope_spec.rb b/spec/rubocop/cop/default_scope_spec.rb
new file mode 100644
index 00000000000..9520915f900
--- /dev/null
+++ b/spec/rubocop/cop/default_scope_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../rubocop/cop/default_scope'
+
+describe RuboCop::Cop::DefaultScope do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ it 'does not flag the use of default_scope with a send receiver' do
+ inspect_source('foo.default_scope')
+
+ expect(cop.offenses.size).to eq(0)
+ end
+
+ it 'flags the use of default_scope with a constant receiver' do
+ inspect_source('User.default_scope')
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'flags the use of default_scope with a nil receiver' do
+ inspect_source('class Foo ; default_scope ; end')
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'flags the use of default_scope when passing arguments' do
+ inspect_source('class Foo ; default_scope(:foo) ; end')
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'flags the use of default_scope when passing a block' do
+ inspect_source('class Foo ; default_scope { :foo } ; end')
+
+ expect(cop.offenses.size).to eq(1)
+ end
+
+ it 'ignores the use of default_scope with a local variable receiver' do
+ inspect_source('users = User.all ; users.default_scope')
+
+ expect(cop.offenses.size).to eq(0)
+ end
+end
diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb
index ac8aa56e040..d06c0b2f3cf 100644
--- a/spec/rubocop/cop/destroy_all_spec.rb
+++ b/spec/rubocop/cop/destroy_all_spec.rb
@@ -11,13 +11,13 @@ describe RuboCop::Cop::DestroyAll do
subject(:cop) { described_class.new }
it 'flags the use of destroy_all with a send receiver' do
- inspect_source('foo.destroy_all # rubocop: disable DestroyAll')
+ inspect_source('foo.destroy_all # rubocop: disable Cop/DestroyAll')
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of destroy_all with a constant receiver' do
- inspect_source('User.destroy_all # rubocop: disable DestroyAll')
+ inspect_source('User.destroy_all # rubocop: disable Cop/DestroyAll')
expect(cop.offenses.size).to eq(1)
end
@@ -31,7 +31,7 @@ describe RuboCop::Cop::DestroyAll do
it 'flags the use of destroy_all with a local variable receiver' do
inspect_source(<<~RUBY)
users = User.all
- users.destroy_all # rubocop: disable DestroyAll
+ users.destroy_all # rubocop: disable Cop/DestroyAll
RUBY
expect(cop.offenses.size).to eq(1)
diff --git a/spec/rubocop/cop/filename_length_spec.rb b/spec/rubocop/cop/filename_length_spec.rb
index 1a665440cbc..b1cc845787a 100644
--- a/spec/rubocop/cop/filename_length_spec.rb
+++ b/spec/rubocop/cop/filename_length_spec.rb
@@ -1,12 +1,11 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/filename_length'
-require_relative '../../support/helpers/expect_offense'
-describe RuboCop::Cop::FilenameLength do
+describe RuboCop::Cop::FilenameLength, type: :rubocop do
subject(:cop) { described_class.new }
it 'does not flag files with names 100 characters long' do
diff --git a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
new file mode 100644
index 00000000000..937c709218f
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'rubocop'
+require 'rubocop/rspec/support'
+require_relative '../../../../rubocop/cop/gitlab/bulk_insert'
+
+describe RuboCop::Cop::Gitlab::BulkInsert do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ it 'flags the use of Gitlab::Database.bulk_insert' do
+ expect_offense(<<~SOURCE)
+ Gitlab::Database.bulk_insert('merge_request_diff_files', rows)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `BulkInsertSafe` concern, instead of using `Gitlab::Database.bulk_insert`. See https://docs.gitlab.com/ee/development/insert_into_tables_in_batches.html
+ SOURCE
+ end
+end
diff --git a/spec/rubocop/cop/gitlab/change_timezone_spec.rb b/spec/rubocop/cop/gitlab/change_timezone_spec.rb
index af76559a9fa..1e4b4048cf4 100644
--- a/spec/rubocop/cop/gitlab/change_timezone_spec.rb
+++ b/spec/rubocop/cop/gitlab/change_timezone_spec.rb
@@ -12,7 +12,7 @@ describe RuboCop::Cop::Gitlab::ChangeTimezone do
context 'Time.zone=' do
it 'registers an offense with no 2nd argument' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
Time.zone = 'Awkland'
^^^^^^^^^^^^^^^^^^^^^ Do not change timezone in the runtime (application or rspec), it could result in silently modifying other behavior.
PATTERN
diff --git a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
index 0ff06b431eb..bf0434e7afe 100644
--- a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
+++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
@@ -12,7 +12,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'Object.const_get' do
it 'registers an offense with no 2nd argument' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
Object.const_get(:CONSTANT)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
@@ -24,7 +24,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'inherit=false' do
it 'does not register an offense' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
Object.const_get(:CONSTANT, false)
PATTERN
end
@@ -32,7 +32,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'inherit=true' do
it 'registers an offense' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
Object.const_get(:CONSTANT, true)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
@@ -46,7 +46,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'const_get for a nested class' do
it 'registers an offense on reload usage' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
Nested::Blog.const_get(:CONSTANT)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
@@ -58,7 +58,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'inherit=false' do
it 'does not register an offense' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
Nested::Blog.const_get(:CONSTANT, false)
PATTERN
end
@@ -66,7 +66,7 @@ describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
context 'inherit=true' do
it 'registers an offense if inherit is true' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
Nested::Blog.const_get(:CONSTANT, true)
^^^^^^^^^ Use inherit=false when using const_get.
PATTERN
diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
index 87dd2f14b31..3a0a74a4713 100644
--- a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
+++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
@@ -20,7 +20,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
context 'Non-EE spec file' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, full_path('spec/foo_spec.rb'))
+ expect_no_offenses(<<~SOURCE, full_path('spec/foo_spec.rb'))
describe 'Foo' do
end
SOURCE
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
context 'Non-EE application file' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, full_path('app/models/blog_post.rb'))
+ expect_no_offenses(<<~SOURCE, full_path('app/models/blog_post.rb'))
class BlogPost
end
SOURCE
@@ -38,7 +38,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
context 'EE application file' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, full_path('ee/app/models/blog_post.rb'))
+ expect_no_offenses(<<~SOURCE, full_path('ee/app/models/blog_post.rb'))
class BlogPost
end
SOURCE
@@ -49,7 +49,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
let(:spec_file_path) { full_path('ee/spec/controllers/foo_spec.rb') }
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path)
+ expect_no_offenses(<<~SOURCE, spec_file_path)
describe 'Foo' do
end
SOURCE
@@ -65,7 +65,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
end
it 'marks the describe as offending' do
- expect_offense(<<~SOURCE.strip_indent, spec_file_path)
+ expect_offense(<<~SOURCE, spec_file_path)
describe 'Foo' do
^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/ee/foo_spec.rb`.
end
@@ -78,7 +78,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
let(:spec_file_path) { full_path('ee/spec/controllers/ee/foo_spec.rb') }
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path)
+ expect_no_offenses(<<~SOURCE, spec_file_path)
describe 'Foo' do
end
SOURCE
@@ -94,7 +94,7 @@ describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do
end
it 'marks the describe as offending' do
- expect_offense(<<~SOURCE.strip_indent, spec_file_path)
+ expect_offense(<<~SOURCE, spec_file_path)
describe 'Foo' do
^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/foo_spec.rb`.
end
diff --git a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
index 3cb1dbbbc2c..f047baa3bc2 100644
--- a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
+++ b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
@@ -170,6 +170,20 @@ describe RuboCop::Cop::InjectEnterpriseEditionModule do
SOURCE
end
+ it 'does not flag the use of `prepend_if_ee EE` as long as all injections are at the end of the file' do
+ expect_no_offenses(<<~SOURCE)
+ class Foo
+ end
+
+ Foo.include_if_ee('EE::Foo')
+ Foo.prepend_if_ee('EE::Foo')
+
+ Foo.include(Bar)
+ # comment on prepending Bar
+ Foo.prepend(Bar)
+ SOURCE
+ end
+
it 'autocorrects offenses by just disabling the Cop' do
source = <<~SOURCE
class Foo
diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb
index 0c3f87e5bf8..ca1aadb381b 100644
--- a/spec/rubocop/cop/migration/add_index_spec.rb
+++ b/spec/rubocop/cop/migration/add_index_spec.rb
@@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::AddIndex do
end
it 'registers an offense when add_index is used' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
def change
add_index :table, :column
^^^^^^^^^ `add_index` requires downtime, use `add_concurrent_index` instead
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Migration::AddIndex do
context 'outside of migration' do
it 'registers no offense' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
def change
add_index :table, :column
end
diff --git a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
index 514260a4306..39ca9ace73d 100644
--- a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
+++ b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
@@ -73,6 +73,27 @@ describe RuboCop::Cop::Migration::AddLimitToTextColumns do
end
end
+ context 'when text array columns are defined without a limit' do
+ it 'registers no offense' do
+ expect_no_offenses(<<~RUBY)
+ class TestTextLimits < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ create_table :test_text_limits, id: false do |t|
+ t.integer :test_id, null: false
+ t.text :name, array: true, default: [], null: false
+ end
+
+ add_column :test_text_limits, :email, :text, array: true
+ add_column_with_default :test_text_limits, :role, :text, default: [], array: true
+ change_column_type_concurrently :test_text_limits, :test_id, :text, array: true
+ end
+ end
+ RUBY
+ end
+ end
+
# Make sure that the cop is properly checking for an `add_text_limit`
# over the same {table, attribute} as the one that triggered the offence
context 'when the limit is defined for a same name attribute but different table' do
diff --git a/spec/rubocop/cop/migration/drop_table_spec.rb b/spec/rubocop/cop/migration/drop_table_spec.rb
new file mode 100644
index 00000000000..4fe7fc8c5a5
--- /dev/null
+++ b/spec/rubocop/cop/migration/drop_table_spec.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/migration/drop_table'
+
+describe RuboCop::Cop::Migration::DropTable do
+ include CopHelper
+
+ subject(:cop) { described_class.new }
+
+ context 'when in deployment migration' do
+ before do
+ allow(cop).to receive(:in_deployment_migration?).and_return(true)
+ end
+
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ def change
+ drop_table :table
+ ^^^^^^^^^^ #{described_class::MSG}
+
+ add_column(:users, :username, :text)
+
+ execute "DROP TABLE table"
+ ^^^^^^^ #{described_class::MSG}
+
+ execute "CREATE UNIQUE INDEX email_index ON users (email);"
+ end
+ PATTERN
+ end
+ end
+
+ context 'when in post-deployment migration' do
+ before do
+ allow(cop).to receive(:in_post_deployment_migration?).and_return(true)
+ end
+
+ it 'registers no offense' do
+ expect_no_offenses(<<~PATTERN)
+ def change
+ drop_table :table
+ execute "DROP TABLE table"
+ end
+ PATTERN
+ end
+ end
+
+ context 'when outside of migration' do
+ it 'registers no offense' do
+ expect_no_offenses(<<~PATTERN)
+ def change
+ drop_table :table
+ execute "DROP TABLE table"
+ end
+ PATTERN
+ end
+ end
+end
diff --git a/spec/rubocop/cop/migration/prevent_strings_spec.rb b/spec/rubocop/cop/migration/prevent_strings_spec.rb
index 2702ce1c090..d0e97874aed 100644
--- a/spec/rubocop/cop/migration/prevent_strings_spec.rb
+++ b/spec/rubocop/cop/migration/prevent_strings_spec.rb
@@ -90,6 +90,27 @@ describe RuboCop::Cop::Migration::PreventStrings do
end
end
+ context 'when the string data type is used for arrays' do
+ it 'registers no offense' do
+ expect_no_offenses(<<~RUBY)
+ class TestStringArrays < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def up
+ create_table :test_string_arrays, id: false do |t|
+ t.integer :test_id, null: false
+ t.string :name, array: true, default: [], null: false
+ end
+
+ add_column :test_string_arrays, :email, :string, array: true
+ add_column_with_default :test_string_arrays, :role, :string, default: [], array: true
+ change_column_type_concurrently :test_string_arrays, :test_id, :string, array: true
+ end
+ end
+ RUBY
+ end
+ end
+
context 'on down' do
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
diff --git a/spec/rubocop/cop/migration/update_large_table_spec.rb b/spec/rubocop/cop/migration/update_large_table_spec.rb
deleted file mode 100644
index 30cd84108df..00000000000
--- a/spec/rubocop/cop/migration/update_large_table_spec.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require 'rubocop'
-require 'rubocop/rspec/support'
-
-require_relative '../../../../rubocop/cop/migration/update_large_table'
-
-describe RuboCop::Cop::Migration::UpdateLargeTable do
- include CopHelper
-
- subject(:cop) { described_class.new }
-
- context 'in migration' do
- before do
- allow(cop).to receive(:in_migration?).and_return(true)
- end
-
- shared_examples 'large tables' do |update_method|
- described_class::BLACKLISTED_TABLES.each do |table|
- it "registers an offense for the #{table} table" do
- inspect_source("#{update_method} :#{table}, :column, default: true")
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
- end
- end
- end
-
- context 'for the add_column_with_default method' do
- include_examples 'large tables', 'add_column_with_default'
- end
-
- context 'for the change_column_type_concurrently method' do
- include_examples 'large tables', 'change_column_type_concurrently'
- end
-
- context 'for the rename_column_concurrently method' do
- include_examples 'large tables', 'rename_column_concurrently'
- end
-
- context 'for the update_column_in_batches method' do
- include_examples 'large tables', 'update_column_in_batches'
- end
-
- it 'registers no offense for non-blacklisted tables' do
- inspect_source("add_column_with_default :table, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
-
- it 'registers no offense for non-blacklisted methods' do
- table = described_class::BLACKLISTED_TABLES.sample
-
- inspect_source("some_other_method :#{table}, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
- end
-
- context 'outside of migration' do
- let(:table) { described_class::BLACKLISTED_TABLES.sample }
-
- it 'registers no offense for add_column_with_default' do
- inspect_source("add_column_with_default :#{table}, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
-
- it 'registers no offense for change_column_type_concurrently' do
- inspect_source("change_column_type_concurrently :#{table}, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
-
- it 'registers no offense for rename_column_concurrently' do
- inspect_source("rename_column_concurrently :#{table}, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
-
- it 'registers no offense for update_column_concurrently' do
- inspect_source("update_column_concurrently :#{table}, :column, default: true")
-
- expect(cop.offenses).to be_empty
- end
- end
-end
diff --git a/spec/rubocop/cop/performance/ar_count_each_spec.rb b/spec/rubocop/cop/performance/ar_count_each_spec.rb
index f934a1fde48..534fa55dd45 100644
--- a/spec/rubocop/cop/performance/ar_count_each_spec.rb
+++ b/spec/rubocop/cop/performance/ar_count_each_spec.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/performance/ar_count_each.rb'
-describe RuboCop::Cop::Performance::ARCountEach do
+describe RuboCop::Cop::Performance::ARCountEach, type: :rubocop do
include CopHelper
include ExpectOffense
diff --git a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
index ce4fdac56b0..da44004f947 100644
--- a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
+++ b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank.rb'
-describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
+describe RuboCop::Cop::Performance::ARExistsAndPresentBlank, type: :rubocop do
include CopHelper
include ExpectOffense
diff --git a/spec/rubocop/cop/performance/readlines_each_spec.rb b/spec/rubocop/cop/performance/readlines_each_spec.rb
index 5b3691e2342..e71aaaf3056 100644
--- a/spec/rubocop/cop/performance/readlines_each_spec.rb
+++ b/spec/rubocop/cop/performance/readlines_each_spec.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/performance/readlines_each'
-describe RuboCop::Cop::Performance::ReadlinesEach do
+describe RuboCop::Cop::Performance::ReadlinesEach, type: :rubocop do
include CopHelper
include ExpectOffense
diff --git a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb
index fc4d0015dde..c77412f91b4 100644
--- a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb
+++ b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb
@@ -14,7 +14,7 @@ describe RuboCop::Cop::PutGroupRoutesUnderScope do
end
it 'registers an offense when route is outside scope' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
scope(path: 'groups/*group_id/-', module: :groups) do
resource :issues
end
@@ -25,7 +25,7 @@ describe RuboCop::Cop::PutGroupRoutesUnderScope do
end
it 'does not register an offense when resource inside the scope' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
scope(path: 'groups/*group_id/-', module: :groups) do
resource :issues
resource :notes
@@ -34,7 +34,7 @@ describe RuboCop::Cop::PutGroupRoutesUnderScope do
end
it 'does not register an offense when resource is deep inside the scope' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
scope(path: 'groups/*group_id/-', module: :groups) do
resource :issues
resource :projects do
diff --git a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb
index b0f1e52f397..80ac4cc52e9 100644
--- a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb
+++ b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb
@@ -14,7 +14,7 @@ describe RuboCop::Cop::PutProjectRoutesUnderScope do
end
it 'registers an offense when route is outside scope' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
scope '-' do
resource :issues
end
@@ -25,7 +25,7 @@ describe RuboCop::Cop::PutProjectRoutesUnderScope do
end
it 'does not register an offense when resource inside the scope' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
scope '-' do
resource :issues
resource :notes
@@ -34,7 +34,7 @@ describe RuboCop::Cop::PutProjectRoutesUnderScope do
end
it 'does not register an offense when resource is deep inside the scope' do
- expect_no_offenses(<<~PATTERN.strip_indent)
+ expect_no_offenses(<<~PATTERN)
scope '-' do
resource :issues
resource :projects do
diff --git a/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb b/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb
deleted file mode 100644
index cee593fe535..00000000000
--- a/spec/rubocop/cop/rspec/empty_line_after_shared_example_spec.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_relative '../../../../rubocop/cop/rspec/empty_line_after_shared_example'
-
-describe RuboCop::Cop::RSpec::EmptyLineAfterSharedExample do
- subject(:cop) { described_class.new }
-
- it 'flags a missing empty line after `it_behaves_like` block' do
- expect_offense(<<-RUBY)
- RSpec.describe Foo do
- it_behaves_like 'does this' do
- end
- ^^^ Add an empty line after `it_behaves_like` block.
- it_behaves_like 'does that' do
- end
- end
- RUBY
-
- expect_correction(<<-RUBY)
- RSpec.describe Foo do
- it_behaves_like 'does this' do
- end
-
- it_behaves_like 'does that' do
- end
- end
- RUBY
- end
-
- it 'ignores one-line shared examples before shared example blocks' do
- expect_no_offenses(<<-RUBY)
- RSpec.describe Foo do
- it_behaves_like 'does this'
- it_behaves_like 'does that' do
- end
- end
- RUBY
- end
-
- it 'flags a missing empty line after `shared_examples`' do
- expect_offense(<<-RUBY)
- RSpec.context 'foo' do
- shared_examples do
- end
- ^^^ Add an empty line after `shared_examples` block.
- shared_examples 'something gets done' do
- end
- end
- RUBY
-
- expect_correction(<<-RUBY)
- RSpec.context 'foo' do
- shared_examples do
- end
-
- shared_examples 'something gets done' do
- end
- end
- RUBY
- end
-
- it 'ignores consecutive one-liners' do
- expect_no_offenses(<<-RUBY)
- RSpec.describe Foo do
- it_behaves_like 'do this'
- it_behaves_like 'do that'
- end
- RUBY
- end
-
- it 'flags mixed one-line and multi-line shared examples' do
- expect_offense(<<-RUBY)
- RSpec.context 'foo' do
- it_behaves_like 'do this'
- it_behaves_like 'do that'
- it_behaves_like 'does this' do
- end
- ^^^ Add an empty line after `it_behaves_like` block.
- it_behaves_like 'do this'
- it_behaves_like 'do that'
- end
- RUBY
- end
-end
diff --git a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
index 938916d8d75..d3d323b6643 100644
--- a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
+++ b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
@@ -2,10 +2,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/rspec/modify_sidekiq_middleware'
-describe RuboCop::Cop::RSpec::ModifySidekiqMiddleware do
+describe RuboCop::Cop::RSpec::ModifySidekiqMiddleware, type: :rubocop do
include CopHelper
include ExpectOffense
diff --git a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
index 258144d4000..ee6b6d39cb4 100644
--- a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
+++ b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
@@ -15,7 +15,7 @@ describe RuboCop::Cop::RSpec::TopLevelDescribePath do
context 'when the file ends in _spec.rb' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo_spec.rb')
+ expect_no_offenses(<<~SOURCE, 'spec/foo_spec.rb')
describe 'Foo' do
end
SOURCE
@@ -24,7 +24,7 @@ describe RuboCop::Cop::RSpec::TopLevelDescribePath do
context 'when the file is a frontend fixture' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, 'spec/frontend/fixtures/foo.rb')
+ expect_no_offenses(<<~SOURCE, 'spec/frontend/fixtures/foo.rb')
describe 'Foo' do
end
SOURCE
@@ -34,7 +34,7 @@ describe RuboCop::Cop::RSpec::TopLevelDescribePath do
context 'when the describe is in a shared example' do
context 'with shared_examples' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo.rb')
+ expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
shared_examples 'Foo' do
describe '#bar' do
end
@@ -45,7 +45,7 @@ describe RuboCop::Cop::RSpec::TopLevelDescribePath do
context 'with shared_examples_for' do
it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE.strip_indent, 'spec/foo.rb')
+ expect_no_offenses(<<~SOURCE, 'spec/foo.rb')
shared_examples_for 'Foo' do
describe '#bar' do
end
@@ -57,7 +57,7 @@ describe RuboCop::Cop::RSpec::TopLevelDescribePath do
context 'when the describe is at the top level' do
it 'marks the describe as offending' do
- expect_offense(<<~SOURCE.strip_indent, 'spec/foo.rb')
+ expect_offense(<<~SOURCE, 'spec/foo.rb')
describe 'Foo' do
^^^^^^^^^^^^^^ #{described_class::MESSAGE}
end
diff --git a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
index 8107cfa8957..61603d0100e 100644
--- a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
+++ b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
@@ -2,17 +2,16 @@
require 'fast_spec_helper'
require 'rubocop'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context'
-describe RuboCop::Cop::Scalability::BulkPerformWithContext do
+describe RuboCop::Cop::Scalability::BulkPerformWithContext, type: :rubocop do
include CopHelper
include ExpectOffense
subject(:cop) { described_class.new }
it "adds an offense when calling bulk_perform_async" do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
Worker.bulk_perform_async(args)
CODE
@@ -20,7 +19,7 @@ describe RuboCop::Cop::Scalability::BulkPerformWithContext do
end
it "adds an offense when calling bulk_perform_in" do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
diffs.each_batch(of: BATCH_SIZE) do |relation, index|
ids = relation.pluck_primary_key.map { |id| [id] }
DeleteDiffFilesWorker.bulk_perform_in(index * 5.minutes, ids)
@@ -33,7 +32,7 @@ describe RuboCop::Cop::Scalability::BulkPerformWithContext do
it "does not add an offense for migrations" do
allow(cop).to receive(:in_migration?).and_return(true)
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
Worker.bulk_perform_in(args)
CODE
@@ -43,7 +42,7 @@ describe RuboCop::Cop::Scalability::BulkPerformWithContext do
it "does not add an offence for specs" do
allow(cop).to receive(:in_spec?).and_return(true)
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
Worker.bulk_perform_in(args)
CODE
@@ -51,7 +50,7 @@ describe RuboCop::Cop::Scalability::BulkPerformWithContext do
end
it "does not add an offense for scheduling BackgroundMigrations" do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
BackgroundMigrationWorker.bulk_perform_in(args)
CODE
diff --git a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
index 460514d9bed..e917d33b1e5 100644
--- a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
+++ b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
@@ -2,17 +2,16 @@
require 'fast_spec_helper'
require 'rubocop'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/scalability/cron_worker_context'
-describe RuboCop::Cop::Scalability::CronWorkerContext do
+describe RuboCop::Cop::Scalability::CronWorkerContext, type: :rubocop do
include CopHelper
include ExpectOffense
subject(:cop) { described_class.new }
it 'adds an offense when including CronjobQueue' do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
class SomeWorker
include CronjobQueue
end
@@ -22,14 +21,14 @@ describe RuboCop::Cop::Scalability::CronWorkerContext do
end
it 'does not add offenses for other workers' do
- expect_no_offenses(<<~CODE.strip_indent)
+ expect_no_offenses(<<~CODE)
class SomeWorker
end
CODE
end
it 'does not add an offense when the class defines a context' do
- expect_no_offenses(<<~CODE.strip_indent)
+ expect_no_offenses(<<~CODE)
class SomeWorker
include CronjobQueue
@@ -39,7 +38,7 @@ describe RuboCop::Cop::Scalability::CronWorkerContext do
end
it 'does not add an offense when the worker calls `with_context`' do
- expect_no_offenses(<<~CODE.strip_indent)
+ expect_no_offenses(<<~CODE)
class SomeWorker
include CronjobQueue
@@ -53,7 +52,7 @@ describe RuboCop::Cop::Scalability::CronWorkerContext do
end
it 'does not add an offense when the worker calls `bulk_perform_async_with_contexts`' do
- expect_no_offenses(<<~CODE.strip_indent)
+ expect_no_offenses(<<~CODE)
class SomeWorker
include CronjobQueue
@@ -67,7 +66,7 @@ describe RuboCop::Cop::Scalability::CronWorkerContext do
end
it 'does not add an offense when the worker calls `bulk_perform_in_with_contexts`' do
- expect_no_offenses(<<~CODE.strip_indent)
+ expect_no_offenses(<<~CODE)
class SomeWorker
include CronjobQueue
diff --git a/spec/rubocop/cop/scalability/file_uploads_spec.rb b/spec/rubocop/cop/scalability/file_uploads_spec.rb
index a35d423581c..b0be9ac2b51 100644
--- a/spec/rubocop/cop/scalability/file_uploads_spec.rb
+++ b/spec/rubocop/cop/scalability/file_uploads_spec.rb
@@ -2,10 +2,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/scalability/file_uploads'
-describe RuboCop::Cop::Scalability::FileUploads do
+describe RuboCop::Cop::Scalability::FileUploads, type: :rubocop do
include CopHelper
include ExpectOffense
@@ -15,7 +14,7 @@ describe RuboCop::Cop::Scalability::FileUploads do
context 'with required params' do
it 'detects File in types array' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
params do
requires :certificate, allow_blank: false, types: [String, File]
^^^^ #{message}
@@ -24,7 +23,7 @@ describe RuboCop::Cop::Scalability::FileUploads do
end
it 'detects File as type argument' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
params do
requires :attachment, type: File
^^^^ #{message}
@@ -35,7 +34,7 @@ describe RuboCop::Cop::Scalability::FileUploads do
context 'with optional params' do
it 'detects File in types array' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
params do
optional :certificate, allow_blank: false, types: [String, File]
^^^^ #{message}
@@ -44,7 +43,7 @@ describe RuboCop::Cop::Scalability::FileUploads do
end
it 'detects File as type argument' do
- expect_offense(<<~PATTERN.strip_indent)
+ expect_offense(<<~PATTERN)
params do
optional :attachment, type: File
^^^^ #{message}
diff --git a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
index 7abd602f8bc..73cacc984e9 100644
--- a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
+++ b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
@@ -2,10 +2,9 @@
require 'fast_spec_helper'
require 'rubocop'
-require_relative '../../../support/helpers/expect_offense'
require_relative '../../../../rubocop/cop/scalability/idempotent_worker'
-describe RuboCop::Cop::Scalability::IdempotentWorker do
+describe RuboCop::Cop::Scalability::IdempotentWorker, type: :rubocop do
include CopHelper
include ExpectOffense
@@ -18,7 +17,7 @@ describe RuboCop::Cop::Scalability::IdempotentWorker do
end
it 'adds an offense when not defining idempotent method' do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
class SomeWorker
end
CODE
@@ -27,7 +26,7 @@ describe RuboCop::Cop::Scalability::IdempotentWorker do
end
it 'adds an offense when not defining idempotent method' do
- inspect_source(<<~CODE.strip_indent)
+ inspect_source(<<~CODE)
class SomeWorker
idempotent!
end