diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-20 09:07:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-20 09:07:57 +0000 |
commit | 7881eb30eaa8b01dbcfe87faa09927c75c7d6e45 (patch) | |
tree | 298bc8d2c62b2f2c29cb8ecbcf3de3eaaa6466d9 /spec/rubocop | |
parent | 64b66e0cb6d1bfd27abf24e06653f00bddb60597 (diff) | |
download | gitlab-ce-7881eb30eaa8b01dbcfe87faa09927c75c7d6e45.tar.gz |
Add latest changes from gitlab-org/gitlab@12-6-stable-ee
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubocop/cop/avoid_return_from_blocks_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubocop/cop/graphql/authorize_types_spec.rb | 10 | ||||
-rw-r--r-- | spec/rubocop/cop/ignored_columns_spec.rb | 22 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/add_index_spec.rb | 39 | ||||
-rw-r--r-- | spec/rubocop/cop/put_group_routes_under_scope_spec.rb | 48 | ||||
-rw-r--r-- | spec/rubocop/cop/put_project_routes_under_scope_spec.rb | 48 |
7 files changed, 173 insertions, 2 deletions
diff --git a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb index 62f6c7a3414..feb85c354ef 100644 --- a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb +++ b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb @@ -62,7 +62,9 @@ describe RuboCop::Cop::AvoidBreakFromStrongMemoize do end end RUBY - expect_any_instance_of(described_class).to receive(:add_offense).once + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:add_offense).once + end inspect_source(source) end diff --git a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb index 133d286ccd2..919cd3d98f3 100644 --- a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb +++ b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb @@ -29,7 +29,9 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do end end RUBY - expect_any_instance_of(described_class).to receive(:add_offense).once + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:add_offense).once + end inspect_source(source) end diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb index af4315ecd34..98797a780e0 100644 --- a/spec/rubocop/cop/graphql/authorize_types_spec.rb +++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb @@ -79,5 +79,15 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do end TYPE end + + it 'does not add an offense for Enums' do + expect_no_offenses(<<~TYPE) + module Types + class ATypeEnum < AnotherEnum + field :a_thing + end + end + TYPE + end end end diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb new file mode 100644 index 00000000000..64437765018 --- /dev/null +++ b/spec/rubocop/cop/ignored_columns_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/ignored_columns' + +describe RuboCop::Cop::IgnoredColumns do + include CopHelper + + subject(:cop) { described_class.new } + + it 'flags the use of destroy_all with a local variable receiver' do + inspect_source(<<~RUBY) + class Foo < ApplicationRecord + self.ignored_columns += %i[id] + end + RUBY + + expect(cop.offenses.size).to eq(1) + end +end diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb new file mode 100644 index 00000000000..0c3f87e5bf8 --- /dev/null +++ b/spec/rubocop/cop/migration/add_index_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/migration/add_index' + +describe RuboCop::Cop::Migration::AddIndex 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 add_index is used' do + expect_offense(<<~PATTERN.strip_indent) + def change + add_index :table, :column + ^^^^^^^^^ `add_index` requires downtime, use `add_concurrent_index` instead + end + PATTERN + end + end + + context 'outside of migration' do + it 'registers no offense' do + expect_no_offenses(<<~PATTERN.strip_indent) + def change + add_index :table, :column + end + PATTERN + end + end +end diff --git a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb new file mode 100644 index 00000000000..fc4d0015dde --- /dev/null +++ b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require_relative '../../../rubocop/cop/put_group_routes_under_scope' + +describe RuboCop::Cop::PutGroupRoutesUnderScope do + include CopHelper + + subject(:cop) { described_class.new } + + before do + allow(cop).to receive(:in_group_routes?).and_return(true) + end + + it 'registers an offense when route is outside scope' do + expect_offense(<<~PATTERN.strip_indent) + scope(path: 'groups/*group_id/-', module: :groups) do + resource :issues + end + + resource :notes + ^^^^^^^^^^^^^^^ Put new group routes under /-/ scope + PATTERN + end + + it 'does not register an offense when resource inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope(path: 'groups/*group_id/-', module: :groups) do + resource :issues + resource :notes + end + PATTERN + end + + it 'does not register an offense when resource is deep inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope(path: 'groups/*group_id/-', module: :groups) do + resource :issues + resource :projects do + resource :issues do + resource :notes + end + end + end + PATTERN + end +end diff --git a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb new file mode 100644 index 00000000000..b0f1e52f397 --- /dev/null +++ b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rubocop' +require_relative '../../../rubocop/cop/put_project_routes_under_scope' + +describe RuboCop::Cop::PutProjectRoutesUnderScope do + include CopHelper + + subject(:cop) { described_class.new } + + before do + allow(cop).to receive(:in_project_routes?).and_return(true) + end + + it 'registers an offense when route is outside scope' do + expect_offense(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + end + + resource :notes + ^^^^^^^^^^^^^^^ Put new project routes under /-/ scope + PATTERN + end + + it 'does not register an offense when resource inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + resource :notes + end + PATTERN + end + + it 'does not register an offense when resource is deep inside the scope' do + expect_no_offenses(<<~PATTERN.strip_indent) + scope '-' do + resource :issues + resource :projects do + resource :issues do + resource :notes + end + end + end + PATTERN + end +end |