Skip to content
Browse files

Skip absent properties when importing

To avoid filling your object with nil stuff
  • Loading branch information...
1 parent 386a1be commit b8240101fc328905b2cee712ec86933c6dadb466 @jhchabran jhchabran committed
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/vintner/importer.rb
  2. +5 −0 spec/vintner/representer_spec.rb
View
2 lib/vintner/importer.rb
@@ -14,7 +14,7 @@ def import representer, model, hash
if object.is_a? Importer
object.import representer, model, hash[key.to_s]
else
- if hash && object.respond_to?(:import)
+ if hash && hash.has_key?(key) && object.respond_to?(:import)
object.import model, hash[key]
end
end
View
5 spec/vintner/representer_spec.rb
@@ -178,6 +178,11 @@ class Dummy
it "should not whine about it if it is absent" do
Dummy.new(@model).from_json(@hash.except(:meta).to_json)
end
+
+ it "should not import nil when a property isn't present" do
+ Dummy.import(@model, {:meta => {:version => 4}})
+ @model.formatted_title.should ==("test")
+ end
end
end

0 comments on commit b824010

Please sign in to comment.
Something went wrong with that request. Please try again.