Sha256: 8fe61ae0eb8dd78608c00ad3fddb47a4569d5f92ec0a45c1d72e149e6ed6e4d0

Contents?: true

Size: 1.92 KB

Versions: 94

Compression:

Stored size: 1.92 KB

Contents

describe ActionSubscriber::Middleware::Env do
  let(:channel) { double("channel") }
  let(:encoded_payload) { 'encoded_payload' }
  let(:properties){ {
    :action => :created,
    :channel => channel,
    :content_type => "application/json",
    :delivery_tag => "XYZ",
    :encoded_payload => encoded_payload,
    :exchange => "events",
    :headers => {},
    :message_id => "MSG-1234",
    :routing_key => "amigo.user.created",
    :queue => "test.amigo.user.created",
  } }
  let(:subscriber) { UserSubscriber }

  subject { described_class.new(subscriber, encoded_payload, properties) }

  specify { expect(subject.action).to eq(:created) }
  specify { expect(subject.content_type).to eq(properties[:content_type]) }
  specify { expect(subject.exchange).to eq(properties[:exchange]) }
  specify { expect(subject.headers).to eq(properties[:headers]) }
  specify { expect(subject.message_id).to eq(properties[:message_id]) }
  specify { expect(subject.routing_key).to eq(properties[:routing_key]) }
  specify { expect(subject.queue).to eq(properties[:queue]) }

  describe "#acknowledge" do
    it "sends an acknowledgement to rabbitmq" do
      expect(channel).to receive(:ack).with(properties[:delivery_tag], false)
      subject.acknowledge
    end
  end

  describe "#reject" do
    it "sends an rejection to rabbitmq" do
      expect(channel).to receive(:reject).with(properties[:delivery_tag], true)
      subject.reject
    end
  end

  describe "#to_hash" do
    it "includes the action" do
      expect(subject.to_hash).to have_key(:action)
    end

    it "includes the content_type" do
      expect(subject.to_hash).to have_key(:content_type)
    end

    it "includes the exchange" do
      expect(subject.to_hash).to have_key(:exchange)
    end

    it "includes the routing_key" do
      expect(subject.to_hash).to have_key(:routing_key)
    end

    it "includes the payload" do
      expect(subject.to_hash).to have_key(:payload)
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
action_subscriber-5.1.3 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.3-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.3.pre2 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.3.pre2-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.3.pre1 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.3.pre1-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.2-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.2 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.1-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.1 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.1.pre0 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.1.pre0-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.0-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.0 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.0.pre-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.1.0.pre spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.0.3-java spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.0.3 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.0.3.pre1 spec/lib/action_subscriber/middleware/env_spec.rb
action_subscriber-5.0.3.pre1-java spec/lib/action_subscriber/middleware/env_spec.rb