debian-mirror-gitlab/spec/rubocop/cop/destroy_all_spec.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2018-11-20 20:47:30 +05:30
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/destroy_all'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::DestroyAll, type: :rubocop do
2018-11-20 20:47:30 +05:30
include CopHelper
subject(:cop) { described_class.new }
it 'flags the use of destroy_all with a send receiver' do
2020-06-23 00:09:42 +05:30
inspect_source('foo.destroy_all # rubocop: disable Cop/DestroyAll')
2018-11-20 20:47:30 +05:30
expect(cop.offenses.size).to eq(1)
end
it 'flags the use of destroy_all with a constant receiver' do
2020-06-23 00:09:42 +05:30
inspect_source('User.destroy_all # rubocop: disable Cop/DestroyAll')
2018-11-20 20:47:30 +05:30
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
2020-06-23 00:09:42 +05:30
users.destroy_all # rubocop: disable Cop/DestroyAll
2018-11-20 20:47:30 +05:30
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