Commits

Anonymous committed e56b5c6

Improve handling of properties we don't know about.

Allow the NoMethodError to happen rather than eating it with the
rescue.

  • Participants
  • Parent commits f67d8d2

Comments (0)

Files changed (2)

File ripple/lib/ripple/document/finders.rb

           klass = robject.data['_type'].constantize rescue self
           klass.new.tap do |doc|
             doc.key = robject.key
-            robject.data.except("_type").each {|k,v| doc.send("#{k}=", v) } rescue nil
+            robject.data.except("_type").each {|k,v| doc.send("#{k}=", v) } if robject.data
             doc.instance_variable_set(:@new, false)
             doc.instance_variable_set(:@robject, robject)
           end

File ripple/spec/ripple/finders_spec.rb

       lambda { Box.find!("square") }.should_not raise_error(Ripple::DocumentNotFound)
     end
 
+    it "should raise an exception when finding an existing document that has properties we don't know about" do
+      @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"non_existent_property":"whatever"}'})
+      lambda { Box.find("square") }.should raise_error
+    end
+
     it "should return the document when calling find!" do
       @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
       box = Box.find!("square")