Skip to content

Commit

Permalink
[Fix rubocop#43] REMOVE change_column_null from BulkChangeTable
Browse files Browse the repository at this point in the history
The `change_column_null` method does not have corresponding method to
use in the suggested `change_table` version.

We should remove it from the offended methods list.
  • Loading branch information
Anthony Robin committed Jun 11, 2019
1 parent b905723 commit 0582a9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 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

* [#43](https://github.com/rubocop-hq/rubocop-rails/issues/43): REMOVE `change_column_null` method from `BulkChangeTable` cop offenses. ([@anthony-robin][])

## 2.0.1 (2019-06-08)

### Changes
Expand All @@ -18,3 +22,4 @@
[@koic]: https://github.com/koic
[@andyw8]: https://github.com/andyw8
[@buehmann]: https://github.com/buehmann
[@anthony-robin]: https://github.com/anthony-robin
1 change: 0 additions & 1 deletion lib/rubocop/cop/rails/bulk_change_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class BulkChangeTable < Cop

POSTGRESQL_COMBINABLE_ALTER_METHODS = %i[
change_column_default
change_column_null
].freeze

def on_def(node)
Expand Down
18 changes: 17 additions & 1 deletion spec/rubocop/cop/rails/bulk_change_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,18 @@ def change

it 'registers an offense when including combinable alter methods' do
expect_offense(<<~RUBY)
def change
change_column_default :users, :name, false
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can use `change_table :users, bulk: true` to combine alter queries.
change_column_default :users, :address, false
end
RUBY
end

it 'does not register an offense for `change_column_null`' do
expect_no_offenses(<<-RUBY.strip_indent)
def change
change_column_null :users, :name, false
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can use `change_table :users, bulk: true` to combine alter queries.
change_column_null :users, :address, false
end
RUBY
Expand All @@ -139,6 +148,13 @@ def change
it 'does not register an offense' \
'when including combinable alter methods' do
expect_no_offenses(<<~RUBY)
def change
change_column_default :users, :name, false
change_column_default :users, :address, false
end
RUBY

expect_no_offenses(<<-RUBY.strip_indent)
def change
change_column_null :users, :name, false
change_column_null :users, :address, false
Expand Down

0 comments on commit 0582a9d

Please sign in to comment.