From c038b485b198d1678a41aaa25a4c13e5c7286bd3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 1 Oct 2019 14:43:47 +0100 Subject: [PATCH] Rename service and methods to remove use of "shop" term --- ....rb => order_cycle_distributed_products.rb} | 2 +- lib/open_food_network/products_renderer.rb | 18 +++++++++--------- .../products_renderer_spec.rb | 4 ++-- ...> order_cycle_distributed_products_spec.rb} | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) rename app/services/{shop_products_service.rb => order_cycle_distributed_products.rb} (98%) rename spec/services/{shop_products_service_spec.rb => order_cycle_distributed_products_spec.rb} (98%) diff --git a/app/services/shop_products_service.rb b/app/services/order_cycle_distributed_products.rb similarity index 98% rename from app/services/shop_products_service.rb rename to app/services/order_cycle_distributed_products.rb index 795cecc6b9..d2c9d3c4ca 100644 --- a/app/services/shop_products_service.rb +++ b/app/services/order_cycle_distributed_products.rb @@ -1,7 +1,7 @@ # Returns a (paginatable) AR object for the products or variants in stock for a given shop and OC. # The stock-checking includes on_demand and stock level overrides from variant_overrides. -class ShopProductsService +class OrderCycleDistributedProducts def initialize(distributor, order_cycle) @distributor = distributor @order_cycle = order_cycle diff --git a/lib/open_food_network/products_renderer.rb b/lib/open_food_network/products_renderer.rb index d6395e483e..527385b6e8 100644 --- a/lib/open_food_network/products_renderer.rb +++ b/lib/open_food_network/products_renderer.rb @@ -10,10 +10,10 @@ module OpenFoodNetwork end def products_json - if shop_products + if products enterprise_fee_calculator = EnterpriseFeeCalculator.new @distributor, @order_cycle - ActiveModel::ArraySerializer.new(shop_products, + ActiveModel::ArraySerializer.new(products, each_serializer: Api::ProductSerializer, current_order_cycle: @order_cycle, current_distributor: @distributor, @@ -27,20 +27,20 @@ module OpenFoodNetwork private - def shop_products + def products return unless @order_cycle - @shop_products ||= begin + @products ||= begin scoper = ScopeProductToHub.new(@distributor) - shop_products_service.products_relation. + distributed_products.products_relation. order(taxon_order). each { |product| scoper.scope(product) } end end - def shop_products_service - ShopProductsService.new(@distributor, @order_cycle) + def distributed_products + OrderCycleDistributedProducts.new(@distributor, @order_cycle) end def taxon_order @@ -58,9 +58,9 @@ module OpenFoodNetwork @variants_for_shop ||= begin scoper = OpenFoodNetwork::ScopeVariantToHub.new(@distributor) - shop_products_service.variants_relation. + distributed_products.variants_relation. includes(:default_price, :stock_locations, :product). - where(product_id: shop_products). + where(product_id: products). each { |v| scoper.scope(v) } end end diff --git a/spec/lib/open_food_network/products_renderer_spec.rb b/spec/lib/open_food_network/products_renderer_spec.rb index 1c970443d0..252f26f517 100644 --- a/spec/lib/open_food_network/products_renderer_spec.rb +++ b/spec/lib/open_food_network/products_renderer_spec.rb @@ -25,13 +25,13 @@ module OpenFoodNetwork it "sorts products by the distributor's preferred taxon list" do allow(distributor).to receive(:preferred_shopfront_taxon_order) { "#{t1.id},#{t2.id}" } - products = pr.send(:shop_products) + products = pr.send(:products) expect(products).to eq([p2, p4, p1, p3]) end it "alphabetizes products by name when taxon list is not set" do allow(distributor).to receive(:preferred_shopfront_taxon_order) { "" } - products = pr.send(:shop_products) + products = pr.send(:products) expect(products).to eq([p1, p2, p3, p4]) end end diff --git a/spec/services/shop_products_service_spec.rb b/spec/services/order_cycle_distributed_products_spec.rb similarity index 98% rename from spec/services/shop_products_service_spec.rb rename to spec/services/order_cycle_distributed_products_spec.rb index fa0c51c01e..b02baf4974 100644 --- a/spec/services/shop_products_service_spec.rb +++ b/spec/services/order_cycle_distributed_products_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ShopProductsService do +describe OrderCycleDistributedProducts do describe "#products_relation" do let(:distributor) { create(:distributor_enterprise) } let(:product) { create(:product) }