diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-05-31 13:47:36 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-05-31 14:03:37 +0200 |
commit | cd74c1434e42f7e6aa12fe2e2b8d9b1e56aea78f (patch) | |
tree | 2eee709fcc756fde8a597c3079c1bf471788ed76 /spec/rubocop | |
parent | 3d160480c07cd967480716d7cfbe332dfc53507e (diff) | |
download | gitlab-ce-cd74c1434e42f7e6aa12fe2e2b8d9b1e56aea78f.tar.gz |
Added Cop to blacklist the use of serializedocument-not-using-serialize
This Cop blacklists the use of ActiveRecord's "serialize" method, except
for cases where we already use this.
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/activerecord_serialize_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/rubocop/cop/activerecord_serialize_spec.rb b/spec/rubocop/cop/activerecord_serialize_spec.rb new file mode 100644 index 00000000000..a303b16d264 --- /dev/null +++ b/spec/rubocop/cop/activerecord_serialize_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/activerecord_serialize' + +describe RuboCop::Cop::ActiverecordSerialize do + include CopHelper + + subject(:cop) { described_class.new } + + 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) + + inspect_source(cop, 'serialize :foo') + + 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_models?).and_return(false) + + inspect_source(cop, 'serialize :foo') + + expect(cop.offenses).to be_empty + end + end +end |