From 660d3f326fc5ab883ca106b6aa73d416af5828cb Mon Sep 17 00:00:00 2001 From: Enrico Stano Date: Wed, 20 Dec 2017 16:00:35 +1100 Subject: [PATCH] Remove unused Enterprise scopes --- app/models/enterprise.rb | 10 ------- spec/models/enterprise_spec.rb | 51 ---------------------------------- 2 files changed, 61 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 0afa4c6e66..a8111d963f 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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'). diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 8c16ac39eb..12fc3bd744 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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)