Skip to content

Commit

Permalink
Fix rubocop issues in app/controllers/application_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
luisramos0 committed Dec 28, 2019
1 parent d0f33e7 commit 4658b7a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def set_checkout_redirect
referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
if referer_path
is_checkout_path_the_referer = [main_app.checkout_path].include?(referer_path)
session["spree_user_return_to"] = is_checkout_path_the_referer ? referer_path : main_app.root_path
session["spree_user_return_to"] = if is_checkout_path_the_referer
referer_path
else
main_app.root_path
end
end
end

Expand Down Expand Up @@ -86,19 +90,21 @@ def require_order_cycle
end

def check_hub_ready_for_checkout
# This condition is more rigourous than required by development to avoid coupling this
# condition to every controller spec
if current_distributor && current_order &&
current_distributor.respond_to?(:ready_for_checkout?) &&
!current_distributor.ready_for_checkout?

if current_distributor_closed?
current_order.empty!
current_order.set_distribution! nil, nil
flash[:info] = "The hub you have selected is temporarily closed for orders. Please try again later."
redirect_to main_app.root_url
end
end

def current_distributor_closed?
current_distributor &&
current_order &&
current_distributor.respond_to?(:ready_for_checkout?) &&
!current_distributor.ready_for_checkout?
end

def check_order_cycle_expiry
if current_order_cycle.andand.closed?
session[:expired_order_cycle_id] = current_order_cycle.id
Expand Down

0 comments on commit 4658b7a

Please sign in to comment.