From 7585e3d1d6e7e1648b05abfc54e6b8367563e2ee Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 10 Mar 2020 18:40:46 +0000 Subject: [PATCH] The variants_to_a method was dead but actually we can use it to make the code simpler --- lib/open_food_network/order_cycle_form_applicator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 611f120f62..8f9c4308d8 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -149,7 +149,7 @@ module OpenFoodNetwork receiver = @order_cycle.coordinator exchange = find_exchange(sender.id, receiver.id, true) - requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested + requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist editable_ids = editable_variant_ids_for_incoming_exchange_between(sender, receiver) # The ids we are allowed to add/remove @@ -166,7 +166,7 @@ module OpenFoodNetwork receiver = Enterprise.find(attrs[:enterprise_id]) exchange = find_exchange(sender.id, receiver.id, false) - requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested + requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist editable_ids = editable_variant_ids_for_outgoing_exchange_between(sender, receiver) # The ids we are allowed to add/remove @@ -184,7 +184,7 @@ module OpenFoodNetwork end def variants_to_a(variants) - variants.select { |_k, v| v }.keys.map(&:to_i).sort + variants.select { |_k, v| v }.keys.map(&:to_i) end end end