From 394a2b890686cadd7a3ecb0038ce5d0b744431f4 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 6 Jul 2026 04:34:04 +0200 Subject: Strengthen event/occurrence cascade test with real assertions test_can_remove_a_node_with_an_event previously just called node.destroy and get :index with no assertions at all - would pass whether or not occurrences were actually cleaned up, or even if index rendered correctly afterward. Now confirms occurrences genuinely exist before destroy (otherwise a passing post-destroy count of zero is meaningless - indistinguishable from "nothing to cascade in the first place"), scopes the count to this event specifically rather than a global Occurrence.count that could coincidentally pass regardless of whether this cascade works, and checks the trailing index request actually succeeds rather than just not raising. First real test of the occurrences.event_id FK constraint added earlier this session, not just the application-level dependent: :destroy. --- test/controllers/nodes_controller_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/controllers/nodes_controller_test.rb') diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index f14e27c..99e06ae 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -364,7 +364,7 @@ class NodesControllerTest < ActionController::TestCase test "can remove a node with an event" do node = create_node_with_published_page - Event.create!( + event = Event.create!( :start_time => "2009-01-01T15:23:42".to_time, :end_time => "2009-01-01T20:05:23".to_time, :url => "http://events.ccc.de/congress/2082", @@ -373,10 +373,16 @@ class NodesControllerTest < ActionController::TestCase :allday => true, :node_id => node.id ) + event_id = event.id + assert_operator Occurrence.where(event_id: event_id).count, :>, 0, "expected the event to have generated at least one occurrence before destroy" + node.destroy + assert_equal 0, Occurrence.where(event_id: event_id).count + login_as :quentin get :index + assert_response :success end test "show renders events row and add-link for zero-event chapter node" do -- cgit v1.3