Sha256: 9168bf32aa15277ffa465731ad15ac4f94e95c52a400db9b73ff86a6180f5ab6

Contents?: true

Size: 1.66 KB

Versions: 91

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Msgr::Route do
  let(:routing_key) { 'routing.key.#' }
  let(:options) { {to: 'test#index'} }
  let(:args) { [routing_key, options] }
  let(:route) { Msgr::Route.new(*args) }
  subject { route }

  describe '#initialize' do
    it 'should require `to` option' do
      expect do
        Msgr::Route.new(routing_key, {})
      end.to raise_error(ArgumentError)
    end

    it 'should require routing_key' do
      expect do
        Msgr::Route.new nil, options
      end.to raise_error(ArgumentError)
    end

    it 'should require not empty routing_key' do
      expect do
        Msgr::Route.new '', options
      end.to raise_error ArgumentError, /routing key required/i
    end

    it 'should require `to: "consumer#action` format' do
      expect do
        Msgr::Route.new routing_key, to: 'abc'
      end.to raise_error ArgumentError, /invalid consumer format/i
    end
  end

  describe '#consumer' do
    it 'should return consumer class name' do
      expect(route.consumer).to eq 'TestConsumer'
    end

    context 'with underscore consumer name' do
      let(:options) { super().merge to: 'test_resource_foo#index' }

      it 'should return camelized method name' do
        expect(route.consumer).to eq 'TestResourceFooConsumer'
      end
    end
  end

  describe '#action' do
    it 'should return action method name' do
      expect(route.action).to eq 'index'
    end

    context 'with camelCase action name' do
      let(:options) { super().merge to: 'test#myActionMethod' }

      it 'should return underscore method name' do
        expect(route.action).to eq 'my_action_method'
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
msgr-1.2.0 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b306 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b305 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b302 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b301 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b300 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b297 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b296 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b295 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b292 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b291 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b288 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b285 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b263 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b249 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b248 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b244 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b241 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b240 spec/msgr/msgr/route_spec.rb
msgr-1.1.0.1.b239 spec/msgr/msgr/route_spec.rb