SELECT DISTINCT results in inconsistent #count value. Work around this with to_a.

This commit is contained in:
Rohan Mitchell
2015-08-05 11:05:29 +10:00
parent eca25a2564
commit be66769999
4 changed files with 8 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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