From 0e62dc04bdee27cb137488689923cbec513340c8 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 21 Feb 2020 12:10:01 +0000 Subject: [PATCH] Improve comments to explain glitch on set_order_cycle and OrderCyclesList --- app/controllers/base_controller.rb | 4 ++-- app/services/shop/order_cycles_list.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index afaa3b42d3..dab3eb6752 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -37,8 +37,8 @@ class BaseController < ApplicationController # Default to the only order cycle if there's only one # # Here we need to use @order_cycles.size not @order_cycles.count - # because TagRuleApplicator changes ActiveRecord::Relation @order_cycles - # and these changes are not seen if the relation is reloaded with count + # because OrderCyclesList returns a modified ActiveRecord::Relation + # and these modifications are not seen if it is reloaded with count def set_order_cycle return if @order_cycles.size != 1 diff --git a/app/services/shop/order_cycles_list.rb b/app/services/shop/order_cycles_list.rb index 730343ca6e..d4ee5e07c3 100644 --- a/app/services/shop/order_cycles_list.rb +++ b/app/services/shop/order_cycles_list.rb @@ -12,6 +12,14 @@ module Shop order_cycles = OrderCycle.with_distributor(@distributor).active .order(@distributor.preferred_shopfront_order_cycle_order) + apply_tag_rules!(order_cycles) + end + + private + + # order_cycles is a ActiveRecord::Relation that is modified with reject in the TagRuleApplicator + # If this relation is reloaded (for example by calling count on it), the modifications are lost + def apply_tag_rules!(order_cycles) applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", @customer.andand.tag_list)