spec/unit/configuration_spec.rb in pwwka-0.16.1 vs spec/unit/configuration_spec.rb in pwwka-0.17.0

- old
+ new

@@ -18,9 +18,31 @@ describe "#topic_exchange_name" do it "is based on the Pwwka.environment" do expect(configuration.topic_exchange_name).to eq("pwwka.topics.production") end end + + describe "#payload_parser" do + it "parses JSON by default" do + payload = { foo: { bar: 42 } } + expect(described_class.new.payload_parser.(payload.to_json)).to eq({ "foo" => { "bar" => 42 } }) + end + + it "setting receive_raw_payload to true pases through the raw payload" do + configuration.receive_raw_payload = true + payload = "<h1>This is some <blink>XML</blink></h1>" + expect(configuration.payload_parser.(payload)).to eq(payload) + end + + it "setting receive_raw_payload to true then false restores the JSON-parsing" do + configuration.receive_raw_payload = true + payload = { foo: { bar: 42 } } + expect(configuration.payload_parser.(payload.to_json)).to eq(payload.to_json) + configuration.receive_raw_payload = false + expect(configuration.payload_parser.(payload.to_json)).to eq({ "foo" => { "bar" => 42 } }) + end + end + describe "#delayed_exchange_name" do it "is based on the Pwwka.environment" do expect(configuration.delayed_exchange_name).to eq("pwwka.delayed.production") end end