collector 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/collector/repository.rb +1 -1
- data/lib/collector/version.rb +1 -1
- data/test/collector/repository_spec.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f528e577d42419e81eaf07fc74f5b6883f505a12
|
4
|
+
data.tar.gz: f5c1caf252cbf1bac5a82067d71e17f25737d51d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f461a77fb15f478eead83a5f82ec1e401ebeb9597d716839314afdd587e024043c1e6cf41e296b85fa5358ecde8c084735284aef511e6146392ed5ce10aa79a2
|
7
|
+
data.tar.gz: 6890cd548912d835d085d863a0be8cc82582589ac7344833eabcd407d93c020cdab0e12d7dd62adbef6e2ba1440585be177a10f1893c9724c19af8e1389b2b17
|
data/lib/collector/repository.rb
CHANGED
@@ -41,7 +41,7 @@ module Collector
|
|
41
41
|
|
42
42
|
def serialize!(model)
|
43
43
|
attributes = serialize(model)
|
44
|
-
attributes["_id"] =
|
44
|
+
attributes["_id"] = normalize_id(attributes.delete("id")) if attributes["id"]
|
45
45
|
attributes.reject! { |key, val| val.nil? }
|
46
46
|
attributes
|
47
47
|
end
|
data/lib/collector/version.rb
CHANGED
@@ -78,11 +78,16 @@ describe Collector::Repository do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
describe "serialize!" do
|
81
|
-
it "normalize id to _id and
|
81
|
+
it "normalize id to _id and normalize to an ObjectId" do
|
82
82
|
model = mock(attributes: { id: "50c58f4ab392d4381a000001", foo: "bar" })
|
83
83
|
TestModelRepository.serialize!(model).must_equal({ "_id" => BSON::ObjectId("50c58f4ab392d4381a000001"), "foo" => "bar" })
|
84
84
|
end
|
85
85
|
|
86
|
+
it "normalize id to _id and leave it as a string if it is not an ObjectId" do
|
87
|
+
model = mock(attributes: { id: "some-string", foo: "bar" })
|
88
|
+
TestModelRepository.serialize!(model).must_equal({ "_id" => "some-string", "foo" => "bar" })
|
89
|
+
end
|
90
|
+
|
86
91
|
it "returns a model's attributes without nil values" do
|
87
92
|
model = mock(attributes: { foo: "bar", nothing: nil })
|
88
93
|
TestModelRepository.serialize!(model).must_equal({ "foo" => "bar" })
|