Commit 384a0477 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei

Fixed professional delete method, now it only deactivates

Signed-off-by: Bruno Freitas Tissei's avatarBruno Freitas Tissei <bft15@inf.ufpr.br>
parent 7ce3f503
Pipeline #6657 passed with stage
in 2 minutes and 9 seconds
......@@ -5,12 +5,19 @@ module Api::V1
# GET /professionals
def index
@professionals = Professional.all
render json: @professionals
end
# GET /professionals/1
def show
render json: @professional
if @professional.nil?
render json: {
errors: ["Professional #{params[:id]} does not exist."]
}, status: 400
else
render json: @professional
end
end
# POST /professionals
......@@ -26,19 +33,33 @@ module Api::V1
# PATCH/PUT /professionals/1
def update
if @professional.update(professional_params)
render json: @professional
else
render json: @professional.errors, status: :unprocessable_entity
end
if @professional.nil?
render json: {
errors: ["Professional #{params[:id]} does not exist."]
}, status: 400
else
if @professional.update(professional_params)
render json: @professional
else
render json: @professional.errors, status: :unprocessable_entity
end
end
end
# DELETE /professionals/1
def destroy
@professional.destroy
if @professional.nil?
render json: {
errors: ["Professional #{params[:id]} does not exist."]
}, status: 400
else
@professional.active = false
@professional.save!
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_professional
@professional = Professional.find(params[:id])
......
......@@ -39,6 +39,15 @@ ActiveRecord::Schema.define(version: 20160901141211) do
t.integer "service_place_id", null: false
end
create_table "cities", force: :cascade do |t|
t.string "ibge_code", null: false
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "state_id"
t.index ["state_id"], name: "index_cities_on_state_id", using: :btree
end
create_table "citizens", force: :cascade do |t|
t.date "birth_date"
t.string "name"
......@@ -128,5 +137,14 @@ ActiveRecord::Schema.define(version: 20160901141211) do
t.index ["city_hall_id"], name: "index_service_places_on_city_hall_id", using: :btree
end
create_table "states", force: :cascade do |t|
t.string "abbreviation", limit: 2, null: false
t.string "ibge_code", null: false
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "cities", "states"
add_foreign_key "citizens", "accounts"
end
......@@ -55,6 +55,8 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
describe "Successful request to delete professional" do
before do
@number_of_professionals = Professional.all_active.count
delete '/v1/professionals/' + @professional.id.to_s, params: {},
headers: @auth_headers
......@@ -69,7 +71,11 @@ class Api::V1::ProfessionalsControllerTest < ActionDispatch::IntegrationTest
end
it "should have been deleted" do
assert_nil Professional.where(id: @professional.id).first
assert_not Professional.where(id: @professional.id).first.active
end
test "number of active professional should be decreased" do
assert_equal @number_of_professionals, Professional.all_active.count + 1
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment