Permalink
Browse files

Update Channel#trigger method to allow options and fix Channel spec.

  • Loading branch information...
1 parent a79c1ab commit b0d538e93ad09a94a198765e31666db1bab9a6fd @DanKnox DanKnox committed Jul 19, 2012
Showing with 15 additions and 7 deletions.
  1. +12 −4 lib/websocket_rails/channel.rb
  2. +3 −3 spec/unit/channel_spec.rb
View
16 lib/websocket_rails/channel.rb
@@ -13,10 +13,18 @@ def subscribe(connection)
@subscribers << connection
end
- def trigger(event_name,data={})
- event_data = {:data => data, :channel => name}
- channel_event = Event.new event_name, event_data
- send_data channel_event
+ def trigger(event_name,data={},options={})
+ options.merge! :channel => name
+
+ event_data =
+ case data
+ when Hash then options.merge!( data )
+ else
+ options[:data] = data
+ end
+ event = Event.new event_name, options
+
+ send_data event
end
def trigger_event(event)
View
6 spec/unit/channel_spec.rb
@@ -24,14 +24,14 @@ module WebsocketRails
describe "#trigger" do
it "should create a new event and trigger it on all subscribers" do
event = double('event').as_null_object
- Event.should_receive(:new) do |name,data|
+ Event.should_receive(:new) do |name,options|
name.should == 'event'
- data[:data].should == 'data'
+ options[:data].should == 'data'
event
end
connection.should_receive(:trigger).with(event)
subject.subscribe connection
- subject.trigger 'event', :data => 'data'
+ subject.trigger 'event', 'data'
end
end

0 comments on commit b0d538e

Please sign in to comment.