Remove QueriesProductDistribution - replaced by Product and Enterprise scopes

This commit is contained in:
Rohan Mitchell
2013-03-08 16:57:54 +11:00
parent c9d1573049
commit 711f769bcd
2 changed files with 0 additions and 44 deletions

View File

@@ -1,29 +0,0 @@
module OpenFoodWeb
class QueriesProductDistribution
def self.active_distributors
(active_distributors_for_product_distributions + active_distributors_for_order_cycles).sort_by { |d| d.name }.uniq
end
private
def self.active_distributors_for_product_distributions
Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name
end
def self.active_distributors_for_order_cycles
# Can I create this with merge scopes?
# ie. Enterprise.is_distributor.join(:order_cycle_distributor).merge(OrderCycle.active)
# Try this:
Enterprise.joins('LEFT INNER JOIN exchanges ON (exchanges.receiver_id = enterprises.id)').joins('LEFT INNER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle.id)').
merge(OrderCycle.active).select('DISTINCT enterprises.*')
# Then I can make each of these methods into a scope on Enterprise, and ultimately a single scope
# Then we don't need this class.
OrderCycle.active.map { |oc| oc.distributors }.flatten.uniq
end
end
end

View File

@@ -1,15 +0,0 @@
require 'open_food_web/queries_product_distribution'
module OpenFoodWeb
describe QueriesProductDistribution do
it "fetches active distributors" do
d1 = double(:distributor_a, name: 'a')
d2 = double(:distributor_b, name: 'b')
d3 = double(:distributor_c, name: 'c')
QueriesProductDistribution.should_receive(:active_distributors_for_product_distributions).and_return([d1, d3])
QueriesProductDistribution.should_receive(:active_distributors_for_order_cycles).and_return([d1, d2])
QueriesProductDistribution.active_distributors.should == [d1, d2, d3]
end
end
end