Skip to content
Browse files

"Fix" tests. Private methods strike again.

  • Loading branch information...
1 parent b317c76 commit 42baf8be6d5e3cdee73739277b6ece946b2742eb @elliotcm committed
View
1 lib/document/serialization/hash_serializer.rb
@@ -17,7 +17,6 @@ def dump(object_to_serialize, current_depth=0)
end
end
- private
def serialize_array(object_to_serialize, current_depth)
object_to_serialize.map do |entry|
Serializer.serialize(entry, current_depth + 1)
View
1 lib/document/serialization/serializer.rb
@@ -43,7 +43,6 @@ def serialize(object_to_serialize, depth=0)
serializer.marshal
end
- private
def array_deserialize(array)
array.map do |entry|
deserialize(entry)
View
2 spec/document/persistence_spec.rb
@@ -103,7 +103,7 @@ class TestClass
@test_class_collection.should_receive(:find).and_return([@no_query_results])
TestClass.find.should == [@no_query_object]
- @test_class_collection.should_receive(:find).with(query = mock(:query)).and_return([@query_results])
+ @test_class_collection.should_receive(:find).with({'_id' => query = mock(:query)}).and_return([@query_results])
TestClass.find(query).should == [@query_object]
end
end
View
4 spec/document/serialization/hash_serializer_spec.rb
@@ -28,7 +28,7 @@ def initialize
end
it "hashifies the object" do
- HashSerializer.send(:serialize_object, @object, @current_depth).
+ HashSerializer.send(:serialize_object, @object, @current_depth+3).
should == {'_class_name' => 'Other', 'name' => @object.name}
end
end
@@ -50,7 +50,7 @@ class TestClass
it "exports the object" do
HashSerializer.send(:serialize_object, @object, @current_depth).
- should == {'_class_name' => 'TestClass', '_id' => @id}
+ should == {'_class_name' => 'TestClass', '_id' => @id, '_embed' => true}
end
end
View
71 spec/document/serialization/serializer_spec.rb
@@ -1,6 +1,8 @@
require File.dirname(__FILE__) + '/../../../lib/document/serialization'
-describe LightMongo::Document::Serialization::Serializer do
+Serializer = LightMongo::Document::Serialization::Serializer
+
+describe Serializer do
before(:each) do
@object = mock(:object)
end
@@ -14,15 +16,13 @@
end
it "map-deserializes each element in the array" do
- LightMongo::Document::Serialization::Serializer.
- should_receive(:deserialize).with(@ivar1).
+ Serializer.should_receive(:deserialize).with(@ivar1).
and_return(desel_ivar1 = mock(:desel_ivar1))
- LightMongo::Document::Serialization::Serializer.
- should_receive(:deserialize).with(@ivar2).
+ Serializer.should_receive(:deserialize).with(@ivar2).
and_return(desel_ivar2 = mock(:desel_ivar2))
- LightMongo::Document::Serialization::Serializer.send(:array_deserialize, @object).
+ Serializer.send(:array_deserialize, @object).
should == [desel_ivar1, desel_ivar2]
end
end
@@ -36,15 +36,13 @@
end
it "map-deserializes each element in the hash" do
- LightMongo::Document::Serialization::Serializer.
- should_receive(:deserialize).with(@ivar1).
+ Serializer.should_receive(:deserialize).with(@ivar1).
and_return(desel_ivar1 = mock(:desel_ivar1))
- LightMongo::Document::Serialization::Serializer.
- should_receive(:deserialize).with(@ivar2).
+ Serializer.should_receive(:deserialize).with(@ivar2).
and_return(desel_ivar2 = mock(:desel_ivar2))
- LightMongo::Document::Serialization::Serializer.send(:hash_deserialize, @object).
+ Serializer.send(:hash_deserialize, @object).
should == {:ivar1 => desel_ivar1, :ivar2 => desel_ivar2}
end
end
@@ -56,12 +54,10 @@
end
it "deserializes the array" do
- LightMongo::Document::Serialization::Serializer.
- should_receive(:array_deserialize).with(@object).
+ Serializer.should_receive(:array_deserialize).with(@object).
and_return(desel_array = mock(:desel_array))
- LightMongo::Document::Serialization::Serializer.deserialize(@object).
- should == desel_array
+ Serializer.deserialize(@object).should == desel_array
end
end
@@ -72,8 +68,8 @@
context "and nothing more" do
it "deserializes the hash" do
- LightMongo::Document::Serialization::Serializer.should_receive(:hash_deserialize).with(@object)
- LightMongo::Document::Serialization::Serializer.deserialize(@object)
+ Serializer.should_receive(:hash_deserialize).with(@object)
+ Serializer.deserialize(@object)
end
end
@@ -87,8 +83,7 @@
Marshal.should_receive(:load).with(@marshal_dump).
and_return(unmarshalled_data = mock(:unmarshalled_data))
- LightMongo::Document::Serialization::Serializer.deserialize(@object).
- should == unmarshalled_data
+ Serializer.deserialize(@object).should == unmarshalled_data
end
end
@@ -98,14 +93,13 @@ class TestClass
end
@id = mock(:id)
- @object = {'_id' => @id, '_class_name' => 'TestClass'}
+ @object = {'_id' => @id, '_class_name' => 'TestClass', '_embed' => true}
end
it "recovers the linked document" do
- TestClass.stub!(:find).with(@id).and_return(test_instance = mock(:test_instance))
+ TestClass.stub!(:find).with(@id).and_return([test_instance = mock(:test_instance)])
- LightMongo::Document::Serialization::Serializer.deserialize(@object).
- should == test_instance
+ Serializer.deserialize(@object).should == test_instance
end
end
end
@@ -116,8 +110,7 @@ class TestClass
end
it "returns the object unharmed" do
- LightMongo::Document::Serialization::Serializer.deserialize(@object).
- should == @object
+ Serializer.deserialize(@object).should == @object
end
end
end
@@ -125,28 +118,28 @@ class TestClass
describe ".serialize(object, current_depth)" do
before(:each) do
@depth = 0
- @serializer = LightMongo::Document::Serialization::Serializer.new(@object, @depth)
+ @serializer = Serializer.new(@object, @depth)
@serializer.stub!(:hash_serialize => (@hash_serialized_object = mock(:hash_serialized_object)))
- LightMongo::Document::Serialization::Serializer.stub!(:new).with(@object, anything).and_return(@serializer)
+ Serializer.stub!(:new).with(@object, anything).and_return(@serializer)
end
def self.it_creates_a_new_serializer_instance
it "creates a new serializer instance" do
- LightMongo::Document::Serialization::Serializer.should_receive(:new).with(@object, @depth).and_return(@serializer)
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth)
+ Serializer.should_receive(:new).with(@object, @depth).and_return(@serializer)
+ Serializer.serialize(@object, @depth)
end
end
def self.it_hash_serializes_the_object
it "hash-serializes the object." do
@serializer.should_receive(:hash_serialize)
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth)
+ Serializer.serialize(@object, @depth)
end
end
def self.it_returns_the_hash_serialized_object
it "returns the hash-serialized object." do
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth).should == @hash_serialized_object
+ Serializer.serialize(@object, @depth).should == @hash_serialized_object
end
end
@@ -161,7 +154,7 @@ def self.it_returns_the_hash_serialized_object
it "does not marshal the object." do
@serializer.should_not_receive(:marshal)
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth)
+ Serializer.serialize(@object, @depth)
end
it_returns_the_hash_serialized_object
@@ -181,17 +174,17 @@ def self.it_returns_the_hash_serialized_object
it "marshals the object." do
@serializer.should_receive(:marshal)
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth)
+ Serializer.serialize(@object, @depth)
end
it "does not hash-serialize the object." do
@serializer.should_not_receive(:hash_serialize)
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth)
+ Serializer.serialize(@object, @depth)
end
it "returns the marshalled object." do
@serializer.stub!(:marshal => (@marshalled_object = mock(:marshalled_object)))
- LightMongo::Document::Serialization::Serializer.serialize(@object, @depth).should == @marshalled_object
+ Serializer.serialize(@object, @depth).should == @marshalled_object
end
end
@@ -212,14 +205,14 @@ def self.it_returns_the_hash_serialized_object
describe "#marshal(object)" do
it "marshals the object." do
Marshal.should_receive(:dump).with(@object)
- LightMongo::Document::Serialization::Serializer.new(@object).marshal
+ Serializer.new(@object).marshal
end
it "returns the marshalled object." do
Marshal.stub!(:dump).
with(@object).
and_return(marshalled_object = mock(:marshalled_object))
- LightMongo::Document::Serialization::Serializer.new(@object).marshal.should == {'_data' => marshalled_object}
+ Serializer.new(@object).marshal.should == {'_data' => marshalled_object}
end
end
@@ -231,14 +224,14 @@ def self.it_returns_the_hash_serialized_object
it "serializes the object into a set of nested hashes." do
LightMongo::Document::Serialization::HashSerializer.
should_receive(:dump).with(@object, @current_depth)
- LightMongo::Document::Serialization::Serializer.new(@object, @current_depth).hash_serialize
+ Serializer.new(@object, @current_depth).hash_serialize
end
it "returns the marshalled object." do
LightMongo::Document::Serialization::HashSerializer.stub!(:dump).
with(@object, @current_depth).
and_return(hashed_object = mock(:hashed_object))
- LightMongo::Document::Serialization::Serializer.new(@object, @current_depth).hash_serialize.should == hashed_object
+ Serializer.new(@object, @current_depth).hash_serialize.should == hashed_object
end
end
end
View
12 spec/document/serialization_spec.rb
@@ -11,10 +11,6 @@ class TestClass
attr_accessor :test_attribute
end
end
-
- before(:each) do
- @test_object = TestClass.new
- end
describe "#export" do
before(:each) do
@@ -30,8 +26,8 @@ class TestClass
@test_object.export
end
- it "generates a hash of its class name and id" do
- @test_object.export.should == {'_class_name' => 'TestClass', '_id' => @id}
+ it "generates a hash of its class name, id, and embed status" do
+ @test_object.export.should == {'_class_name' => 'TestClass', '_id' => @id, '_embed' => true}
end
end
@@ -67,6 +63,10 @@ class NoPersistence
end
describe "#from_hash(hash)" do
+ before(:each) do
+ @test_object = TestClass.new
+ end
+
it "parses a hash into instance attributes" do
@test_object.from_hash(:test_attribute => 'Test value')
@test_object.test_attribute.should == 'Test value'

0 comments on commit 42baf8b

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