Skip to content

Commit

Permalink
Fix an error for UniqueValidationWithoutIndex when db/schema.rb i…
Browse files Browse the repository at this point in the history
…s empty
  • Loading branch information
fatkodima committed Jun 28, 2023
1 parent 297e022 commit 0ee4ef5
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 0ee4ef5

Please sign in to comment.