From abf1b17fe933a179ec24bfb5a0d1119dba7ec0a0 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 19 Mar 2014 12:03:39 +1100 Subject: [PATCH] Taking payment methods with no distributor out of circulation --- app/models/spree/order_decorator.rb | 4 ++-- spec/models/spree/order_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index c744a3270a..40c06c3132 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -133,10 +133,10 @@ Spree::Order.class_eval do line_items.map { |li| li.variant } end - # Show payment methods with no distributor or for this distributor + # Show payment methods for this distributor def available_payment_methods @available_payment_methods ||= Spree::PaymentMethod.available(:front_end).select do |pm| - (self.distributor && (pm.distributors.include? self.distributor)) || pm.distributors.empty? + (self.distributor && (pm.distributors.include? self.distributor)) end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index ff17188998..80a65b79cc 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -22,6 +22,19 @@ describe Spree::Order do end end + describe "Payment methods" do + let(:order) { build(:order, distributor: create(:distributor_enterprise)) } + let(:pm1) { create(:payment_method, distributors: [order.distributor])} + let(:pm2) { create(:payment_method, distributors: [])} + + it "finds the correct payment methods" do + Spree::PaymentMethod.stub(:available).and_return [pm1, pm2] + order.available_payment_methods.include?(pm2).should == false + order.available_payment_methods.include?(pm1).should == true + end + + end + describe "updating the distribution charge" do let(:order) { build(:order) }