From e7828e107b3d078afb20e7cd9a28a1331f865d5a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 1 Jun 2020 14:07:34 +0100 Subject: [PATCH] Delete dead methods from product_decorator --- app/models/spree/product_decorator.rb | 12 ------- spec/models/spree/product_spec.rb | 51 --------------------------- 2 files changed, 63 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index fe20fe5194..4b99aff8f2 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -158,18 +158,6 @@ Spree::Product.class_eval do self.class.in_order_cycle(order_cycle).include? self end - # overriding to check self.on_demand as well - def has_stock? - has_variants? ? variants.any?(&:in_stock?) : (on_demand || master.in_stock?) - end - - def has_stock_for_distribution?(order_cycle, distributor) - # This product has stock for a distribution if it is available on-demand - # or if one of its variants in the distribution is in stock - (!has_variants? && on_demand) || - variants_distributed_by(order_cycle, distributor).any?(&:in_stock?) - end - def variants_distributed_by(order_cycle, distributor) order_cycle.variants_distributed_by(distributor).where(product_id: self) end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index a8c6368a70..15d79596ee 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -579,57 +579,6 @@ module Spree end end - describe "stock filtering" do - it "considers products that are on_demand as being in stock" do - product = create(:simple_product, on_demand: true) - product.master.update_attribute(:on_hand, 0) - expect(product.has_stock?).to eq(true) - end - - describe "finding products in stock for a particular distribution" do - it "returns on-demand products" do - p = create(:simple_product, on_demand: true) - p.variants.first.update_attributes!(on_hand: 0, on_demand: true) - d = create(:distributor_enterprise) - oc = create(:simple_order_cycle, distributors: [d]) - oc.exchanges.outgoing.first.variants << p.variants.first - - expect(p).to have_stock_for_distribution(oc, d) - end - - it "returns products with in-stock variants" do - p = create(:simple_product) - v = create(:variant, product: p) - v.update_attribute(:on_hand, 1) - d = create(:distributor_enterprise) - oc = create(:simple_order_cycle, distributors: [d]) - oc.exchanges.outgoing.first.variants << v - - expect(p).to have_stock_for_distribution(oc, d) - end - - it "returns products with on-demand variants" do - p = create(:simple_product) - v = create(:variant, product: p, on_demand: true) - v.update_attribute(:on_hand, 0) - d = create(:distributor_enterprise) - oc = create(:simple_order_cycle, distributors: [d]) - oc.exchanges.outgoing.first.variants << v - - expect(p).to have_stock_for_distribution(oc, d) - end - - it "does not return products that have stock not in the distribution" do - p = create(:simple_product) - p.master.update_attribute(:on_hand, 1) - d = create(:distributor_enterprise) - oc = create(:simple_order_cycle, distributors: [d]) - - expect(p).not_to have_stock_for_distribution(oc, d) - end - end - end - describe "taxons" do let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) }