File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change
1
+ * [ #1282 ] ( https://github.com/rubocop/rubocop-rails/issues/1282 ) : Fix ` WhereRange ` to correctly handle template strings with extra spaces. ([ @fatkodima ] [ ] )
Original file line number Diff line number Diff line change @@ -37,17 +37,17 @@ class WhereRange < Base
37
37
RESTRICT_ON_SEND = %i[ where not ] . freeze
38
38
39
39
# column >= ?
40
- GTEQ_ANONYMOUS_RE = /\A ([\w .]+)\s +>=\s +\? \z / . freeze
40
+ GTEQ_ANONYMOUS_RE = /\A \s * ([\w .]+)\s +>=\s +\? \s * \z / . freeze
41
41
# column <[=] ?
42
- LTEQ_ANONYMOUS_RE = /\A ([\w .]+)\s +(<=?)\s +\? \z / . freeze
42
+ LTEQ_ANONYMOUS_RE = /\A \s * ([\w .]+)\s +(<=?)\s +\? \s * \z / . freeze
43
43
# column >= ? AND column <[=] ?
44
- RANGE_ANONYMOUS_RE = /\A ([\w .]+)\s +>=\s +\? \s +AND\s +\1 \s +(<=?)\s +\? \z /i . freeze
44
+ RANGE_ANONYMOUS_RE = /\A \s * ([\w .]+)\s +>=\s +\? \s +AND\s +\1 \s +(<=?)\s +\? \s * \z /i . freeze
45
45
# column >= :value
46
- GTEQ_NAMED_RE = /\A ([\w .]+)\s +>=\s +:(\w +)\z / . freeze
46
+ GTEQ_NAMED_RE = /\A \s * ([\w .]+)\s +>=\s +:(\w +)\s * \z / . freeze
47
47
# column <[=] :value
48
- LTEQ_NAMED_RE = /\A ([\w .]+)\s +(<=?)\s +:(\w +)\z / . freeze
48
+ LTEQ_NAMED_RE = /\A \s * ([\w .]+)\s +(<=?)\s +:(\w +)\s * \z / . freeze
49
49
# column >= :value1 AND column <[=] :value2
50
- RANGE_NAMED_RE = /\A ([\w .]+)\s +>=\s +:(\w +)\s +AND\s +\1 \s +(<=?)\s +:(\w +)\z /i . freeze
50
+ RANGE_NAMED_RE = /\A \s * ([\w .]+)\s +>=\s +:(\w +)\s +AND\s +\1 \s +(<=?)\s +:(\w +)\s * \z /i . freeze
51
51
52
52
minimum_target_ruby_version 2.6
53
53
minimum_target_rails_version 6.0
Original file line number Diff line number Diff line change 142
142
RUBY
143
143
end
144
144
145
+ it 'correctly handles spaces in the template string' do
146
+ expect_offense ( <<~RUBY )
147
+ Model.where(' column >= ? ', value)
148
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `where(column: value..)` instead of manually constructing SQL.
149
+ Model.where(' column >= :min ', min: value)
150
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `where(column: value..)` instead of manually constructing SQL.
151
+ Model.where(' column >= ? AND column < ? ', value1, value2)
152
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `where(column: value1...value2)` instead of manually constructing SQL.
153
+ Model.where(' column >= :min AND column < :max ', min: value1, max: value2)
154
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `where(column: value1...value2)` instead of manually constructing SQL.
155
+ RUBY
156
+ end
157
+
145
158
it 'does not register an offense when using ranges' do
146
159
expect_no_offenses ( <<~RUBY )
147
160
Model.where(column: value..)
You can’t perform that action at this time.
0 commit comments