From 8bab13a6ceb56ecde3afede5abfd76ca9214d6a9 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 4 Jan 2021 11:16:43 +0100 Subject: [PATCH] Be consistent with method names checking if a field is required Across the repo the `_required?` format is the most common. --- core/app/models/spree/order.rb | 9 +++++++-- core/spec/models/spree/order/validations_spec.rb | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 4443f97f9e8..0291c981229 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -128,7 +128,7 @@ def states before_create :create_token before_create :link_by_email - validates :email, presence: true, if: :require_email + validates :email, presence: true, if: :email_required? validates :email, 'spree/email' => true, allow_blank: true validates :guest_token, presence: { allow_nil: true } validates :number, presence: true, uniqueness: { allow_blank: true, case_sensitive: true } @@ -750,10 +750,15 @@ def link_by_email end # Determine if email is required (we don't want validation errors before we hit the checkout) - def require_email + def email_required? true unless new_record? || ['cart', 'address'].include?(state) end + def require_email + Spree::Deprecation.warn "Use email_required? instead", caller(1) + email_required? + end + def ensure_inventory_units if has_checkout_step?("delivery") inventory_validator = Spree::Stock::InventoryValidator.new diff --git a/core/spec/models/spree/order/validations_spec.rb b/core/spec/models/spree/order/validations_spec.rb index d88292fd477..4920077f49b 100644 --- a/core/spec/models/spree/order/validations_spec.rb +++ b/core/spec/models/spree/order/validations_spec.rb @@ -8,7 +8,7 @@ module Spree # Regression test for https://github.com/spree/spree/issues/2214 it "does not return two error messages when email is blank" do order = Spree::Order.new - allow(order).to receive_messages(require_email: true) + allow(order).to receive_messages(email_required?: true) order.valid? expect(order.errors[:email]).to eq(["can't be blank"]) end