Sha256: 6dca1085adca4a3f4c65ff1cb3183f817af05eb97871f11d0aacfc953b8b269d

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 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

23 entries across 23 versions & 1 rubygems

Version Path
msgr-0.15.2.1.b157 spec/msgr/msgr/route_spec.rb
msgr-0.15.2.1.b156 spec/msgr/msgr/route_spec.rb
msgr-0.15.2.1.b155 spec/msgr/msgr/route_spec.rb
msgr-0.15.2.1.b154 spec/msgr/msgr/route_spec.rb
msgr-0.15.2.1.b152 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b151 spec/msgr/msgr/route_spec.rb
msgr-0.15.2 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b150 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b146 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b145 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b144 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b143 spec/msgr/msgr/route_spec.rb
msgr-0.15.1.1.b141 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b140 spec/msgr/msgr/route_spec.rb
msgr-0.15.1 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b139 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b136 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b135 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b134 spec/msgr/msgr/route_spec.rb
msgr-0.15.0.1.b131 spec/msgr/msgr/route_spec.rb