Skip to content

Commit

Permalink
Improve delgation from class to default client. Drop support of Ruby …
Browse files Browse the repository at this point in the history
…1.9 (#10)

* Improve delgation from class to default client
* Requiring secure random explicitly
* Removed 1.9.3 from travis
  • Loading branch information
tuned-up authored and arrowcircle committed Apr 11, 2017
1 parent 2c00cb4 commit eeb9901
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: ruby
notifications:
email: false
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
Expand Down
11 changes: 3 additions & 8 deletions lib/centrifuge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ class << self

def_delegators :default_client, :scheme, :host, :port, :secret
def_delegators :default_client, :scheme=, :host=, :port=, :secret=

# def_delegators :default_client, :authentication_token, :url
# def_delegators :default_client, :encrypted=, :url=
def_delegators :default_client, :timeout=, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=

# def_delegators :default_client, :get, :get_async, :post, :post_async
def_delegators :default_client, :publish
# def_delegators :default_client, :webhook, :channel, :[]
def_delegators :default_client, :connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=
def_delegators :default_client, :broadcast, :publish, :unsubscribe, :disconnect, :presence, :history, :channels, :stats
def_delegators :default_client, :token_for, :generate_channel_sign

attr_writer :logger

Expand Down
24 changes: 24 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'securerandom'

describe Centrifuge::Client do
let(:options) { { scheme: :https, host: 'centrifugo.herokuapp.com', port: 443, secret: 'secret' } }
Expand Down Expand Up @@ -50,3 +51,26 @@
it { expect(result).to eq 'be26ac57ef264c23662ba373e4b68670c1a006431c763af6d33ad10ab6aa97d9' }
end
end

describe Centrifuge do
context 'delegation' do
it 'class should delegate methods to default client' do
client_double = double('default_client')
methods_to_delegate = [:scheme, :host, :port, :secret,
:scheme=, :host=, :port=, :secret=,
:connect_timeout=, :send_timeout=, :receive_timeout=, :keep_alive_timeout=,
:broadcast, :publish, :unsubscribe, :disconnect, :presence, :history,
:channels, :stats, :token_for, :generate_channel_sign]

methods_to_delegate.each do |method|
expect(client_double).to receive(method)
end

Centrifuge.stub(:default_client).and_return(client_double)

methods_to_delegate.each do |method|
Centrifuge.send(method)
end
end
end
end

0 comments on commit eeb9901

Please sign in to comment.