Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Unify Email Validation Across the Application #2464

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Customer < ApplicationRecord
validates :net_payment_term, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
validates :payment_provider, inclusion: {in: PAYMENT_PROVIDERS}, allow_nil: true
validates :timezone, timezone: true, allow_nil: true
validates :email, email: true, if: :email?

def self.ransackable_attributes(_auth_object = nil)
%w[id name external_id email]
Expand Down
7 changes: 0 additions & 7 deletions app/services/customers/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ def create_from_api(organization:, params:)
new_customer = customer.new_record?
shipping_address = params[:shipping_address] ||= {}

unless valid_email?(params[:email])
return result.single_validation_failure!(
field: :email,
error_code: 'invalid_format'
)
end

unless valid_metadata_count?(metadata: params[:metadata])
return result.single_validation_failure!(
field: :metadata,
Expand Down
4 changes: 3 additions & 1 deletion lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# frozen_string_literal: true

# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
require 'annotate'
task :set_annotation_options do
task set_annotation_options: :environment do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
Expand Down
2 changes: 1 addition & 1 deletion spec/services/customers/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
expect(result).not_to be_success
expect(result.error).to be_a(BaseService::ValidationFailure)
expect(result.error.messages.keys).to include(:email)
expect(result.error.messages[:email]).to include('invalid_format')
expect(result.error.messages[:email]).to include('invalid_email_format')
end
end
end
Expand Down