collector 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Collector
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
@@ -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: 123, foo: "bar" })
55
- TestRepository.serialize!(model).must_equal({ "_id" => 123, "foo" => "bar" })
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" => 123, "name" => "Brandon")
74
- TestRepository.deserialize!(_id: 123, name: "Brandon")
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: