diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-02 14:29:30 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-07 17:36:55 +0200 |
commit | 5819ca1a249d1daf3b4feb655c217c98a1b70225 (patch) | |
tree | 799459af23e425921e5368693ee3d0a258c426bb /spec/rubocop | |
parent | 44d65c36dbe2f38eacb1858a99996c025b755937 (diff) | |
download | gitlab-ce-5819ca1a249d1daf3b4feb655c217c98a1b70225.tar.gz |
Added Cop to blacklist polymorphic associations
One should really use a separate table instead of using polymorphic
associations.
See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11168 for
more information.
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/activerecord_serialize_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubocop/cop/polymorphic_associations_spec.rb | 33 |
2 files changed, 35 insertions, 2 deletions
diff --git a/spec/rubocop/cop/activerecord_serialize_spec.rb b/spec/rubocop/cop/activerecord_serialize_spec.rb index a303b16d264..5bd7e5fa926 100644 --- a/spec/rubocop/cop/activerecord_serialize_spec.rb +++ b/spec/rubocop/cop/activerecord_serialize_spec.rb @@ -10,7 +10,7 @@ describe RuboCop::Cop::ActiverecordSerialize do context 'inside the app/models directory' do it 'registers an offense when serialize is used' do - allow(cop).to receive(:in_models?).and_return(true) + allow(cop).to receive(:in_model?).and_return(true) inspect_source(cop, 'serialize :foo') @@ -23,7 +23,7 @@ describe RuboCop::Cop::ActiverecordSerialize do context 'outside the app/models directory' do it 'does nothing' do - allow(cop).to receive(:in_models?).and_return(false) + allow(cop).to receive(:in_model?).and_return(false) inspect_source(cop, 'serialize :foo') diff --git a/spec/rubocop/cop/polymorphic_associations_spec.rb b/spec/rubocop/cop/polymorphic_associations_spec.rb new file mode 100644 index 00000000000..49959aa6419 --- /dev/null +++ b/spec/rubocop/cop/polymorphic_associations_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/polymorphic_associations' + +describe RuboCop::Cop::PolymorphicAssociations do + include CopHelper + + subject(:cop) { described_class.new } + + context 'inside the app/models directory' do + it 'registers an offense when polymorphic: true is used' do + allow(cop).to receive(:in_model?).and_return(true) + + inspect_source(cop, 'belongs_to :foo, polymorphic: true') + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([1]) + end + end + end + + context 'outside the app/models directory' do + it 'does nothing' do + allow(cop).to receive(:in_model?).and_return(false) + + inspect_source(cop, 'belongs_to :foo, polymorphic: true') + + expect(cop.offenses).to be_empty + end + end +end |