diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-16 14:28:25 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-16 17:29:33 +0200 |
commit | 96ce2da74ee36e88f20cbd7ceaff2ab49f0bb223 (patch) | |
tree | 484f41cb9b2013fde409715bad4d00a602e92fb2 /spec/rubocop | |
parent | 353360ef824e10cb0197733e7b104a6fb53cf9af (diff) | |
download | gitlab-ce-96ce2da74ee36e88f20cbd7ceaff2ab49f0bb223.tar.gz |
Blacklist the use of "destroy_all"
This method usually has really bad performance implications, as it loads
rows into memory and deletes them one by one.
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/destroy_all_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb new file mode 100644 index 00000000000..153a5a863cf --- /dev/null +++ b/spec/rubocop/cop/destroy_all_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/destroy_all' + +describe RuboCop::Cop::DestroyAll do + include CopHelper + + subject(:cop) { described_class.new } + + it 'flags the use of destroy_all with a send receiver' do + inspect_source('foo.destroy_all') + + 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') + + expect(cop.offenses.size).to eq(1) + end + + it 'flags the use of destroy_all when passing arguments' do + inspect_source('User.destroy_all([])') + + expect(cop.offenses.size).to eq(1) + end + + it 'flags the use of destroy_all with a local variable receiver' do + inspect_source(<<~RUBY) + users = User.all + users.destroy_all + RUBY + + expect(cop.offenses.size).to eq(1) + end + + it 'does not flag the use of delete_all' do + inspect_source('foo.delete_all') + + expect(cop.offenses).to be_empty + end +end |