Merge branch 'ordercyclemanagementreports2' of https://github.com/lin-d-hop/openfoodnetwork into lin-d-hop-ordercyclemanagementreports2

This commit is contained in:
Rohan Mitchell
2015-03-13 10:47:49 +11:00
2 changed files with 9 additions and 5 deletions

View File

@@ -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.*')
}

View File

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