Skip to content

Commit 809fd54

Browse files
committed
Cut 2.25.0
1 parent 0576d54 commit 809fd54

File tree

7 files changed

+122
-14
lines changed

7 files changed

+122
-14
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
## master (unreleased)
1111

12+
## 2.25.0 (2024-05-17)
13+
1214
### New features
1315

1416
* [#1272](https://github.com/rubocop/rubocop-rails/pull/1272): Add new `Rails/WhereRange` cop. ([@fatkodima][])

Diff for: config/default.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ Rails/UnusedIgnoredColumns:
11651165
Description: 'Remove a column that does not exist from `ignored_columns`.'
11661166
Enabled: false
11671167
VersionAdded: '2.11'
1168-
VersionChanged: <<next>>
1168+
VersionChanged: '2.25'
11691169
Include:
11701170
- app/models/**/*.rb
11711171

@@ -1226,7 +1226,7 @@ Rails/WhereRange:
12261226
Description: 'Use ranges in `where` instead of manually constructing SQL.'
12271227
StyleGuide: 'https://rails.rubystyle.guide/#where-ranges'
12281228
Enabled: pending
1229-
VersionAdded: '<<next>>'
1229+
VersionAdded: '2.25'
12301230

12311231
# Accept `redirect_to(...) and return` and similar cases.
12321232
Style/AndOr:

Diff for: docs/antora.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ name: rubocop-rails
22
title: RuboCop Rails
33
# We always provide version without patch here (e.g. 1.1),
44
# as patch versions should not appear in the docs.
5-
version: ~
5+
version: '2.25'
66
nav:
77
- modules/ROOT/nav.adoc

Diff for: docs/modules/ROOT/pages/cops.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,6 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
145145
* xref:cops_rails.adoc#railswheremissing[Rails/WhereMissing]
146146
* xref:cops_rails.adoc#railswherenot[Rails/WhereNot]
147147
* xref:cops_rails.adoc#railswherenotwithmultipleconditions[Rails/WhereNotWithMultipleConditions]
148+
* xref:cops_rails.adoc#railswhererange[Rails/WhereRange]
148149

149150
// END_COP_LIST

Diff for: docs/modules/ROOT/pages/cops_rails.adoc

+91-10
Original file line numberDiff line numberDiff line change
@@ -2661,13 +2661,17 @@ render json: { foo: 'bar' }, status: 200
26612661
render plain: 'foo/bar', status: 304
26622662
redirect_to root_url, status: 301
26632663
head 200
2664+
assert_response 200
2665+
assert_redirected_to '/some/path', status: 301
26642666
26652667
# good
26662668
render :foo, status: :ok
26672669
render json: { foo: 'bar' }, status: :ok
26682670
render plain: 'foo/bar', status: :not_modified
26692671
redirect_to root_url, status: :moved_permanently
26702672
head :ok
2673+
assert_response :ok
2674+
assert_redirected_to '/some/path', status: :moved_permanently
26712675
----
26722676
26732677
==== EnforcedStyle: numeric
@@ -2680,13 +2684,17 @@ render json: { foo: 'bar' }, status: :not_found
26802684
render plain: 'foo/bar', status: :not_modified
26812685
redirect_to root_url, status: :moved_permanently
26822686
head :ok
2687+
assert_response :ok
2688+
assert_redirected_to '/some/path', status: :moved_permanently
26832689
26842690
# good
26852691
render :foo, status: 200
26862692
render json: { foo: 'bar' }, status: 404
26872693
render plain: 'foo/bar', status: 304
26882694
redirect_to root_url, status: 301
26892695
head 200
2696+
assert_response 200
2697+
assert_redirected_to '/some/path', status: 301
26902698
----
26912699
26922700
=== Configurable attributes
@@ -3659,13 +3667,25 @@ hash.exclude?(:key)
36593667
| 2.20
36603668
|===
36613669
3662-
Checks for add_column call with NOT NULL constraint in migration file.
3670+
Checks for add_column calls with a NOT NULL constraint without a default
3671+
value.
36633672
3664-
`TEXT` can have default values in PostgreSQL, but not in MySQL.
3665-
It will automatically detect an adapter from `development` environment
3666-
in `config/database.yml` or the environment variable `DATABASE_URL`
3667-
when the `Database` option is not set. If the database is MySQL,
3668-
this cop ignores offenses for the `TEXT`.
3673+
This cop only applies when adding a column to an existing table, since
3674+
existing records will not have a value for the new column. New tables
3675+
can freely use NOT NULL columns without defaults, since there are no
3676+
records that could violate the constraint.
3677+
3678+
If you need to add a NOT NULL column to an existing table, you must add
3679+
it as nullable first, back-fill the data, and then use
3680+
`change_column_null`. Alternatively, you could add the column with a
3681+
default first to have the database automatically backfill existing rows,
3682+
and then use `change_column_default` to remove the default.
3683+
3684+
`TEXT` cannot have a default value in MySQL.
3685+
The cop will automatically detect an adapter from `development`
3686+
environment in `config/database.yml` or the environment variable
3687+
`DATABASE_URL` when the `Database` option is not set. If the database
3688+
is MySQL, this cop ignores offenses for `TEXT` columns.
36693689
36703690
=== Examples
36713691
@@ -3674,12 +3694,18 @@ this cop ignores offenses for the `TEXT`.
36743694
# bad
36753695
add_column :users, :name, :string, null: false
36763696
add_reference :products, :category, null: false
3697+
change_table :users do |t|
3698+
t.string :name, null: false
3699+
end
36773700
36783701
# good
36793702
add_column :users, :name, :string, null: true
36803703
add_column :users, :name, :string, null: false, default: ''
3704+
change_table :users do |t|
3705+
t.string :name, null: false, default: ''
3706+
end
36813707
add_reference :products, :category
3682-
add_reference :products, :category, null: false, default: 1
3708+
change_column_null :products, :category_id, false
36833709
----
36843710
36853711
=== Configurable attributes
@@ -3869,6 +3895,10 @@ Using `pluck` followed by `first` creates an intermediate array, which
38693895
`pick` avoids. When called on an Active Record relation, `pick` adds a
38703896
limit to the query so that only one value is fetched from the database.
38713897
3898+
Note that when `pick` is added to a relation with an existing limit, it
3899+
causes a subquery to be added. In most cases this is undesirable, and
3900+
care should be taken while resolving this violation.
3901+
38723902
=== Safety
38733903
38743904
This cop is unsafe because `pluck` is defined on both `ActiveRecord::Relation` and `Enumerable`,
@@ -6612,17 +6642,23 @@ Rails.env == 'production'
66126642
|===
66136643
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
66146644
6615-
| Pending
6645+
| Disabled
66166646
| Yes
66176647
| No
66186648
| 2.11
6619-
| -
6649+
| 2.25
66206650
|===
66216651
66226652
Suggests you remove a column that does not exist in the schema from `ignored_columns`.
66236653
`ignored_columns` is necessary to drop a column from RDBMS, but you don't need it after the migration
66246654
to drop the column. You avoid forgetting to remove `ignored_columns` by this cop.
66256655
6656+
IMPORTANT: This cop can't be used to effectively check for unused columns because the development
6657+
and production schema can be out of sync until the migration has been run on production. As such,
6658+
this cop can cause `ignored_columns` to be removed even though the production schema still contains
6659+
the column, which can lead to downtime when the migration is actually executed. Only enable this cop
6660+
if you know your migrations will be run before any of your Rails applications boot with the modified code.
6661+
66266662
=== Examples
66276663
66286664
[source,ruby]
@@ -6729,7 +6765,7 @@ validates :foo, length: true
67296765
validates :foo, numericality: true
67306766
validates :foo, presence: true
67316767
validates :foo, absence: true
6732-
validates :foo, size: true
6768+
validates :foo, length: true
67336769
validates :foo, uniqueness: true
67346770
----
67356771
@@ -6984,3 +7020,48 @@ User.where.not('trashed = ? OR role = ?', true, 'admin')
69847020
=== References
69857021
69867022
* https://rails.rubystyle.guide/#where-not-with-multiple-attributes
7023+
7024+
== Rails/WhereRange
7025+
7026+
NOTE: Required Ruby version: 2.6
7027+
7028+
|===
7029+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
7030+
7031+
| Pending
7032+
| Yes
7033+
| Always
7034+
| 2.25
7035+
| -
7036+
|===
7037+
7038+
Identifies places where manually constructed SQL
7039+
in `where` can be replaced with ranges.
7040+
7041+
=== Examples
7042+
7043+
[source,ruby]
7044+
----
7045+
# bad
7046+
User.where('age >= ?', 18)
7047+
User.where.not('age >= ?', 18)
7048+
User.where('age < ?', 18)
7049+
User.where('age >= ? AND age < ?', 18, 21)
7050+
User.where('age >= :start', start: 18)
7051+
User.where('users.age >= ?', 18)
7052+
7053+
# good
7054+
User.where(age: 18..)
7055+
User.where.not(age: 18..)
7056+
User.where(age: ...18)
7057+
User.where(age: 18...21)
7058+
User.where(users: { age: 18.. })
7059+
7060+
# good
7061+
# There are no beginless ranges in ruby.
7062+
User.where('age > ?', 18)
7063+
----
7064+
7065+
=== References
7066+
7067+
* https://rails.rubystyle.guide/#where-ranges

Diff for: lib/rubocop/rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RuboCop
44
module Rails
55
# This module holds the RuboCop Rails version information.
66
module Version
7-
STRING = '2.24.1'
7+
STRING = '2.25.0'
88

99
def self.document_version
1010
STRING.match('\d+\.\d+').to_s

Diff for: relnotes/v2.25.0.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### New features
2+
3+
* [#1272](https://github.com/rubocop/rubocop-rails/pull/1272): Add new `Rails/WhereRange` cop. ([@fatkodima][])
4+
5+
### Bug fixes
6+
7+
* [#1270](https://github.com/rubocop/rubocop-rails/issues/1270): Fix an incorrect autocorrect for `Rails/Validation` when using `validates_size_of`. ([@koic][])
8+
* [#1278](https://github.com/rubocop/rubocop-rails/issues/1278): Fix a false positive for `Rails/SkipsModelValidations` when using `insert` or `insert!` with a safe navigator. ([@tldn0718][])
9+
* [#1260](https://github.com/rubocop/rubocop-rails/issues/1260): Fix a performance regression caused by `Rails/UnknownEnv` when using Rails 7.1. ([@lukasfroehlich1][])
10+
11+
### Changes
12+
13+
* [#1249](https://github.com/rubocop/rubocop-rails/issues/1249): Disable `Rails/UnusedIgnoredColumns` by default. ([@earlopain][])
14+
* [#1266](https://github.com/rubocop/rubocop-rails/pull/1266): Check `change_table` calls for offenses. ([@ccutrer][])
15+
* [#1267](https://github.com/rubocop/rubocop-rails/pull/1267): Make `Rails/HttpStatus` aware of Rails-specific response assertions. ([@tldn0718][])
16+
* [#1137](https://github.com/rubocop/rubocop-rails/pull/1137): Migrate to `TargetRailsVersion` the new [`requires_gem` API](https://github.com/rubocop/rubocop/pull/12186). ([@amomchilov][])
17+
18+
[@fatkodima]: https://github.com/fatkodima
19+
[@koic]: https://github.com/koic
20+
[@tldn0718]: https://github.com/tldn0718
21+
[@lukasfroehlich1]: https://github.com/lukasfroehlich1
22+
[@earlopain]: https://github.com/earlopain
23+
[@ccutrer]: https://github.com/ccutrer
24+
[@amomchilov]: https://github.com/amomchilov

0 commit comments

Comments
 (0)