From 0d07bf2a3b25fe80a50fbcd51c1acdcbff6423f0 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 7 Apr 2019 11:24:31 +0100 Subject: [PATCH] Adapt enterprise.distributing_products scope to rails 4 --- app/models/enterprise.rb | 8 ++++---- app/models/spree/product_decorator.rb | 2 +- spec/models/enterprise_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a85ffb00e7..3908650eb8 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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 diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 33367ef319..ef75d1601e 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -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 diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index c648031e88..4e3e9d5565 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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