Permalink
Browse files

Add convenience method for the JS to override Pusher client configura…

…tion.
  • Loading branch information...
1 parent 35a29de commit 2dc24fa655b8f6e4ed986e9fa457620e4263bab8 @tristandunn committed Jan 23, 2013
Showing with 30 additions and 0 deletions.
  1. +1 −0 CHANGELOG.markdown
  2. +10 −0 lib/pusher-fake.rb
  3. +19 −0 spec/lib/pusher_fake_spec.rb
View
@@ -2,6 +2,7 @@
## Unreleased
+* Add convenience method for the JS to override Pusher client configuration. (Tristan Dunn)
* Update dependencies. (Tristan Dunn)
## 0.5.0 — January 21, 2013
View
@@ -34,4 +34,14 @@ def self.configure
def self.configuration
@configuration ||= Configuration.new
end
+
+ # Convenience method for the JS to override the Pusher client host and port.
+ #
+ # @return [String] JavaScript overriding the Pusher client host and port.
+ def self.javascript
+ <<-EOS
+ Pusher.host = #{configuration.socket_host.to_json};
+ Pusher.ws_port = #{configuration.socket_port.to_json};
+ EOS
+ end
end
@@ -43,3 +43,22 @@
subject.configuration.should == configuration
end
end
+
+describe PusherFake, ".javascript" do
+ let(:socket_host) { "127.0.0.1" }
+ let(:socket_port) { 1234 }
+ let(:configuration) { stub(socket_host: socket_host, socket_port: socket_port) }
+
+ subject { PusherFake }
+
+ before do
+ PusherFake.stubs(configuration: configuration)
+ end
+
+ it "returns JavaScript setting the host and port to the configured options" do
+ subject.javascript.should == <<-EOS
+ Pusher.host = #{socket_host.to_json};
+ Pusher.ws_port = #{socket_port.to_json};
+ EOS
+ end
+end

0 comments on commit 2dc24fa

Please sign in to comment.