mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Simplify customer code
The API endpoint merges the created_manually flag in the params already. No need to write it separately.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user