diff --git a/app/controllers/barcas_controller.rb b/app/controllers/barcas_controller.rb index 4471e8b..95b60a4 100644 --- a/app/controllers/barcas_controller.rb +++ b/app/controllers/barcas_controller.rb @@ -117,7 +117,7 @@ class BarcasController < ApplicationController def abandonar find_barca - if @barca.tripulaciones.find_by(pirata: current_pirata).destroy + if @barca.tripulaciones.find_by(pirata: current_pirata).try :destroy notify(subject: :abandonar, urgency: :'very-low', ttl: 1.day) render status: :no_content else diff --git a/test/controllers/barcas_controller_test.rb b/test/controllers/barcas_controller_test.rb index 9f0b03f..d02ef2d 100644 --- a/test/controllers/barcas_controller_test.rb +++ b/test/controllers/barcas_controller_test.rb @@ -94,6 +94,14 @@ class BarcasControllerTest < ActionDispatch::IntegrationTest assert_not barca.reload.piratas.include?(@pirata) end + test 'no se pueden abandonar si no estan abordadas' do + barca = create :barca + + delete barca_abandonar_url(barca), as: :json, headers: @auth + + assert_response :unprocessable_entity + end + test 'se pueden abordar' do barca = create :barca