From b879439d5835fe487f01d1c2dd6480c9601ee3aa Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 22 Jun 2020 13:26:02 +0100 Subject: [PATCH] Use rubocop auto correct to fix Style/SafeNavigation issue --- app/controllers/spree/credit_cards_controller.rb | 2 +- app/controllers/spree/orders_controller.rb | 2 +- app/helpers/i18n_helper.rb | 2 +- app/models/producer_property.rb | 2 +- app/models/product_import/entry_validator.rb | 9 ++++----- app/models/product_import/product_importer.rb | 4 ++-- app/models/proxy_order.rb | 4 ++-- lib/discourse/single_sign_on.rb | 4 +--- spec/factories.rb | 4 +--- 9 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index fe23cd5d6e..a1c2e60ea5 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -60,7 +60,7 @@ module Spree def destroy_at_stripe stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {}) - stripe_customer.delete if stripe_customer + stripe_customer&.delete end def stripe_account_id diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index d77c4c0719..85939fe1ad 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -166,7 +166,7 @@ module Spree # recalculates the shipment taxes def update_totals_and_taxes @order.updater.update_totals - @order.shipment.ensure_correct_adjustment_with_included_tax if @order.shipment + @order.shipment&.ensure_correct_adjustment_with_included_tax end # Sets the adjustments to open to perform the block's action and restores diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index b316b3e3ce..a04405ac97 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -2,7 +2,7 @@ module I18nHelper def set_locale # Save a given locale if params[:locale] && available_locale?(params[:locale]) - spree_current_user.update!(locale: params[:locale]) if spree_current_user + spree_current_user&.update!(locale: params[:locale]) cookies[:locale] = params[:locale] end diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb index 75f3d98f17..278118871d 100644 --- a/app/models/producer_property.rb +++ b/app/models/producer_property.rb @@ -5,7 +5,7 @@ class ProducerProperty < ActiveRecord::Base default_scope { order("#{table_name}.position") } def property_name - property.name if property + property&.name end def property_name=(name) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index fa2380c07b..ad88cbd369 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -154,21 +154,21 @@ module ProductImport def unit_fields_validation(entry) unit_types = ['g', 'kg', 't', 'ml', 'l', 'kl', ''] - unless entry.units && entry.units.present? + unless entry.units&.present? mark_as_invalid(entry, attribute: 'units', error: I18n.t('admin.product_import.model.blank')) end return if import_into_inventory? # unit_type must be valid type - if entry.unit_type && entry.unit_type.present? + if entry.unit_type&.present? unit_type = entry.unit_type.to_s.strip.downcase mark_as_invalid(entry, attribute: 'unit_type', error: I18n.t('admin.product_import.model.incorrect_value')) unless unit_types.include?(unit_type) return end # variant_unit_name must be present if unit_type not present - mark_as_invalid(entry, attribute: 'variant_unit_name', error: I18n.t('admin.product_import.model.conditional_blank')) unless entry.variant_unit_name && entry.variant_unit_name.present? + mark_as_invalid(entry, attribute: 'variant_unit_name', error: I18n.t('admin.product_import.model.conditional_blank')) unless entry.variant_unit_name&.present? end def variant_of_product_validation(entry) @@ -372,8 +372,7 @@ module ProductImport def inventory_permission?(enterprise_id, producer_id) @current_user.admin? || - ( @inventory_permissions[enterprise_id] && - @inventory_permissions[enterprise_id].include?(producer_id) ) + ( @inventory_permissions[enterprise_id]&.include?(producer_id) ) end def mark_as_invalid(entry, options = {}) diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index 85600d0407..70b5d20ee6 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -190,7 +190,7 @@ module ProductImport end def staged_import? - @import_settings && @import_settings.key?(:start) && @import_settings.key?(:end) + @import_settings&.key?(:start) && @import_settings.key?(:end) end def init_permissions @@ -224,7 +224,7 @@ module ProductImport end def rows - return [] unless @sheet && @sheet.last_row + return [] unless @sheet&.last_row (2..@sheet.last_row).map do |i| @sheet.row(i) diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb index a7342c9702..bece28a65d 100644 --- a/app/models/proxy_order.rb +++ b/app/models/proxy_order.rb @@ -33,7 +33,7 @@ class ProxyOrder < ActiveRecord::Base transaction do update_column(:canceled_at, Time.zone.now) - order.cancel if order + order&.cancel true end end @@ -43,7 +43,7 @@ class ProxyOrder < ActiveRecord::Base transaction do update_column(:canceled_at, nil) - order.resume if order + order&.resume true end end diff --git a/lib/discourse/single_sign_on.rb b/lib/discourse/single_sign_on.rb index 31d5d06989..658159cce6 100644 --- a/lib/discourse/single_sign_on.rb +++ b/lib/discourse/single_sign_on.rb @@ -92,11 +92,9 @@ module Discourse payload[k] = val end - if @custom_fields - @custom_fields.each do |k, v| + @custom_fields&.each do |k, v| payload["custom.#{k}"] = v.to_s end - end Rack::Utils.build_query(payload) end diff --git a/spec/factories.rb b/spec/factories.rb index d13757cb2a..ad3c804c92 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -44,9 +44,7 @@ FactoryBot.define do subscription order_cycle { subscription.order_cycles.first } before(:create) do |proxy_order, _proxy| - if proxy_order.order - proxy_order.order.update_attribute(:order_cycle_id, proxy_order.order_cycle_id) - end + proxy_order.order&.update_attribute(:order_cycle_id, proxy_order.order_cycle_id) end end