mongoid-publishable 0.0.2 → 0.0.3

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.
@@ -25,8 +25,11 @@ module Mongoid
25
25
  @after_publish_callbacks ||= CallbackCollection.new
26
26
  end
27
27
 
28
+ # add the callback to the collection
28
29
  def add_after_publish_callback(callback)
30
+ # add it to this object's collection
29
31
  after_publish_callbacks << callback
32
+ # add it to the subclasses collections too
30
33
  subclasses.each do |subclass|
31
34
  subclass.add_after_publish_callback(callback)
32
35
  end
@@ -25,8 +25,8 @@ module Mongoid
25
25
  MultiJson.load(@serialized_data)
26
26
  end
27
27
 
28
- def respond_to_missing?(method)
29
- source_object.respond_to?(method)
28
+ def respond_to_missing?(method, include_private = false)
29
+ source_object.respond_to?(method) || super
30
30
  end
31
31
 
32
32
  def method_missing(method, *args, &block)
@@ -71,7 +71,7 @@ module Mongoid
71
71
  result = {
72
72
  embedded: {
73
73
  association: parent_relation.inverse_of,
74
- embedded: result,
74
+ embedded: result && result[:embedded],
75
75
  id: object.id
76
76
  }
77
77
  }
@@ -79,7 +79,7 @@ module Mongoid
79
79
  object = object._parent
80
80
  end
81
81
  # when at the top level, store the class/id/result
82
- result = { class_name: object.class.name, id: object.id, embedded: result }
82
+ result = { class_name: object.class.name, id: object.id, embedded: result && result[:embedded] }
83
83
  # convert the result to JSON
84
84
  MultiJson.dump(result)
85
85
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Publishable
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -4,6 +4,12 @@ require "mongoid/publishable/unpublished_object"
4
4
 
5
5
  describe Mongoid::Publishable::UnpublishedObject do
6
6
  let(:model) { PublishableObject.new }
7
+ let(:parent_model) do
8
+ ParentPublishableObject.create
9
+ end
10
+ let(:nested_model) do
11
+ parent_model.nested_objects.build
12
+ end
7
13
 
8
14
  describe "::deserialize_from_session" do
9
15
  it "should initialize with data" do
@@ -56,6 +62,35 @@ describe Mongoid::Publishable::UnpublishedObject do
56
62
  expect(json["class_name"]).to eq model.class.name
57
63
  expect(json["id"].to_s).to eq model.id.to_s
58
64
  end
65
+
66
+ it "should deserialise back into the object" do
67
+ model.save
68
+ data = subject.serialize_for_session
69
+ reloaded_subject = subject.class.deserialize_from_session(data)
70
+ expect(reloaded_subject.source_object).to eq subject.source_object
71
+ end
72
+ end
73
+
74
+ context "with a nested model" do
75
+ subject do
76
+ Mongoid::Publishable::UnpublishedObject.new(model: nested_model)
77
+ end
78
+
79
+ it "should return a string of JSON" do
80
+ json = MultiJson.load(subject.serialize_for_session)
81
+ expect(json["class_name"]).to eq nested_model._parent.class.name
82
+ expect(json["id"].to_s).to eq nested_model._parent.id.to_s
83
+ expect(json["embedded"]["id"]).to eq nested_model.id.to_s
84
+ expect(json["embedded"]["association"]).to eq "nested_objects"
85
+ expect(json["embedded"]["embedded"]).to be_nil
86
+ end
87
+
88
+ it "should deserialise back into the object" do
89
+ nested_model.save
90
+ data = subject.serialize_for_session
91
+ reloaded_subject = subject.class.deserialize_from_session(data)
92
+ expect(reloaded_subject.source_object).to eq subject.source_object
93
+ end
59
94
  end
60
95
 
61
96
  context "with data" do
@@ -1,2 +1,4 @@
1
+ require_relative "callbackable_object"
2
+
1
3
  class CallbackableSubobject < CallbackableObject
2
4
  end
@@ -0,0 +1,9 @@
1
+ require_relative "publishable_object"
2
+
3
+ class ParentPublishableObject < PublishableObject
4
+ embeds_many :nested_objects, class_name: "NestedPublishableObject"
5
+ end
6
+
7
+ class NestedPublishableObject < PublishableObject
8
+ embedded_in :parent_publishable, class_name: "ParentPublishableObject", inverse_of: :nested_objects
9
+ end
@@ -0,0 +1,3 @@
1
+ require "mongoid"
2
+
3
+ Mongoid.load!(File.join(File.dirname(__FILE__), "mongoid.yml"), :test)
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ hosts:
5
+ - localhost:27017
6
+ database: ryantownsend_mongoid_publishable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-publishable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -130,9 +130,12 @@ files:
130
130
  - spec/support/env.rb
131
131
  - spec/support/models/callbackable_object.rb
132
132
  - spec/support/models/callbackable_subobject.rb
133
+ - spec/support/models/nested_publishable_object.rb
133
134
  - spec/support/models/publishable_object.rb
134
135
  - spec/support/models/publisher.rb
135
136
  - spec/support/models/queuing_controller.rb
137
+ - spec/support/mongoid.rb
138
+ - spec/support/mongoid.yml
136
139
  homepage: https://github.com/ryantownsend/mongoid-publishable
137
140
  licenses: []
138
141
  post_install_message:
@@ -170,6 +173,9 @@ test_files:
170
173
  - spec/support/env.rb
171
174
  - spec/support/models/callbackable_object.rb
172
175
  - spec/support/models/callbackable_subobject.rb
176
+ - spec/support/models/nested_publishable_object.rb
173
177
  - spec/support/models/publishable_object.rb
174
178
  - spec/support/models/publisher.rb
175
179
  - spec/support/models/queuing_controller.rb
180
+ - spec/support/mongoid.rb
181
+ - spec/support/mongoid.yml