From 883b206cd9c0815a9c0888467377473940e469ed Mon Sep 17 00:00:00 2001 From: Matt Redmond Date: Wed, 16 Oct 2024 11:04:41 +1030 Subject: [PATCH] Test that the model instance is deleted in the destroy method The generated spec for the destroy method only tests the redirect, not the actual model deletion. To do this, we need to ensure that the model is instantiated before performing the action. --- .../koi/admin_controller/templates/controller_spec.rb.tt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/generators/koi/admin_controller/templates/controller_spec.rb.tt b/lib/generators/koi/admin_controller/templates/controller_spec.rb.tt index 4e152028..a0a2fb01 100644 --- a/lib/generators/koi/admin_controller/templates/controller_spec.rb.tt +++ b/lib/generators/koi/admin_controller/templates/controller_spec.rb.tt @@ -124,6 +124,7 @@ RSpec.describe <%= controller_class_name %>Controller do describe "DELETE /admin/<%= plural_name %>/:id" do let(:action) { delete polymorphic_path([:admin, model]) } + let!(:model) { create(:<%= singular_name %>) } it_behaves_like "requires admin" @@ -131,5 +132,9 @@ RSpec.describe <%= controller_class_name %>Controller do action expect(response).to redirect_to(polymorphic_path([:admin, <%= class_name %>])) end + + it "deletes the <%= singular_name %>" do + expect { action }.to change(<%= class_name %>, :count).by(-1) + end end end