Taking payment methods with no distributor out of circulation

This commit is contained in:
Will Marshall
2014-03-19 12:03:39 +11:00
parent 3df3afe068
commit abf1b17fe9
2 changed files with 15 additions and 2 deletions

View File

@@ -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

View File

@@ -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) }