lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb in ably-rest-0.8.3 vs lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb in ably-rest-0.8.5

- old
+ new

@@ -14,11 +14,11 @@ Base64.encode64(text).gsub("\n", '') end context '#initialize' do let(:client_id) { random_str } - let(:token_request) { client.auth.create_token_request(key_name: key_name, key_secret: key_secret, client_id: client_id) } + let(:token_request) { client.auth.create_token_request({}, key_name: key_name, key_secret: key_secret, client_id: client_id) } context 'with only an API key' do let(:client) { Ably::Rest::Client.new(client_options.merge(key: api_key)) } it 'uses basic authentication' do @@ -61,10 +61,20 @@ it 'uses token authentication' do expect(client.auth).to be_using_token_auth end end + context 'with an :auth_callback Proc (clientId provided in library options instead of as a token_request param)' do + let(:client) { Ably::Rest::Client.new(client_options.merge(client_id: client_id, auth_callback: Proc.new { token_request })) } + let(:token_request) { client.auth.create_token_request({}, key_name: key_name, key_secret: key_secret) } + + it 'correctly sets the clientId on the token' do + expect { client.channel('channel_name').publish('event', 'message') }.to change { client.auth.current_token_details } + expect(client.auth.current_token_details.client_id).to eql(client_id) + end + end + context 'with an auth URL' do let(:client_options) { default_options.merge(key: api_key, auth_url: token_request_url, auth_method: :get) } let(:token_request_url) { 'http://get.token.request.com/' } it 'uses token authentication' do @@ -72,11 +82,11 @@ end context 'before any REST request' do before do expect(client.auth).to receive(:token_request_from_auth_url).with(token_request_url, hash_including(:auth_method => :get)).once do - client.auth.create_token_request(token_params: { client_id: client_id }) + client.auth.create_token_request(client_id: client_id) end end it 'sends an HTTP request to the provided auth URL to get a new token' do expect { client.channel('channel_name').publish('event', 'message') }.to change { client.auth.current_token_details } @@ -142,14 +152,14 @@ @request_index ||= 0 @request_index += 1 send("token_request_#{@request_index > 2 ? 'next' : @request_index}") end)) end - let(:token_request_1) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) } - let(:token_request_2) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) } + let(:token_request_1) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) } + let(:token_request_2) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) } # If token expires against whilst runnig tests in a slower CI environment then use this token - let(:token_request_next) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) } + let(:token_request_next) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) } context 'when expired' do before do # Ensure tokens issued expire immediately after issue stub_const 'Ably::Auth::TOKEN_DEFAULTS', Ably::Auth::TOKEN_DEFAULTS.merge(renew_token_buffer: 0)