From 2d4326ded3c7544cef4154cc323894090db68d3f Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 30 Jun 2020 19:40:35 +0100 Subject: [PATCH] Replace empty? with blank? which is equivalent but a bit more resilient, returns false for nil Present is not blank, so unless blank? becomes if present? --- app/controllers/admin/enterprises_controller.rb | 2 +- app/controllers/checkout_controller.rb | 2 +- app/controllers/spree/admin/image_settings_controller.rb | 4 ++-- app/controllers/spree/admin/products_controller.rb | 2 +- app/controllers/user_registrations_controller.rb | 2 +- app/serializers/api/admin/enterprise_serializer.rb | 2 +- app/serializers/api/admin/units_variant_serializer.rb | 2 +- app/services/permitted_attributes/enterprise.rb | 2 +- app/services/permitted_attributes/order_cycle.rb | 2 +- app/services/permitted_attributes/subscription.rb | 2 +- .../producer_properties/_producer_property_fields.html.haml | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 333926a728..4277dc2ff4 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -146,7 +146,7 @@ module Admin enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle) .visible_enterprises - unless enterprises.empty? + if enterprises.present? enterprises.includes( supplied_products: [:supplier, master: [:images], variants: { option_values: :option_type }] diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 8616f4f6ad..c83b5e361d 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -241,7 +241,7 @@ class CheckoutController < Spree::StoreController def update_failed(error = RuntimeError.new(order_error)) Bugsnag.notify(error) - flash[:error] = order_error if flash.empty? + flash[:error] = order_error if flash.blank? checkout_failed update_failed_response end diff --git a/app/controllers/spree/admin/image_settings_controller.rb b/app/controllers/spree/admin/image_settings_controller.rb index 32aae5c783..476dd401a8 100644 --- a/app/controllers/spree/admin/image_settings_controller.rb +++ b/app/controllers/spree/admin/image_settings_controller.rb @@ -26,7 +26,7 @@ module Spree def update_styles(params) if params[:new_attachment_styles].present? params[:new_attachment_styles].each do |_index, style| - params[:attachment_styles][style[:name]] = style[:value] unless style[:value].empty? + params[:attachment_styles][style[:name]] = style[:value] if style[:value].present? end end @@ -38,7 +38,7 @@ module Spree def update_headers(params) if params[:new_s3_headers].present? params[:new_s3_headers].each do |_index, header| - params[:s3_headers][header[:name]] = header[:value] unless header[:value].empty? + params[:s3_headers][header[:name]] = header[:value] if header[:value].present? end end diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 707a65b3f1..76f0066d86 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -171,7 +171,7 @@ module Spree end def permitted_resource_params - return params[:product] if params[:product].empty? + return params[:product] if params[:product].blank? params.require(:product).permit(::PermittedAttributes::Product.attributes) end diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index 873d7d4036..d6fdf5ac76 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -33,7 +33,7 @@ class UserRegistrationsController < Spree::UserRegistrationsController private def spree_user_params - return params[:spree_user] if params[:spree_user].empty? + return params[:spree_user] if params[:spree_user].blank? PermittedAttributes::User.new(params, :spree_user).call([:remember_me]) end diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index bcb2fe39d7..e3024fdc46 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -25,7 +25,7 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer tag_group = find_match(tag_groups, tag_rule.preferred_customer_tags. split(","). map{ |t| { text: t } }) - if tag_group[:rules].empty? + if tag_group[:rules].blank? tag_groups << tag_group tag_group[:position] = tag_groups.count end diff --git a/app/serializers/api/admin/units_variant_serializer.rb b/app/serializers/api/admin/units_variant_serializer.rb index dc27e3adc3..f70959b925 100644 --- a/app/serializers/api/admin/units_variant_serializer.rb +++ b/app/serializers/api/admin/units_variant_serializer.rb @@ -3,6 +3,6 @@ class Api::Admin::UnitsVariantSerializer < ActiveModel::Serializer def full_name full_name = object.full_name - object.product.name + (full_name.empty? ? "" : ": #{full_name}") + object.product.name + (full_name.blank? ? "" : ": #{full_name}") end end diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index f02863b2a5..db7f31f10c 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -7,7 +7,7 @@ module PermittedAttributes end def call - return @params[:enterprise] if @params[:enterprise].empty? + return @params[:enterprise] if @params[:enterprise].blank? @params.require(:enterprise).permit( basic_permitted_attributes + [ diff --git a/app/services/permitted_attributes/order_cycle.rb b/app/services/permitted_attributes/order_cycle.rb index 6da6175a51..41fd82bead 100644 --- a/app/services/permitted_attributes/order_cycle.rb +++ b/app/services/permitted_attributes/order_cycle.rb @@ -7,7 +7,7 @@ module PermittedAttributes end def call - return @params[:order_cycle] if @params[:order_cycle].empty? + return @params[:order_cycle] if @params[:order_cycle].blank? @params.require(:order_cycle).permit( :name, :orders_open_at, :orders_close_at, :coordinator_id, diff --git a/app/services/permitted_attributes/subscription.rb b/app/services/permitted_attributes/subscription.rb index 2ab3956fca..21e523e4fe 100644 --- a/app/services/permitted_attributes/subscription.rb +++ b/app/services/permitted_attributes/subscription.rb @@ -7,7 +7,7 @@ module PermittedAttributes end def call - return @params[:subscription] if @params[:subscription].empty? + return @params[:subscription] if @params[:subscription].blank? @params.require(:subscription).permit(basic_permitted_attributes + other_permitted_attributes) end diff --git a/app/views/admin/producer_properties/_producer_property_fields.html.haml b/app/views/admin/producer_properties/_producer_property_fields.html.haml index 6fe0b1d7ad..841a0cfb73 100644 --- a/app/views/admin/producer_properties/_producer_property_fields.html.haml +++ b/app/views/admin/producer_properties/_producer_property_fields.html.haml @@ -11,5 +11,5 @@ %td.value = f.text_field :value, :class => 'autocomplete' %td.actions - - unless @enterprise.producer_properties.empty? + - if @enterprise.producer_properties.present? = link_to_remove_fields t(:remove), f, no_text: true, url: (f.object.persisted? && main_app.admin_enterprise_producer_property_path(@enterprise, f.object)), html: {"onclick" => "if(typeof(enterprise_form) != 'undefined') { angular.element(enterprise_form).scope().setFormDirty() }".html_safe}