mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
SELECT DISTINCT results in inconsistent #count value. Work around this with to_a.
This commit is contained in:
@@ -136,7 +136,8 @@ class OrderCycle < ActiveRecord::Base
|
||||
joins(:exchanges).
|
||||
merge(Exchange.in_order_cycle(self)).
|
||||
not_deleted.
|
||||
select('DISTINCT spree_variants.*')
|
||||
select('DISTINCT spree_variants.*').
|
||||
to_a # http://stackoverflow.com/q/15110166
|
||||
end
|
||||
|
||||
def distributed_variants
|
||||
|
||||
@@ -89,7 +89,7 @@ module OpenFoodNetwork
|
||||
|
||||
def load_coordinator_fees
|
||||
@order_cycle.coordinator_fees.per_item.each do |enterprise_fee|
|
||||
@order_cycle.variants.pluck(:id).each do |variant_id|
|
||||
@order_cycle.variants.map(&:id).each do |variant_id|
|
||||
@indexed_enterprise_fees[variant_id] ||= []
|
||||
@indexed_enterprise_fees[variant_id] << enterprise_fee
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ FactoryGirl.define do
|
||||
ExchangeFee.create!(exchange: ex2,
|
||||
enterprise_fee: create(:enterprise_fee, enterprise: ex2.sender))
|
||||
|
||||
#Distributors
|
||||
# Distributors
|
||||
distributor1 = create(:distributor_enterprise)
|
||||
distributor2 = create(:distributor_enterprise)
|
||||
|
||||
|
||||
@@ -218,6 +218,10 @@ describe OrderCycle do
|
||||
@oc.variants.should match_array [@p0.master, @p1.master, @p2.master, @p2_v]
|
||||
end
|
||||
|
||||
it "returns the correct count of variants" do
|
||||
@oc.variants.count.should == 4
|
||||
end
|
||||
|
||||
it "reports on the variants distributed" do
|
||||
@oc.distributed_variants.should match_array [@p1.master, @p2.master, @p2_v]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user