models/message.rb
class Message
attr_reader :bundle_id, :order_id, :order_number, :event
def initialize(message)
hash = message
@bundle_id = hash[:payload][:bundle_id]
@order_id = hash[:payload][:order_id]
@order_number = hash[:payload][:order_number]
@event = hash[:concern]
end
end
spec/models/message_spec.rb
require 'spec_helper'
describe Message do
it 'should save the payload' do
payload = {:payload=>{:order_id=>138251, :order_number=>"AW116554416"}, :concern=>"order_create"}
message = FactoryGirl.build(:message, {:payload=>{:order_id=>138251, :order_number=>"AW116554416"}, :concern=>"order_create"})
message.event.should == "order_create"
end
end
error_log
Failures:
1) Message should save the payload
Failure/Error: message = FactoryGirl.build(:message, {:payload=>{:order_id=>138251, :order_number=>"AW116554416"}, :concern=>"order_create"})
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/models/message.rb:4:in `initialize'
# ./spec/models/message_spec.rb:7:in `block (2 levels) in <top (required)>'