Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a remote subscriber API

  • Loading branch information...
commit 09c6f08bcd9144ead5049412562c3ca675d03920 1 parent 34f7c47
tomhuda authored
Showing with 43 additions and 0 deletions.
  1. +9 −0 lib/remote_notifications.rb
  2. +34 −0 spec/remote_subscriber_spec.rb
View
9 lib/remote_notifications.rb
@@ -42,3 +42,12 @@ def finish(name, id, payload)
dispatch "after", serialized
end
end
+
+class RemoteSubscriber
+ def process(blob)
+ sequence, name, id, payload = deserialize(blob)
+ notifier = ActiveSupport::Notifications.notifier
+
+ notifier.send(sequence, name, id, payload)
+ end
+end
View
34 spec/remote_subscriber_spec.rb
@@ -0,0 +1,34 @@
+require "date"
+
+class JSONSubscriber < RemoteSubscriber
+ def deserialize(blob)
+ payload = ActiveSupport::JSON.decode(blob)
+ return payload["sequence"], payload["name"], payload["id"], payload["payload"]
+ end
+end
+
+describe "the remote subscriber" do
+ before do
+ @test_subscriber = JSONSubscriber.new
+ @notifier = ActiveSupport::Notifications::Fanout.new
+ @events = []
+
+ ActiveSupport::Notifications.notifier = @notifier
+ ActiveSupport::Notifications.subscribe do |*args|
+ @events << ActiveSupport::Notifications::Event.new(*args)
+ end
+ end
+
+ it "deserializes a remote notification" do
+ @test_subscriber.process ActiveSupport::JSON.encode(:sequence => :start, :name => "ohai", :id => "abc123def", :payload => { :ohai => true })
+ @test_subscriber.process ActiveSupport::JSON.encode(:sequence => :finish, :name => "ohai", :id => "abc123def", :payload => { :ohai => true })
+
+ @events.size.should == 1
+
+ event = @events[0]
+
+ event.name.should == "ohai"
+ event.transaction_id.should == "abc123def"
+ event.payload.should == { "ohai" => true }
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.