Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions lib/representable/deserializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def call(fragment)
@object = @binding.create_object(fragment)
end

return if @binding.options[:ignore_nil_instance] && @object == fragment

# DISCUSS: what parts should be in this class, what in Binding?
representable = prepare(@object)
deserialize(representable, fragment, @binding.user_options)
Expand Down
11 changes: 11 additions & 0 deletions test/representable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,17 @@ def compute_representer(name)
song.name.must_equal obj
song.name.must_be_kind_of mod
end

describe "with :ignore_nil_instance set and the instance being nil" do
representer! do
property :name, :extend => mod, :instance => lambda { |*| nil }, :ignore_nil_instance => true
end

it "does not evaluate the property" do
song = Song.new.extend(representer).from_hash("name" => "Eric's Had A Bad Day")
song.name.must_be_nil
end
end
end

describe "property with :extend" do
Expand Down