Skip to content

Commit

Permalink
[Fix rubocop#357] Fix a false positive for Rails/ReversibleMigration
Browse files Browse the repository at this point in the history
Fixes rubocop#357.

This PR fixes a false positive for `Rails/ReversibleMigration`
when keyword arguments of `change_column_default` are in the
order of `to`, `from`.
  • Loading branch information
koic committed Sep 15, 2020
1 parent 3ec7cda commit 99515d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [#351](https://github.com/rubocop-hq/rubocop-rails/pull/351): Add `<>` operator to `Rails/WhereNot` cop. ([@Tietew][])
* [#352](https://github.com/rubocop-hq/rubocop-rails/pull/352): Do not register offense if given a splatted hash. ([@dvandersluis][])
* [#346](https://github.com/rubocop-hq/rubocop-rails/pull/346): Fix a false positive for `Rails/DynamicFindBy` when any of the arguments are splat argument. ([@koic][])
* [#357](https://github.com/rubocop-hq/rubocop-rails/issues/357): Fix a false positive for `Rails/ReversibleMigration` when keyword arguments of `change_column_default` are in the order of `to`, `from`. ([@koic][])

## 2.8.0 (2020-09-04)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def all_hash_key?(args, *keys)
key.children.first.to_sym
end

hash_keys & keys == keys
(hash_keys & keys).sort == keys
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/rails/reversible_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def change
change_column_default(:posts, :state, from: nil, to: "draft")
RUBY

it_behaves_like 'accepts',
'change_column_default(with :to and :from)', <<-RUBY
change_column_default(:posts, :state, to: "draft", from: nil)
RUBY

it_behaves_like 'accepts',
'change_column_default(*column :from and :to)', <<-RUBY
columns = [:foo, :bar]
Expand Down

0 comments on commit 99515d0

Please sign in to comment.