From 4a67acf954390d08ca7689771a632246eefd70be Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 10 May 2019 12:21:20 +0100 Subject: [PATCH] Removing a few rubocop warnings --- .rubocop_manual_todo.yml | 4 -- app/controllers/application_controller.rb | 5 ++- app/controllers/base_controller.rb | 4 +- app/controllers/checkout_controller.rb | 40 ++++++++++++++----- app/controllers/enterprises_controller.rb | 7 +++- app/controllers/shop_controller.rb | 7 +++- .../user_confirmations_controller.rb | 7 +++- 7 files changed, 50 insertions(+), 24 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index e522ba7e80..f8de8f86e7 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -41,10 +41,7 @@ Metrics/LineLength: - app/controllers/api/enterprise_attachment_controller.rb - app/controllers/api/product_images_controller.rb - app/controllers/application_controller.rb - - app/controllers/base_controller.rb - - app/controllers/cart_controller.rb - app/controllers/checkout_controller.rb - - app/controllers/shop_controller.rb - app/controllers/spree/admin/adjustments_controller_decorator.rb - app/controllers/spree/admin/base_controller_decorator.rb - app/controllers/spree/admin/line_items_controller_decorator.rb @@ -58,7 +55,6 @@ Metrics/LineLength: - app/controllers/spree/orders_controller_decorator.rb - app/controllers/spree/paypal_controller_decorator.rb - app/controllers/stripe/callbacks_controller.rb - - app/controllers/user_confirmations_controller.rb - app/helpers/admin/account_helper.rb - app/helpers/admin/injection_helper.rb - app/helpers/angular_form_builder.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b0cae8049..14179ca695 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery prepend_before_filter :restrict_iframes - before_filter :set_cache_headers # Issue #1213, prevent cart emptying via cache when using back button + before_filter :set_cache_headers # prevent cart emptying via cache when using back button #1213 include EnterprisesHelper @@ -16,7 +16,8 @@ class ApplicationController < ActionController::Base def set_checkout_redirect referer_path = OpenFoodNetwork::RefererParser::path(request.referer) if referer_path - session["spree_user_return_to"] = [main_app.checkout_path].include?(referer_path) ? referer_path : root_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 : root_path end end diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 36bf72fd9c..b01b5b002e 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -32,7 +32,9 @@ class BaseController < ApplicationController @order_cycles = OrderCycle.with_distributor(@distributor).active .order(@distributor.preferred_shopfront_order_cycle_order) - applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", current_customer.andand.tag_list) + applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, + "FilterOrderCycles", + current_customer.andand.tag_list) applicator.filter!(@order_cycles) # And default to the only order cycle if there's only the one diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 56b163cec0..c0f9c0a21b 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -82,10 +82,14 @@ class CheckoutController < Spree::CheckoutController new_bill_address = @order.bill_address.clone.attributes user_bill_address_id = spree_current_user.bill_address.andand.id - spree_current_user.update_attributes(bill_address_attributes: new_bill_address.merge('id' => user_bill_address_id)) + spree_current_user.update_attributes( + bill_address_attributes: new_bill_address.merge('id' => user_bill_address_id) + ) customer_bill_address_id = @order.customer.bill_address.andand.id - @order.customer.update_attributes(bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id)) + @order.customer.update_attributes( + bill_address_attributes: new_bill_address.merge('id' => customer_bill_address_id) + ) end end @@ -94,16 +98,23 @@ class CheckoutController < Spree::CheckoutController new_ship_address = @order.ship_address.clone.attributes user_ship_address_id = spree_current_user.ship_address.andand.id - spree_current_user.update_attributes(ship_address_attributes: new_ship_address.merge('id' => user_ship_address_id)) + spree_current_user.update_attributes( + ship_address_attributes: new_ship_address.merge('id' => user_ship_address_id) + ) customer_ship_address_id = @order.customer.ship_address.andand.id - @order.customer.update_attributes(ship_address_attributes: new_ship_address.merge('id' => customer_ship_address_id)) + @order.customer.update_attributes( + ship_address_attributes: new_ship_address.merge('id' => customer_ship_address_id) + ) end end def check_order_for_phantom_fees - phantom_fees = @order.adjustments.joins('LEFT OUTER JOIN spree_line_items ON spree_line_items.id = spree_adjustments.source_id'). - where("originator_type = 'EnterpriseFee' AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL") + phantom_fees = @order.adjustments. + joins("LEFT OUTER JOIN spree_line_items"\ + " ON spree_line_items.id = spree_adjustments.source_id"). + where("originator_type = 'EnterpriseFee'"\ + " AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL") if phantom_fees.any? Bugsnag.notify(RuntimeError.new("Phantom Fees"), { @@ -118,7 +129,9 @@ class CheckoutController < Spree::CheckoutController # Copied and modified from spree. Remove check for order state, since the state machine is # progressed all the way in one go with the one page checkout. def object_params - # For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected + # For payment step, filter order parameters to produce the expected + # nested attributes for a single payment and its source, + # discarding attributes for payment methods other than the one selected if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore] params[:order][:payments_attributes].first[:source_attributes] = source_params end @@ -154,7 +167,8 @@ class CheckoutController < Spree::CheckoutController end end - # When we have a pickup Shipping Method, we clone the distributor address into ship_address before_save + # When we have a pickup Shipping Method, + # we clone the distributor address into ship_address before_save # We don't want this data in the form, so we clear it out def clear_ship_address unless current_order.shipping_method.andand.require_ship_address @@ -185,7 +199,9 @@ class CheckoutController < Spree::CheckoutController end def valid_order_line_items? - @order.insufficient_stock_lines.empty? && OrderCycleDistributedVariants.new(@order.order_cycle, @order.distributor).distributes_order_variants?(@order) + @order.insufficient_stock_lines.empty? && + OrderCycleDistributedVariants.new(@order.order_cycle, @order.distributor). + distributes_order_variants?(@order) end def redirect_to_cart_path @@ -203,10 +219,12 @@ class CheckoutController < Spree::CheckoutController def redirect_to_paypal_express_form_if_needed return unless params[:order][:payments_attributes] - payment_method = Spree::PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id]) + payment_method_id = params[:order][:payments_attributes].first[:payment_method_id] + payment_method = Spree::PaymentMethod.find(payment_method_id) return unless payment_method.kind_of?(Spree::Gateway::PayPalExpress) - render json: {path: spree.paypal_express_path(payment_method_id: payment_method.id)}, status: 200 + render json: {path: spree.paypal_express_path(payment_method_id: payment_method.id)}, + status: 200 true end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index cfaab8de47..6a74f58b01 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -42,7 +42,9 @@ class EnterprisesController < BaseController end def check_permalink - render text: params[:permalink], status: 409 and return if Enterprise.find_by_permalink params[:permalink] + if Enterprise.find_by_permalink params[:permalink] + render text: params[:permalink], status: 409 and return + end begin Rails.application.routes.recognize_path( "/#{ params[:permalink].to_s }" ) @@ -67,7 +69,8 @@ class EnterprisesController < BaseController end def reset_order - distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || Enterprise.is_distributor.find(params[:id]) + distributor = Enterprise.is_distributor.find_by_permalink(params[:id]) || + Enterprise.is_distributor.find(params[:id]) order = current_order(true) reset_distributor(order, distributor) diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index 4160bc1690..c8c67f7672 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -11,7 +11,8 @@ class ShopController < BaseController def products begin - renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor, current_order_cycle) + renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor, + current_order_cycle) # If we add any more filtering logic, we should probably # move it all to a lib class like 'CachedProductsFilterer' @@ -59,6 +60,8 @@ class ShopController < BaseController def applicator return @applicator unless @applicator.nil? - @applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterProducts", current_customer.andand.tag_list) + @applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, + "FilterProducts", + current_customer.andand.tag_list) end end diff --git a/app/controllers/user_confirmations_controller.rb b/app/controllers/user_confirmations_controller.rb index e564da0b64..1e15a6a296 100644 --- a/app/controllers/user_confirmations_controller.rb +++ b/app/controllers/user_confirmations_controller.rb @@ -1,5 +1,6 @@ class UserConfirmationsController < DeviseController - include Spree::Core::ControllerHelpers::Auth # Needed for access to current_ability, so we can authorize! actions + # Needed for access to current_ability, so we can authorize! actions + include Spree::Core::ControllerHelpers::Auth # GET /resource/confirmation/new def new @@ -44,7 +45,9 @@ class UserConfirmationsController < DeviseController end if resource.reset_password_token.present? - return spree.edit_spree_user_password_path(reset_password_token: resource.reset_password_token) + return spree.edit_spree_user_password_path( + reset_password_token: resource.reset_password_token + ) end path = (session[:confirmation_return_url] || login_path).to_s