/
order_field_spec.rb
58 lines (50 loc) · 1.32 KB
/
order_field_spec.rb
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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Sevencop::OrderField, :config do
context 'without field' do
it 'registers no offense' do
expect_no_offenses(<<~TEXT)
articles.order('id DESC')
TEXT
end
end
context 'with Hash' do
it 'registers no offense' do
expect_no_offenses(<<~TEXT)
articles.order(id: :desc)
TEXT
end
end
context 'with receiver' do
it 'autocorrects offense' do
expect_offense(<<~TEXT)
articles.order('field(id, ?)', a)
^^^^^^^^^^^^^^ Wrap safe SQL String by `Arel.sql`.
TEXT
expect_correction(<<~RUBY)
articles.order(Arel.sql('field(id, ?)'), a)
RUBY
end
end
context 'without receiver' do
it 'autocorrects offense' do
expect_offense(<<~TEXT)
order('field(id, ?)', a)
^^^^^^^^^^^^^^ Wrap safe SQL String by `Arel.sql`.
TEXT
expect_correction(<<~RUBY)
order(Arel.sql('field(id, ?)'), a)
RUBY
end
end
context 'with reorder' do
it 'autocorrects offense' do
expect_offense(<<~TEXT)
reorder('field(id, ?)', a)
^^^^^^^^^^^^^^ Wrap safe SQL String by `Arel.sql`.
TEXT
expect_correction(<<~RUBY)
reorder(Arel.sql('field(id, ?)'), a)
RUBY
end
end
end