Sha256: e800feb02616c5aebe44171d517e9b321465fd1c2759dfc0ffe07f3c86b9e60b

Contents?: true

Size: 1.97 KB

Versions: 45

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'
require 'shared/protocol_msgbus_behaviour'

describe Ably::Auth do
  let(:client)        { double('client').as_null_object }
  let(:client_id)     { nil }
  let(:auth_options)  { { key: 'appid.keyuid:keysecret', client_id: client_id } }
  let(:token_params)  { { } }

  subject do
    Ably::Auth.new(client, token_params, auth_options)
  end

  describe 'client_id option' do
    let(:client_id) { random_str.encode(encoding) }

    context 'with nil value' do
      let(:client_id) { nil }

      it 'is permitted' do
        expect(subject.client_id).to be_nil
      end
    end

    context 'as UTF_8 string' do
      let(:encoding) { Encoding::UTF_8 }

      it 'is permitted' do
        expect(subject.client_id).to eql(client_id)
      end

      it 'remains as UTF-8' do
        expect(subject.client_id.encoding).to eql(encoding)
      end
    end

    context 'as SHIFT_JIS string' do
      let(:encoding) { Encoding::SHIFT_JIS }

      it 'gets converted to UTF-8' do
        expect(subject.client_id.encoding).to eql(Encoding::UTF_8)
      end

      it 'is compatible with original encoding' do
        expect(subject.client_id.encode(encoding)).to eql(client_id)
      end
    end

    context 'as ASCII_8BIT string' do
      let(:encoding) { Encoding::ASCII_8BIT }

      it 'gets converted to UTF-8' do
        expect(subject.client_id.encoding).to eql(Encoding::UTF_8)
      end

      it 'is compatible with original encoding' do
        expect(subject.client_id.encode(encoding)).to eql(client_id)
      end
    end

    context 'as Integer' do
      let(:client_id) { 1 }

      it 'raises an argument error' do
        expect { subject.client_id }.to raise_error ArgumentError, /must be a String/
      end
    end
  end

  context 'defaults' do
    it 'should have no default TTL' do
      expect(Ably::Auth::TOKEN_DEFAULTS[:ttl]).to be_nil
    end

    it 'should have no default capability' do
      expect(Ably::Auth::TOKEN_DEFAULTS[:capability]).to be_nil
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
ably-rest-1.2.7 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.7 spec/unit/auth_spec.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.6 spec/unit/auth_spec.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.4 spec/unit/auth_spec.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.3 spec/unit/auth_spec.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.2 spec/unit/auth_spec.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.1 spec/unit/auth_spec.rb
ably-rest-1.2.0 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.2.0 spec/unit/auth_spec.rb
ably-rest-1.1.8 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.1.8 spec/unit/auth_spec.rb
ably-rest-1.1.7 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.1.7 spec/unit/auth_spec.rb
ably-rest-1.1.6 lib/submodules/ably-ruby/spec/unit/auth_spec.rb
ably-1.1.6 spec/unit/auth_spec.rb