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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'rubocop_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
it 'flags the use of destroy_all with a send receiver' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~CODE)
2022-10-11 01:57:18 +05:30
foo.destroy_all
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^ 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)
2022-10-11 01:57:18 +05:30
User.destroy_all
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^ 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
2022-10-11 01:57:18 +05:30
users.destroy_all
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^^ 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