Sha256: c76f1e3cdea622594231a3421bcc2241cdbc6614b64f5f80b3586453179f3399

Contents?: true

Size: 1.73 KB

Versions: 14

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ably::Models::ChannelOptions do
  let(:modes) { nil }
  let(:params) { {} }
  let(:options) { described_class.new(modes: modes, params: params) }

  describe '#modes_to_flags' do
    let(:modes) { %w[publish subscribe presence_subscribe] }

    subject(:protocol_message) do
      Ably::Models::ProtocolMessage.new(action: Ably::Models::ProtocolMessage::ACTION.Attach, flags: options.modes_to_flags)
    end

    it 'converts modes to ProtocolMessage#flags correctly' do
      expect(protocol_message.has_attach_publish_flag?).to eq(true)
      expect(protocol_message.has_attach_subscribe_flag?).to eq(true)
      expect(protocol_message.has_attach_presence_subscribe_flag?).to eq(true)

      expect(protocol_message.has_attach_resume_flag?).to eq(false)
      expect(protocol_message.has_attach_presence_flag?).to eq(false)
    end
  end

  describe '#set_modes_from_flags' do
    let(:subscribe_flag) { 262144 }

    it 'converts flags to ChannelOptions#modes correctly' do
      result = options.set_modes_from_flags(subscribe_flag)

      expect(result).to eq(options.modes)
      expect(options.modes.map(&:to_sym)).to eq(%i[subscribe])
    end
  end

    describe '#set_params' do
      let(:previous_params) { { example_attribute: 1 } }
      let(:new_params) { { new_attribute: 1 } }
      let(:params) { previous_params }

      it 'should be able to overwrite attributes' do
        expect { options.set_params(new_params) }.to \
          change { options.params }.from(previous_params).to(new_params)
      end

      it 'should be able to make params empty' do # (1)
        expect { options.set_params({}) }.to change { options.params }.from(previous_params).to({})
      end
    end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
ably-rest-1.2.7 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.7 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.6 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.6 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.4 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.4 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.3 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.3 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.2 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.2 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.1 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.1 spec/lib/unit/models/channel_options_spec.rb
ably-rest-1.2.0 lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb
ably-1.2.0 spec/lib/unit/models/channel_options_spec.rb