Welcome to mirror list, hosted at ThFree Co, Russian Federation.

destroy_all_spec.rb « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f984822a4e896d919b0f0b3e96af4a3142bc2f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require 'rubocop_spec_helper'
require_relative '../../../rubocop/cop/destroy_all'

RSpec.describe RuboCop::Cop::DestroyAll do
  it 'flags the use of destroy_all with a send receiver' do
    expect_offense(<<~CODE)
      foo.destroy_all
      ^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
    CODE
  end

  it 'flags the use of destroy_all with a constant receiver' do
    expect_offense(<<~CODE)
      User.destroy_all
      ^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
    CODE
  end

  it 'flags the use of destroy_all when passing arguments' do
    expect_offense(<<~CODE)
      User.destroy_all([])
      ^^^^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
    CODE
  end

  it 'flags the use of destroy_all with a local variable receiver' do
    expect_offense(<<~CODE)
      users = User.all
      users.destroy_all
      ^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...]
    CODE
  end

  it 'does not flag the use of delete_all' do
    expect_no_offenses('foo.delete_all')
  end
end