diff --git a/lib/browser/postal.diagnostics.min.gz.js b/lib/browser/postal.diagnostics.min.gz.js index 86741d5..12c0992 100644 Binary files a/lib/browser/postal.diagnostics.min.gz.js and b/lib/browser/postal.diagnostics.min.gz.js differ diff --git a/lib/browser/postal.min.gz.js b/lib/browser/postal.min.gz.js index 965ec1b..bf99623 100644 Binary files a/lib/browser/postal.min.gz.js and b/lib/browser/postal.min.gz.js differ diff --git a/pavlov b/pavlov new file mode 120000 index 0000000..884259e --- /dev/null +++ b/pavlov @@ -0,0 +1 @@ +/home/jcowart/.nvm/v0.4.10/lib/node_modules/anvil.js/ext \ No newline at end of file diff --git a/spec/Postal.spec.js b/spec/Postal.spec.js index db6fe88..cf16168 100644 --- a/spec/Postal.spec.js +++ b/spec/Postal.spec.js @@ -323,6 +323,59 @@ QUnit.specify("postal.js", function(){ assert(count).equals(2); }); }); + describe("When using shortcut publish api", function(){ + var msgReceivedCnt = 0, + msgData; + before(function(){ + channel = postal.channel("MyExchange","MyTopic") + subscription = channel.subscribe(function(data) { msgReceivedCnt++; msgData = data;}); + postal.publish("MyExchange", "MyTopic", "Testing123"); + subscription.unsubscribe(); + postal.publish("MyExchange", "MyTopic", "Testing123"); + }); + after(function(){ + postal.configuration.bus.subscriptions = {}; + }); + it("subscription callback should be invoked once", function(){ + assert(msgReceivedCnt).equals(1); + }); + it("subscription callback should receive published data", function(){ + assert(msgData).equals("Testing123"); + }); + }); + describe("When using shortcut subscribe api", function(){ + before(function(){ + subscription = postal.subscribe("MyExchange", "MyTopic", function() { }); + sub = postal.configuration.bus.subscriptions.MyExchange.MyTopic[0]; + }); + after(function(){ + postal.configuration.bus.subscriptions = {}; + }); + it("should create an exchange called MyExchange", function(){ + assert(postal.configuration.bus.subscriptions["MyExchange"] !== undefined).isTrue(); + }); + it("should create a topic under MyExchange called MyTopic", function(){ + assert(postal.configuration.bus.subscriptions["MyExchange"]["MyTopic"] !== undefined).isTrue(); + }); + it("should have set subscription exchange value", function() { + assert(sub.exchange).equals("MyExchange"); + }); + it("should have set subscription topic value", function() { + assert(sub.topic).equals("MyTopic"); + }); + it("should have set subscription priority value", function() { + assert(sub.priority).equals(50); + }); + it("should have defaulted the subscription constraints array", function() { + assert(sub.constraints.length).equals(0); + }); + it("should have defaulted the subscription disposeAfter value", function() { + assert(sub.maxCalls).equals(0); + }); + it("should have defaulted the subscription context value", function() { + assert(sub.context).isNull(); + }); + }); // TODO: Add test coverage for direct unsubscribe and wire taps }); }); \ No newline at end of file diff --git a/src/main/Api.js b/src/main/Api.js index 0b38c7e..f965c9b 100644 --- a/src/main/Api.js +++ b/src/main/Api.js @@ -10,6 +10,20 @@ var postal = { return new ChannelDefinition(exch, tpc); }, + subscribe: function(exchange, topic, callback) { + var exch = arguments.length === 3 ? exchange : DEFAULT_EXCHANGE, + tpc = arguments.length === 3 ? topic : exchange; + var channel = this.channel(exch, tpc); + return channel.subscribe(callback); + }, + + publish: function(exchange, topic, payload) { + var exch = arguments.length === 3 ? exchange : DEFAULT_EXCHANGE, + tpc = arguments.length === 3 ? topic : exchange; + var channel = this.channel(exch, tpc); + channel.publish(payload); + }, + addWireTap: function(callback) { this.configuration.bus.addWireTap(callback); }