Skip to content

Commit

Permalink
moving subscription server config into PrivatePub module
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jan 15, 2012
1 parent 3ab4c57 commit 335f6e6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/private_pub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def load_config(filename, environment)
end

def subscription(options = {})
sub = {:timestamp => (Time.now.to_f * 1000).round}.merge(options)
sub = {:server => config[:server], :timestamp => (Time.now.to_f * 1000).round}.merge(options)
sub[:signature] = Digest::SHA1.hexdigest([config[:secret_token], sub[:channel], sub[:timestamp]].join)
sub
end
Expand Down
1 change: 0 additions & 1 deletion lib/private_pub/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def publish_to(channel, data = nil, &block)

def subscribe_to(channel)
subscription = PrivatePub.subscription(:channel => channel)
subscription[:server] = PrivatePub.config[:server]
content_tag "script", :type => "text/javascript" do
raw("PrivatePub.sign(#{subscription.to_json});")
end
Expand Down
4 changes: 3 additions & 1 deletion spec/private_pub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
}.should raise_error ArgumentError
end

it "includes channel and custom time in subscription" do
it "includes channel, server, and custom time in subscription" do
PrivatePub.config[:server] = "server"
subscription = PrivatePub.subscription(:timestamp => 123, :channel => "hello")
subscription[:timestamp].should == 123
subscription[:channel].should == "hello"
subscription[:server].should == "server"
end

it "does a sha1 digest of channel, timestamp, and secret token" do
Expand Down

0 comments on commit 335f6e6

Please sign in to comment.