Skip to content

Commit

Permalink
Merge pull request #6 from fabianoflorentino/development
Browse files Browse the repository at this point in the history
Development to Main
  • Loading branch information
fabianoflorentino authored Mar 3, 2024
2 parents eaf42db + 5e68c69 commit 5e79002
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def create
render json: { message: 'Customer created!' }, status: :created
end

def destroy
customer.destroy!

render json: { message: 'Customer deleted!' }, status: :ok
end

private

def customers
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# root "posts#index"

# Define a resource route for customers
resources :customers, only: %i[index show create] do
resources :customers, only: %i[index show create destroy] do
resources :transactions, only: %i[create]
end
end
27 changes: 27 additions & 0 deletions spec/requests/customer/destroy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'DELETE - /customer' do
let(:customer) { create(:customer) }
let(:url) { '/customers' }

describe 'DELETE /customers/:id' do
context 'when the customer exists' do
it 'deletes the customer' do
delete("#{url}/#{customer.id}")

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include('message' => 'Customer deleted!')
end
end

context 'when the customer does not exist' do
it 'returns 404' do
delete("#{url}/0")

expect(response).to have_http_status(:not_found)
end
end
end
end

0 comments on commit 5e79002

Please sign in to comment.