Sha256: 1a3dffe82eb641044c52f3008c5e42a4c487c95ea6b76aae78d42d0f1527f0d0

Contents?: true

Size: 1.9 KB

Versions: 16

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe DispatchRider::Message do
  subject(:message) { DispatchRider::Message.new(subject: 'test', body: 'test_handler') }

  describe "#initialize" do
    context "when all the required attributes are passed" do
      context "when the attributes hash has keys as strings" do
        subject(:message) { DispatchRider::Message.new('subject' => 'test', 'body' => 'test_handler') }

        it "should initiate a new message" do
          expect(message.subject).to eq('test')
          expect(message.body).to eq('test_handler')
        end
      end

      context "when the attributes hash has keys as symbols" do
        it "should initiate a new message" do
          expect(message.subject).to eq('test')
          expect(message.body).to eq('test_handler')
        end
      end
    end

    context "when all the required attributes are not passed" do
      it "should raise an exception" do
        expect { DispatchRider::Message.new({}) }.to raise_exception(DispatchRider::RecordInvalid)
      end
    end
  end

  describe "#attributes" do
    it "should return the attributes hash of the message" do
      expect(message.attributes).to eq(subject: 'test', body: 'test_handler')
    end
  end

  describe "#to_json" do
    it "should return the attributes hash in json format" do
      result = JSON.parse(message.to_json)
      expect(result['subject']).to eq('test')
      expect(result['body']).to eq('test_handler')
    end
  end

  describe "#==" do
    context "when 2 messages have the same attribute values" do
      it "should return true" do
        expect(message).to eq(DispatchRider::Message.new(subject: 'test', body: 'test_handler'))
      end
    end

    context "when 2 messages do not have same attribute values" do
      it "should return false" do
        expect(message).not_to eq(DispatchRider::Message.new(subject: 'random_test', body: 'test_handler'))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dispatch-rider-2.1.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-2.0.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.9.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.6 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.5 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.4 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.3 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.2 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.1 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.8.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.7.2 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.7.1 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.7.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.6.2 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.6.1 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.6.0 spec/lib/dispatch-rider/message_spec.rb