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: d06c0b2f3cf9a87f88acd8e81ad613c59c60561d (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
40
41
42
43
44
45
# frozen_string_literal: true

require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/destroy_all'

describe RuboCop::Cop::DestroyAll do
  include CopHelper

  subject(:cop) { described_class.new }

  it 'flags the use of destroy_all with a send receiver' do
    inspect_source('foo.destroy_all # rubocop: disable Cop/DestroyAll')

    expect(cop.offenses.size).to eq(1)
  end

  it 'flags the use of destroy_all with a constant receiver' do
    inspect_source('User.destroy_all # rubocop: disable Cop/DestroyAll')

    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
    users.destroy_all # rubocop: disable Cop/DestroyAll
    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