Browse files

Added tests for Client#trigger_async

  • Loading branch information...
1 parent 6b1524f commit b5edfdfbb17a854f5b64815f4c553143cc8c9ec0 @mloughran mloughran committed Nov 12, 2012
Showing with 43 additions and 0 deletions.
  1. +43 −0 spec/client_spec.rb
View
43 spec/client_spec.rb
@@ -230,6 +230,49 @@
end
end
+ describe '#trigger_async' do
+ before :each do
+ @api_path = %r{/apps/20/events}
+ stub_request(:post, @api_path).to_return({
+ :status => 200,
+ :body => MultiJson.encode({})
+ })
+ end
+
+ it "should call correct URL" do
+ EM.run {
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}).callback { |r|
+ r.should == {}
+ EM.stop
+ }
+ }
+ end
+
+ it "should pass any parameters in the body of the request" do
+ EM.run {
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}, {
+ :socket_id => "1234"
+ }).callback {
+ WebMock.should have_requested(:post, @api_path).with { |req|
+ MultiJson.decode(req.body)["socket_id"].should == '1234'
+ }
+ EM.stop
+ }
+ }
+ end
+
+ it "should convert non string data to JSON before posting" do
+ EM.run {
+ @client.trigger_async('mychannel', 'event', {'some' => 'data'}).callback {
+ WebMock.should have_requested(:post, @api_path).with { |req|
+ MultiJson.decode(req.body)["data"].should == '{"some":"data"}'
+ }
+ EM.stop
+ }
+ }
+ end
+ end
+
[:get, :post].each do |verb|
describe "##{verb}" do
before :each do

0 comments on commit b5edfdf

Please sign in to comment.