From 44703499e30b62baabb4301fe7c62e394773281c Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 10 Nov 2021 14:29:31 +0000 Subject: [PATCH] Fixes #3845 - Removing calendars via UI and API does not check for references. --- app/controllers/calendars_controller.rb | 1 + spec/requests/calendar_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 0092cdf53..38863730a 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -38,6 +38,7 @@ class CalendarsController < ApplicationController end def destroy + model_references_check(Calendar, params) model_destroy_render(Calendar, params) end diff --git a/spec/requests/calendar_spec.rb b/spec/requests/calendar_spec.rb index 023ae25d3..64c538de0 100644 --- a/spec/requests/calendar_spec.rb +++ b/spec/requests/calendar_spec.rb @@ -76,4 +76,18 @@ RSpec.describe 'Calendars', type: :request do end end + describe 'Removing calendars via UI and API does not check for references #3845', authenticated_as: -> { user } do + let(:calendar) { create(:calendar) } + let(:sla) { create(:sla, calendar: calendar) } + let(:user) { create(:admin) } + + before do + sla + end + + it 'does return reference error on delete if related objects exist' do + delete "/api/v1/calendars/#{calendar.id}", params: {}, as: :json + expect(json_response['error']).to eq("Can't delete, object has references.") + end + end end