From 9c2c4308675a84fa6a754514e211113a749438d4 Mon Sep 17 00:00:00 2001 From: Luuk Veenis Date: Thu, 17 Aug 2017 09:54:40 -0700 Subject: [PATCH 1/2] Add failing spec to expose bug The `Spree::ReturnAuthorization#amount` method currently calls: `return_item.sum(:amount)` This will raise a method missing error because the association is a `has_many`, so we need to call `return_items.sum(:amount)`. --- core/spec/models/spree/return_authorization_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/spec/models/spree/return_authorization_spec.rb b/core/spec/models/spree/return_authorization_spec.rb index 8192b74c9fc..25a048695e1 100644 --- a/core/spec/models/spree/return_authorization_spec.rb +++ b/core/spec/models/spree/return_authorization_spec.rb @@ -101,6 +101,18 @@ end end + describe "#amount" do + let(:return_item1) { create(:return_item, amount: 10) } + let(:return_item2) { create(:return_item, amount: 5) } + let(:return_authorization) { create(:return_authorization, return_items: [return_item1, return_item2]) } + + subject { return_authorization.amount } + + it "sums the return items' amounts", skip: "failing test to demonstrate bug" do + expect(subject).to eq(15) + end + end + describe "#refundable_amount" do let(:line_item_price) { 5.0 } let(:line_item_count) { return_authorization.order.line_items.count } From fb90f5fcccf72e91a1f3554fe375981d407f9db8 Mon Sep 17 00:00:00 2001 From: Luuk Veenis Date: Thu, 17 Aug 2017 09:56:58 -0700 Subject: [PATCH 2/2] Fix method missing error on RMAs `return_items` is a `has_many` association, but we're currently calling `return_item.sum(:amount)` which raises a method missing error. --- core/app/models/spree/return_authorization.rb | 2 +- core/spec/models/spree/return_authorization_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rb index 1e757700a51..017ad0093e5 100644 --- a/core/app/models/spree/return_authorization.rb +++ b/core/app/models/spree/return_authorization.rb @@ -38,7 +38,7 @@ def pre_tax_total end def amount - return_item.sum(:amount) + return_items.sum(:amount) end def currency diff --git a/core/spec/models/spree/return_authorization_spec.rb b/core/spec/models/spree/return_authorization_spec.rb index 25a048695e1..f3fdc8eb97b 100644 --- a/core/spec/models/spree/return_authorization_spec.rb +++ b/core/spec/models/spree/return_authorization_spec.rb @@ -108,7 +108,7 @@ subject { return_authorization.amount } - it "sums the return items' amounts", skip: "failing test to demonstrate bug" do + it "sums the return items' amounts" do expect(subject).to eq(15) end end