collector 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/collector/repository.rb +2 -2
- data/lib/collector/version.rb +1 -1
- data/test/collector/repository_spec.rb +6 -6
- metadata +1 -1
data/lib/collector/repository.rb
CHANGED
@@ -35,7 +35,7 @@ module Collector
|
|
35
35
|
|
36
36
|
def serialize!(model)
|
37
37
|
attributes = serialize(model)
|
38
|
-
attributes["_id"] = attributes.delete("id")
|
38
|
+
attributes["_id"] = BSON::ObjectId.from_string(attributes.delete("id")) if attributes["id"]
|
39
39
|
attributes.reject! { |key, val| val.nil? }
|
40
40
|
attributes
|
41
41
|
end
|
@@ -46,7 +46,7 @@ module Collector
|
|
46
46
|
|
47
47
|
def deserialize!(attributes)
|
48
48
|
attributes = attributes.with_indifferent_access
|
49
|
-
attributes["id"] = attributes.delete("_id")
|
49
|
+
attributes["id"] = attributes.delete("_id").to_s
|
50
50
|
deserialize(attributes)
|
51
51
|
end
|
52
52
|
|
data/lib/collector/version.rb
CHANGED
@@ -50,9 +50,9 @@ describe Collector::Repository do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "serialize!" do
|
53
|
-
it "normalize id to _id" do
|
54
|
-
model = mock(attributes: { id:
|
55
|
-
TestRepository.serialize!(model).must_equal({ "_id" =>
|
53
|
+
it "normalize id to _id and converts to a BSON::ObjectId" do
|
54
|
+
model = mock(attributes: { id: "50c58f4ab392d4381a000001", foo: "bar" })
|
55
|
+
TestRepository.serialize!(model).must_equal({ "_id" => BSON::ObjectId("50c58f4ab392d4381a000001"), "foo" => "bar" })
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns a model's attributes without nil values" do
|
@@ -69,9 +69,9 @@ describe Collector::Repository do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "deserialize!" do
|
72
|
-
it "normalizes _id to id" do
|
73
|
-
TestRepository.expects(:deserialize).with("id" =>
|
74
|
-
TestRepository.deserialize!(_id:
|
72
|
+
it "normalizes _id to id and converts to a string id" do
|
73
|
+
TestRepository.expects(:deserialize).with("id" => "50c58f4ab392d4381a000001", "name" => "Brandon")
|
74
|
+
TestRepository.deserialize!(_id: BSON::ObjectId("50c58f4ab392d4381a000001"), name: "Brandon")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|