Skip to content

Commit

Permalink
Merge pull request #1038 from fatkodima/fix-unique_validation_without…
Browse files Browse the repository at this point in the history
…_index-empty-schema

Fix an error for `UniqueValidationWithoutIndex` when `db/schema.rb` is empty
  • Loading branch information
koic authored Jun 30, 2023
2 parents 297e022 + 0ee4ef5 commit b040d84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1036](https://github.com/rubocop/rubocop-rails/issues/1036): Fix an error for `UniqueValidationWithoutIndex` when `db/schema.rb` is empty. ([@fatkodima][])
2 changes: 1 addition & 1 deletion lib/rubocop/rails/schema_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def load!(target_ruby_version)
return unless path

ast = parse(path, target_ruby_version)
Schema.new(ast)
Schema.new(ast) if ast
end

def parse(path, target_ruby_version)
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/rails/unique_validation_without_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,5 +690,17 @@ module User
RUBY
end
end

context 'when db/schema.rb file is empty' do
let(:schema) { '' }

it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class User
validates :account, uniqueness: true
end
RUBY
end
end
end
end

0 comments on commit b040d84

Please sign in to comment.