Permalink
Browse files

Fix for nil FKs on a belongs_to association (#428)

  • Loading branch information...
mereghost authored and jodosha committed Aug 8, 2017
1 parent d17de4f commit 14e9841f5d6f9ad8c3bcbcd5a80b57425343c2cf
Showing with 8 additions and 0 deletions.
  1. +1 −0 lib/hanami/model/types.rb
  2. +7 −0 spec/integration/hanami/model/associations/belongs_to_spec.rb
@@ -47,6 +47,7 @@ class CoercibleType < Dry::Types::Definition
# @since 0.7.0
# @api private
def call(value)
return if value.nil?
if valid?(value)
coerce(value)
else
@@ -25,4 +25,11 @@

expect(found).to eq(author)
end

it "returns nil if there's no associated record" do
repository = BookRepository.new
book = repository.create(title: 'The no author book')

expect { repository.find_with_author(book.id) }.to_not raise_error
end
end

0 comments on commit 14e9841

Please sign in to comment.