diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index c4dfeaeb64..5d3e317572 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -68,7 +68,7 @@ Spree::Order.class_eval do scope :with_payment_method_name, lambda { |payment_method_name| joins(:payments => :payment_method). - where('spree_payment_methods.name = ?', payment_method_name). + where('spree_payment_methods.name IN (?)', payment_method_name). select('DISTINCT spree_orders.*') } diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 114f774a1d..ae689e009e 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -337,7 +337,7 @@ describe Spree::Order do end end - describe "with payment method name" do + describe "with payment method names" do let!(:o1) { create(:order) } let!(:o2) { create(:order) } let!(:pm1) { create(:payment_method, name: 'foo') } @@ -345,8 +345,12 @@ describe Spree::Order do let!(:p1) { create(:payment, order: o1, payment_method: pm1) } let!(:p2) { create(:payment, order: o2, payment_method: pm2) } - it "returns the order with payment method name" do - Spree::Order.with_payment_method_name('foo').should == [o1] + it "returns the order with payment method name when one specified" do + Spree::Order.with_payment_method_name('foo').should == [o1] + end + + it "returns the orders with payment method name when many specified" do + Spree::Order.with_payment_method_name(['foo', 'bar']).should include o1, o2 end it "doesn't return rows with a different payment method name" do @@ -356,7 +360,7 @@ describe Spree::Order do it "doesn't return duplicate rows" do p2 = FactoryGirl.create(:payment, :order => o1, :payment_method => pm1) - Spree::Order.with_payment_method_name('foo').length.should == 1 + Spree::Order.with_payment_method_name('foo').length.should == 1 end end end