Back to Source Monitor

Source Deletion Fix

.vbw-planning/milestones/polish-and-reliability/phases/04-bug-fixes-and-polish/PLAN-02-SUMMARY.md

0.13.0847 B
Original Source

Fixed 500 error when deleting sources by adding proper error handling for FK constraint violations from host app model extensions.

What Was Built

  • Wrapped @source.destroy in begin/rescue with ActiveRecord::InvalidForeignKey catch
  • Added handle_destroy_failure private method supporting both turbo_stream (error toast) and html (flash alert) responses
  • FK violations now produce a user-friendly "Cannot delete — other records still reference this source" message instead of a 500 error
  • Added 6 new tests covering successful deletion, FK violation handling, and both response formats

Files Modified

  • app/controllers/source_monitor/sources_controller.rb -- wrapped destroy in error handling, added handle_destroy_failure method
  • test/controllers/source_monitor/sources_controller_test.rb -- added 6 destroy action tests