Sha256: 3867bca592e50d11224a9b0b70ff32905914a33d707e43b868c6a58736cc31f6

Contents?: true

Size: 1.4 KB

Versions: 86

Compression:

Stored size: 1.4 KB

Contents

class TwitterSubscriber < ActionSubscriber::Base
  def tweet
    $messages << {
      :decoded => payload,
      :raw => raw_payload,
    }
  end
end


describe "Payload Decoding", :integration => true do
  let(:connection) { subscriber.connection }
  let(:draw_routes) do
    ::ActionSubscriber.draw_routes do
      default_routes_for TwitterSubscriber
    end
  end
  let(:subscriber) { TwitterSubscriber }
  let(:json_string) { '{"foo": "bar"}' }

  it "decodes json by default" do
    ::ActionSubscriber.start_subscribers!
    ::ActivePublisher.publish("twitter.tweet", json_string, "events", :content_type => "application/json")

    verify_expectation_within(2.0) do
      expect($messages).to eq Set.new([{
        :decoded => JSON.parse(json_string),
        :raw => json_string,
      }])
    end
  end

  context "Custom Decoder" do
    let(:content_type) { "foo/type" }

    before { ::ActionSubscriber.config.add_decoder(content_type => lambda{ |payload| :foo }) }
    after { ::ActionSubscriber.config.decoder.delete(content_type) }

    it "it decodes the payload using the custom decoder" do
      ::ActionSubscriber.start_subscribers!
      ::ActivePublisher.publish("twitter.tweet", json_string, "events", :content_type => content_type)

      verify_expectation_within(2.0) do
        expect($messages).to eq Set.new([{
          :decoded => :foo,
          :raw => json_string,
        }])
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
action_subscriber-5.3.3-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.3 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.2-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.2 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.1-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.1 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.1.pre-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.1.pre spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.0-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.3.0 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.4-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.4 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.3-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.3 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.2-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.2 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.1-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.1 spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.0-java spec/integration/decoding_payloads_spec.rb
action_subscriber-5.2.0 spec/integration/decoding_payloads_spec.rb