diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 04:34:04 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-06 04:34:04 +0200 |
| commit | 394a2b890686cadd7a3ecb0038ce5d0b744431f4 (patch) | |
| tree | c09550efe2acb64bf7e79c9a8b0e5f4724abfe7e | |
| parent | 970f10854bccee0528de8435e5a65cdcc18ba93e (diff) | |
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.
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 8 |
1 files changed, 7 insertions, 1 deletions
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 | |||
| 364 | 364 | ||
| 365 | test "can remove a node with an event" do | 365 | test "can remove a node with an event" do |
| 366 | node = create_node_with_published_page | 366 | node = create_node_with_published_page |
| 367 | Event.create!( | 367 | event = Event.create!( |
| 368 | :start_time => "2009-01-01T15:23:42".to_time, | 368 | :start_time => "2009-01-01T15:23:42".to_time, |
| 369 | :end_time => "2009-01-01T20:05:23".to_time, | 369 | :end_time => "2009-01-01T20:05:23".to_time, |
| 370 | :url => "http://events.ccc.de/congress/2082", | 370 | :url => "http://events.ccc.de/congress/2082", |
| @@ -373,10 +373,16 @@ class NodesControllerTest < ActionController::TestCase | |||
| 373 | :allday => true, | 373 | :allday => true, |
| 374 | :node_id => node.id | 374 | :node_id => node.id |
| 375 | ) | 375 | ) |
| 376 | event_id = event.id | ||
| 377 | assert_operator Occurrence.where(event_id: event_id).count, :>, 0, "expected the event to have generated at least one occurrence before destroy" | ||
| 378 | |||
| 376 | node.destroy | 379 | node.destroy |
| 377 | 380 | ||
| 381 | assert_equal 0, Occurrence.where(event_id: event_id).count | ||
| 382 | |||
| 378 | login_as :quentin | 383 | login_as :quentin |
| 379 | get :index | 384 | get :index |
| 385 | assert_response :success | ||
| 380 | end | 386 | end |
| 381 | 387 | ||
| 382 | test "show renders events row and add-link for zero-event chapter node" do | 388 | test "show renders events row and add-link for zero-event chapter node" do |
