@@ -2661,13 +2661,17 @@ render json: { foo: 'bar' }, status: 200
26612661render plain: 'foo/bar', status: 304
26622662redirect_to root_url, status: 301
26632663head 200
2664+ assert_response 200
2665+ assert_redirected_to '/some/path', status: 301
26642666
26652667# good
26662668render :foo, status: :ok
26672669render json: { foo: 'bar' }, status: :ok
26682670render plain: 'foo/bar', status: :not_modified
26692671redirect_to root_url, status: :moved_permanently
26702672head :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
26802684render plain: 'foo/bar', status: :not_modified
26812685redirect_to root_url, status: :moved_permanently
26822686head :ok
2687+ assert_response :ok
2688+ assert_redirected_to '/some/path', status: :moved_permanently
26832689
26842690# good
26852691render :foo, status: 200
26862692render json: { foo: 'bar' }, status: 404
26872693render plain: 'foo/bar', status: 304
26882694redirect_to root_url, status: 301
26892695head 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
36753695add_column :users, :name, :string, null: false
36763696add_reference :products, :category, null: false
3697+ change_table :users do |t|
3698+ t.string :name, null: false
3699+ end
36773700
36783701# good
36793702add_column :users, :name, :string, null: true
36803703add_column :users, :name, :string, null: false, default: ''
3704+ change_table :users do |t|
3705+ t.string :name, null: false, default: ''
3706+ end
36813707add_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
38703896limit 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
38743904This 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
66226652Suggests 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
66246654to 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
67296765validates :foo, numericality: true
67306766validates :foo, presence: true
67316767validates :foo, absence: true
6732- validates :foo, size : true
6768+ validates :foo, length : true
67336769validates :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
0 commit comments