Skip to content

Commit

Permalink
destroy enquiry server-side working. #39
Browse files Browse the repository at this point in the history
  • Loading branch information
jollopre committed Sep 14, 2018
1 parent 5f13b2f commit c33cfb2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions server/app/controllers/enquiries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ def export
render json: { detail: e.message }, status: :not_found
end
end
def destroy
id = params[:id]
Enquiry.destroy(id)
head(:ok)
rescue ActiveRecord::RecordNotFound => e
render(json: { detail: e.message }, status: :not_found)
end
end
2 changes: 1 addition & 1 deletion server/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

# enquiries actions that do not need hierarchy
resources :enquiries, only: [:show, :update] do
resources :enquiries, only: [:show, :update, :destroy] do
get 'export', on: :member
end

Expand Down
41 changes: 41 additions & 0 deletions server/spec/requests/enquiries_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rails_helper'

RSpec.describe EnquiriesController do
fixtures :users
fixtures :enquiries

describe '#index' do
pending
end

describe '#create' do
pending
end

describe '#show' do
pending
end

describe '#update' do
pending
end

describe '#export' do
pending
end

describe '#delete' do
it 'returns 404 when the enquiries does not exist' do
delete enquiry_path('INVALID'), headers: auth_header(users(:user1))

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

it 'returns 200 when the enquiry exists' do
enquiry = enquiries(:enquiry1)
delete enquiry_path(enquiry), headers: auth_header(users(:user1))

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

0 comments on commit c33cfb2

Please sign in to comment.