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

42 lines
1.2 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_relative '../../../rubocop/cop/destroy_all'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::DestroyAll do
2018-11-20 20:47:30 +05:30
subject(:cop) { described_class.new }
it 'flags the use of destroy_all with a send receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
foo.destroy_all # rubocop: disable Cop/DestroyAll
^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
CODE
2018-11-20 20:47:30 +05:30
end
it 'flags the use of destroy_all with a constant receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
User.destroy_all # rubocop: disable Cop/DestroyAll
^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
CODE
2018-11-20 20:47:30 +05:30
end
it 'flags the use of destroy_all when passing arguments' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
User.destroy_all([])
^^^^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
CODE
2018-11-20 20:47:30 +05:30
end
it 'flags the use of destroy_all with a local variable receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
users = User.all
users.destroy_all # rubocop: disable Cop/DestroyAll
^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
CODE
2018-11-20 20:47:30 +05:30
end
it 'does not flag the use of delete_all' do
2021-03-11 19:13:27 +05:30
expect_no_offenses('foo.delete_all')
2018-11-20 20:47:30 +05:30
end
end