From daab0dfd7a8690126b05611ffc0b4a4bbba7ee03 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 17 May 2017 12:38:17 +1000 Subject: [PATCH] Refactor: Splitting changeable_order_from_number out into separate method --- .../spree/orders_controller_decorator.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 7d221ddbeb..22791661fb 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -224,16 +224,18 @@ Spree::OrdersController.class_eval do n == Float::INFINITY ? 2147483647 : n end - # If a specific order is mentioned, check that it is COMPLETE, that changes - # are allowed and that the user has access. Return nil if not. def order_to_update return @order_to_update if defined? @order_to_update return @order_to_update = current_order unless params[:id] - @order_to_update = begin - order = Spree::Order.complete.find_by_number(params[:id]) - order = nil unless order.andand.changes_allowed? && can?(:update, order) - order - end + @order_to_update = changeable_order_from_number + end + + # If a specific order is requested, return it if it is COMPLETE and + # changes are allowed and the user has access. Return nil if not. + def changeable_order_from_number + order = Spree::Order.complete.find_by_number(params[:id]) + return nil unless order.andand.changes_allowed? && can?(:update, order) + order end def check_at_least_one_line_item