mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Adapt enterprise.distributing_products scope to rails 4
This commit is contained in:
@@ -111,7 +111,7 @@ class Enterprise < ActiveRecord::Base
|
||||
joins(:shipping_methods).
|
||||
joins(:payment_methods).
|
||||
merge(Spree::PaymentMethod.available).
|
||||
select('DISTINCT enterprises.*')
|
||||
select('DISTINCT enterprises.id')
|
||||
}
|
||||
scope :not_ready_for_checkout, lambda {
|
||||
# When ready_for_checkout is empty, return all rows when there are no enterprises ready for
|
||||
@@ -165,14 +165,14 @@ class Enterprise < ActiveRecord::Base
|
||||
select('DISTINCT enterprises.*')
|
||||
}
|
||||
|
||||
scope :distributing_products, lambda { |products|
|
||||
scope :distributing_products, lambda { |product_ids|
|
||||
exchanges = joins("
|
||||
INNER JOIN exchanges
|
||||
ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')
|
||||
").
|
||||
joins('INNER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
|
||||
joins('INNER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)').
|
||||
where('spree_variants.product_id IN (?)', products).select('DISTINCT enterprises.id')
|
||||
where('spree_variants.product_id IN (?)', product_ids).select('DISTINCT enterprises.id')
|
||||
|
||||
where(id: exchanges)
|
||||
}
|
||||
@@ -449,7 +449,7 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def touch_distributors
|
||||
Enterprise.distributing_products(supplied_products).
|
||||
Enterprise.distributing_products(supplied_products.select(:id)).
|
||||
where('enterprises.id != ?', id).
|
||||
find_each(&:touch)
|
||||
end
|
||||
|
||||
@@ -216,7 +216,7 @@ Spree::Product.class_eval do
|
||||
end
|
||||
|
||||
def touch_distributors
|
||||
Enterprise.distributing_products(self).each(&:touch)
|
||||
Enterprise.distributing_products(self.id).each(&:touch)
|
||||
end
|
||||
|
||||
def add_primary_taxon_to_taxons
|
||||
|
||||
@@ -360,13 +360,13 @@ describe Enterprise do
|
||||
|
||||
it "returns enterprises distributing via an order cycle" do
|
||||
order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master])
|
||||
expect(Enterprise.distributing_products(product)).to eq([distributor])
|
||||
expect(Enterprise.distributing_products(product.id)).to eq([distributor])
|
||||
end
|
||||
|
||||
it "does not return duplicate enterprises" do
|
||||
another_product = create(:product)
|
||||
order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master, another_product.master])
|
||||
expect(Enterprise.distributing_products([product, another_product])).to eq([distributor])
|
||||
expect(Enterprise.distributing_products([product.id, another_product.id])).to eq([distributor])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user