Fix handling of empty order cycle params

This guard clause was returning an instance of an unpermitted Params object (containing a blank hash) here, which was causing unexpected results in various places. Returning a blank hash explicitly resolved the issue.

Fixes:

4) Admin::OrderCyclesController create as a manager of a shop when creation is successful returns success: true and a valid edit path
     Failure/Error:
       @order_cycle_params ||= PermittedAttributes::OrderCycle.new(params).call.
         to_h.with_indifferent_access

     ActionController::UnfilteredParameters:
       unable to convert unpermitted parameters to hash
     # ./app/controllers/admin/order_cycles_controller.rb:245:in `order_cycle_params'
     # ./app/controllers/admin/order_cycles_controller.rb:44:in `create'
     # ./spec/support/controller_requests_helper.rb:49:in `process_action_with_route'
     # ./spec/support/controller_requests_helper.rb:27:in `spree_post'
     # ./spec/controllers/admin/order_cycles_controller_spec.rb:124:in `block (5 levels) in <module:Admin>'
This commit is contained in:
Matt-Yorkley
2021-03-27 14:54:27 +00:00
committed by Andy Brett
parent 6f8ade52eb
commit 72c6935ff8

View File

@@ -7,7 +7,7 @@ module PermittedAttributes
end
def call
return @params[:order_cycle] if @params[:order_cycle].blank?
return {} if @params[:order_cycle].blank?
@params.require(:order_cycle).permit(attributes)
end