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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# frozen_string_literal: true
require 'fast_spec_helper'
require_relative '../../../rubocop/cop/ignored_columns'
RSpec.describe RuboCop::Cop::IgnoredColumns do
subject(:cop) { described_class.new }
it 'flags direct use of ignored_columns instead of the IgnoredColumns concern' do
expect_offense(<<~RUBY)
class Foo < ApplicationRecord
self.ignored_columns += %i[id]
^^^^^^^^^^^^^^^^^^^^ Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.
end
RUBY
end
context 'when only CE model exist' do
let(:file_path) { full_path('app/models/bar.rb') }
it 'does not flag ignore_columns usage in CE model' do
expect_no_offenses(<<~RUBY, file_path)
class Bar < ApplicationRecord
ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
end
RUBY
end
it 'flags ignore_column usage in EE model' do
expect_no_offenses(<<~RUBY, file_path)
class Baz < ApplicationRecord
ignore_column :bar, remove_with: '14.3', remove_after: '2021-09-22'
end
RUBY
end
end
context 'when only EE model exist' do
let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
before do
allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(false)
end
it 'flags ignore_columns usage in EE model' do
expect_no_offenses(<<~RUBY, file_path)
class Bar < ApplicationRecord
ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
end
RUBY
end
it 'flags ignore_column usage in EE model' do
expect_no_offenses(<<~RUBY, file_path)
class Bar < ApplicationRecord
ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
end
RUBY
end
end
context 'when CE and EE model exist' do
let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
before do
allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(true)
end
it 'flags ignore_columns usage in EE model' do
expect_offense(<<~RUBY, file_path)
class Bar < ApplicationRecord
ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
end
RUBY
end
it 'flags ignore_column usage in EE model' do
expect_offense(<<~RUBY, file_path)
class Bar < ApplicationRecord
ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
end
RUBY
end
end
private
def full_path(path)
rails_root = '../../../'
File.expand_path(File.join(rails_root, path), __dir__)
end
end
|