From 75cce8bc19b07ec9d8ad977fb43ed01e43285ed7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 15 Jun 2023 11:42:32 +1000 Subject: [PATCH] Simplify customer code The API endpoint merges the created_manually flag in the params already. No need to write it separately. --- app/controllers/api/v1/customers_controller.rb | 1 - app/models/customer.rb | 7 ------- spec/requests/api/v1/customers_spec.rb | 3 +++ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index 70bc7936e9..772ed1bb92 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -31,7 +31,6 @@ module Api authorize! :update, Enterprise.find(customer_params[:enterprise_id]) customer = Customer.find_or_new(customer_params[:email], customer_params[:enterprise_id]) customer.assign_attributes(customer_params) - customer.set_created_manually_flag if customer.save render json: Api::V1::CustomerSerializer.new(customer), status: :created diff --git a/app/models/customer.rb b/app/models/customer.rb index 8e65246265..effeae83c4 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -54,13 +54,6 @@ class Customer < ApplicationRecord "#{first_name} #{last_name}".strip end - def set_created_manually_flag - self.created_manually = true - return unless persisted? - - update_attribute(:created_manually, true) - end - private def downcase_email diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index 542d10f9b8..2f12c59e4c 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -190,6 +190,9 @@ describe "Customers", type: :request do allow_charges: false, terms_and_conditions_accepted_at: nil, ) + + customer = Customer.find(json_response[:data][:attributes][:id]) + expect(customer.created_manually).to eq true end end