mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #2004 from coopdevs/is-this-needed
Remove unused Enterprise scopes
This commit is contained in:
@@ -120,16 +120,6 @@ class Enterprise < ActiveRecord::Base
|
||||
scope :is_distributor, where('sells != ?', 'none')
|
||||
scope :is_hub, where(sells: 'any')
|
||||
scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') }
|
||||
scope :with_supplied_active_products_on_hand, lambda {
|
||||
joins(:supplied_products)
|
||||
.where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.zone.now)
|
||||
.uniq
|
||||
}
|
||||
scope :with_distributed_active_products_on_hand, lambda {
|
||||
joins(:distributed_products)
|
||||
.where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.zone.now)
|
||||
.uniq
|
||||
}
|
||||
|
||||
scope :with_distributed_products_outer,
|
||||
joins('LEFT OUTER JOIN product_distributions ON product_distributions.distributor_id = enterprises.id').
|
||||
|
||||
@@ -457,57 +457,6 @@ describe Enterprise do
|
||||
end
|
||||
end
|
||||
|
||||
describe "with_distributed_active_products_on_hand" do
|
||||
it "returns distributors with products in stock" do
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
d4 = create(:distributor_enterprise)
|
||||
create(:product, :distributors => [d1, d2], :on_hand => 5)
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 0)
|
||||
|
||||
Enterprise.with_distributed_active_products_on_hand.should match_array [d1, d2]
|
||||
end
|
||||
|
||||
it "returns distributors with available products in stock" do
|
||||
d1 = create(:distributor_enterprise) # two products on hand
|
||||
d2 = create(:distributor_enterprise) # one product on hand
|
||||
d3 = create(:distributor_enterprise) # product on hand but not yet available
|
||||
d4 = create(:distributor_enterprise) # no products on hand
|
||||
d5 = create(:distributor_enterprise) # deleted product
|
||||
d6 = create(:distributor_enterprise) # no products
|
||||
create(:product, :distributors => [d1, d2], :on_hand => 5)
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 5, :available_on => 1.week.from_now)
|
||||
create(:product, :distributors => [d4], :on_hand => 0)
|
||||
create(:product, :distributors => [d5]).delete
|
||||
|
||||
Enterprise.with_distributed_active_products_on_hand.should match_array [d1, d2]
|
||||
Enterprise.with_distributed_active_products_on_hand.distinct_count.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "with_supplied_active_products_on_hand" do
|
||||
it "returns suppliers with available products in stock" do
|
||||
d1 = create(:supplier_enterprise) # two products on hand
|
||||
d2 = create(:supplier_enterprise) # one product on hand
|
||||
d3 = create(:supplier_enterprise) # product on hand but not yet available
|
||||
d4 = create(:supplier_enterprise) # no products on hand
|
||||
d5 = create(:supplier_enterprise) # deleted product
|
||||
d6 = create(:supplier_enterprise) # no products
|
||||
create(:product, :supplier => d1, :on_hand => 5)
|
||||
create(:product, :supplier => d1, :on_hand => 5)
|
||||
create(:product, :supplier => d2, :on_hand => 5)
|
||||
create(:product, :supplier => d3, :on_hand => 5, :available_on => 1.week.from_now)
|
||||
create(:product, :supplier => d4, :on_hand => 0)
|
||||
create(:product, :supplier => d5).delete
|
||||
|
||||
Enterprise.with_supplied_active_products_on_hand.should match_array [d1, d2]
|
||||
Enterprise.with_supplied_active_products_on_hand.distinct_count.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "supplying_variant_in" do
|
||||
it "finds producers by supply of master variant" do
|
||||
s = create(:supplier_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user