Skip to content

Commit

Permalink
[Fix rubocop#6330] Fix an error for Rails/ReversibleMigration
Browse files Browse the repository at this point in the history
Fixes rubocop#6330 and follow up of rubocop#6198.

This PR fixes an error for `Rails/ReversibleMigration`
when using variable assignment.
  • Loading branch information
koic authored and bbatsov committed Sep 26, 2018
1 parent 4d94114 commit 9993896
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6330](https://github.com/rubocop-hq/rubocop/issues/6330): Fix an error for `Rails/ReversibleMigration` when using variable assignment. ([@koic][], [@scottmatthewman][])

## 0.59.2 (2018-09-24)

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/reversible_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def check_change_table_node(node, block)
end

def check_change_table_offense(receiver, node)
return unless node.send_type?

method_name = node.method_name
return if receiver != node.receiver &&
!IRREVERSIBLE_CHANGE_TABLE_CALLS.include?(method_name)
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/rails/reversible_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def change
RUBY
end

context 'when using variable assignment' do
it_behaves_like 'accepts', 'create_table', <<-RUBY
def change
change_table :invoices do |t|
decimals_params = {precision: 10, scale: 2}
t.decimal :total_discount, decimals_params
end
end
RUBY
end

context 'within #reversible' do
it_behaves_like 'accepts', 'execute', <<-RUBY
reversible do |dir|
Expand Down

0 comments on commit 9993896

Please sign in to comment.