diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e036e8717..51e77977d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rubocop/cop/rails/reversible_migration.rb b/lib/rubocop/cop/rails/reversible_migration.rb index 04f39aef11..948f65da75 100644 --- a/lib/rubocop/cop/rails/reversible_migration.rb +++ b/lib/rubocop/cop/rails/reversible_migration.rb @@ -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 diff --git a/spec/rubocop/cop/rails/reversible_migration_spec.rb b/spec/rubocop/cop/rails/reversible_migration_spec.rb index e42a6644ff..2b36341511 100644 --- a/spec/rubocop/cop/rails/reversible_migration_spec.rb +++ b/spec/rubocop/cop/rails/reversible_migration_spec.rb @@ -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]