Skip to content

Commit

Permalink
Merge pull request #1248 from koic/fix_an_error_for_rails_unused_igno…
Browse files Browse the repository at this point in the history
…red_column

[Fix #1247] Fix an error for `Rails/UnusedIgnoredColumns`
  • Loading branch information
koic authored Mar 5, 2024
2 parents 56d11bd + 7864209 commit 83c0968
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 83c0968

Please sign in to comment.