Skip to content

Commit

Permalink
Merge pull request spree#47 from bonobos/send_retro_refunds
Browse files Browse the repository at this point in the history
add order_id to refund serializer
  • Loading branch information
allisonlarson committed Feb 9, 2015
2 parents 11c27a5 + ad8508c commit 3e7a40b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/serializers/spree/wombat/refund_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
module Spree
module Wombat
class RefundSerializer < ActiveModel::Serializer
attributes :reason, :amount, :description
attributes :reason, :amount, :description, :order_id, :store, :code
has_one :payment, serializer: Spree::Wombat::PaymentSerializer

def reason
object.reason.try(:name)
end

def code
object.reason.try(:code)
end

def order_id
object.payment.order.try(:number)
end

def store
{ code: object.payment.order.store.code }
end
end
end
end
13 changes: 13 additions & 0 deletions spec/serializers/spree/hub/refund_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@ module Wombat
describe RefundSerializer do
let(:refund) { build(:refund) }
let(:serialized_refund) { JSON.parse(RefundSerializer.new(refund, root: false).to_json, symbolize_names: true) }
before { refund.reason.update_attributes!(code: '12345') }

context "format" do
it "sets the reason" do
expect(serialized_refund[:reason]).to match /Refund/
end

it 'sets the code' do
expect(serialized_refund[:code]).to eq '12345'
end

it "includes the payment" do
expect(serialized_refund[:payment]).to be_present
end

it "includes the order_id" do
expect(serialized_refund[:order_id]).to eq refund.payment.order.number
end

it "includes the store" do
expect(serialized_refund[:store][:code]).to eq refund.payment.order.store.code
end
end
end
end
Expand Down

0 comments on commit 3e7a40b

Please sign in to comment.