diff --git a/app/models/collection/workflowing.rb b/app/models/collection/workflowing.rb index 0793f804f..658087fe2 100644 --- a/app/models/collection/workflowing.rb +++ b/app/models/collection/workflowing.rb @@ -13,6 +13,6 @@ module Collection::Workflowing private def set_all_cards_to_initial_workflow_stage - cards.update_all(stage_id: initial_workflow_stage.id) + cards.update_all(stage_id: initial_workflow_stage&.id) end end diff --git a/test/models/collection/workflowing_test.rb b/test/models/collection/workflowing_test.rb index ec12bbc9d..c43cda6ed 100644 --- a/test/models/collection/workflowing_test.rb +++ b/test/models/collection/workflowing_test.rb @@ -5,4 +5,9 @@ class Collection::WorkflowingTest < ActiveSupport::TestCase collections(:writebook).update! workflow: workflows(:on_call) assert_equal [ collections(:writebook).initial_workflow_stage ], collections(:writebook).cards.reload.collect(&:stage).uniq end + + test "remove stage from cards if workflow is removed" do + collections(:writebook).update! workflow: nil + assert_equal [], collections(:writebook).cards.reload.collect(&:stage).compact + end end