2019-10-29 08:06:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 02:08:43 -04:00
|
|
|
require 'fast_spec_helper'
|
2018-08-16 08:28:25 -04:00
|
|
|
require_relative '../../../rubocop/cop/destroy_all'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::DestroyAll do
|
2018-08-16 08:28:25 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it 'flags the use of destroy_all with a send receiver' do
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
foo.destroy_all # rubocop: disable Cop/DestroyAll
|
|
|
|
^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
|
|
|
|
CODE
|
2018-08-16 08:28:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of destroy_all with a constant receiver' do
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
User.destroy_all # rubocop: disable Cop/DestroyAll
|
|
|
|
^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
|
|
|
|
CODE
|
2018-08-16 08:28:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of destroy_all when passing arguments' do
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
User.destroy_all([])
|
|
|
|
^^^^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
|
|
|
|
CODE
|
2018-08-16 08:28:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'flags the use of destroy_all with a local variable receiver' do
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_offense(<<~CODE)
|
|
|
|
users = User.all
|
|
|
|
users.destroy_all # rubocop: disable Cop/DestroyAll
|
|
|
|
^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
|
|
|
|
CODE
|
2018-08-16 08:28:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not flag the use of delete_all' do
|
2021-02-09 01:09:21 -05:00
|
|
|
expect_no_offenses('foo.delete_all')
|
2018-08-16 08:28:25 -04:00
|
|
|
end
|
|
|
|
end
|