Skip to content

Commit

Permalink
Test that the model instance is deleted in the destroy method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattr committed Oct 21, 2024
1 parent 2f415f5 commit 883b206
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ 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"

it "renders successfully" 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

0 comments on commit 883b206

Please sign in to comment.