diff --git a/lib/representable/hash/binding.rb b/lib/representable/hash/binding.rb index ac54c254..4144d2f8 100644 --- a/lib/representable/hash/binding.rb +++ b/lib/representable/hash/binding.rb @@ -10,6 +10,7 @@ def self.build_for(definition) end def read(hash, as) + return FragmentNotFound unless hash hash.has_key?(as) ? hash[as] : FragmentNotFound end diff --git a/test/hash_bindings_test.rb b/test/hash_bindings_test.rb index 048b3cf9..53878f0f 100644 --- a/test/hash_bindings_test.rb +++ b/test/hash_bindings_test.rb @@ -28,6 +28,9 @@ class SongWithRepresenter < ::Song assert_equal Representable::Binding::FragmentNotFound, @property.read({}, "song") end + it "will not fail if given an empty hash value and will return FRAGMENT_NOT_FOUND" do + assert_equal Representable::Binding::FragmentNotFound, @property.read(nil, "song") + end end end