mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove QueriesProductDistribution - replaced by Product and Enterprise scopes
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user