Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash value of null breaks parsing #264

Merged
merged 3 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/representable/hash/binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test/hash_bindings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ 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
not_failed = true
result = nil
begin
result = @property.read(nil, "song")
rescue NoMethodError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toadle we don't have to consider rescuing NoMethodError now as we know it shouldn't occur. If it does, then it must be due to some other bug and should be handled differently.

So in this test, we can just assert on return value of read, like in above test.

it "..." do
  assert_equal Representable::Binding::FragmentNotFound, @property.read(nil, "song")
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yogeshjain999 here you go

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yogeshjain999 Wanna merge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, almost forgot :)

not_failed = false
end
assert not_failed
assert_equal Representable::Binding::FragmentNotFound, result
end
end
end

Expand Down