Skip to content

Commit

Permalink
Simplify customer code
Browse files Browse the repository at this point in the history
The API endpoint merges the created_manually flag in the params already.
No need to write it separately.
  • Loading branch information
mkllnk committed Jun 15, 2023
1 parent a655d3d commit 75cce8b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
1 change: 0 additions & 1 deletion app/controllers/api/v1/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def create
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
Expand Down
7 changes: 0 additions & 7 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ def full_name
"#{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
Expand Down
3 changes: 3 additions & 0 deletions spec/requests/api/v1/customers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@
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

Expand Down

0 comments on commit 75cce8b

Please sign in to comment.