From 9018c30e90c5ae173a0018433da25f804216061c Mon Sep 17 00:00:00 2001 From: f Date: Wed, 26 Feb 2020 21:05:59 -0300 Subject: [PATCH] la pirata quizas no esta en la barca closes #13 --- app/controllers/barcas_controller.rb | 2 +- test/controllers/barcas_controller_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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