Skip to content

Commit

Permalink
[Fix rubocop#1247] Fix an error for Rails/UnusedIgnoredColumns
Browse files Browse the repository at this point in the history
Fixes rubocop#1247.

This PR fixes an error for `Rails/UnusedIgnoredColumns`
when without tables in db/schema.rb.
  • Loading branch information
koic committed Mar 5, 2024
1 parent 56d11bd commit 7864209
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_rails_unused_ignored_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1247](https://github.com/rubocop/rubocop-rails/issues/1247): Fix an error for `Rails/UnusedIgnoredColumns` when without tables in db/schema.rb. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/rails/schema_loader/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def add_indices_by(table_name:)

def build!(ast)
raise "Unexpected type: #{ast.type}" unless ast.block_type?
return unless ast.body

each_table(ast) do |table_def|
next unless table_def.method?(:create_table)
Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cop/rails/unused_ignored_columns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ class User < ApplicationRecord
context 'with no tables db/schema.rb' do
include_context 'with SchemaLoader'

let(:schema) { <<~RUBY }
ActiveRecord::Schema.define(version: 2020_02_02_075409) do
end
RUBY

context 'with an unused ignored column as a Symbol' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class User < ApplicationRecord
self.ignored_columns = [:real_name]
end
RUBY
end
end
end

context 'with `enable_extension` and no tables db/schema.rb' do
include_context 'with SchemaLoader'

let(:schema) { <<~RUBY }
ActiveRecord::Schema.define(version: 2020_02_02_075409) do
enable_extension 'plpgsql'
Expand Down

0 comments on commit 7864209

Please sign in to comment.