Skip to content

refactor(workshops): move the deletion policy into Workshop#deletable? - #2957

Merged
mroderick merged 2 commits into
codebar:masterfrom
costajohnt:refactor/2940-workshop-deletable
Sep 28, 2026
Merged

mroderick merged 2 commits into
codebar:masterfrom
costajohnt:refactor/2940-workshop-deletable

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Closes #2940

Moves the workshop deletion policy out of Admin::WorkshopsController and into the model: Workshop::DELETION_WINDOW (4 hours) and Workshop#deletable?, which is true while the workshop is within that window of created_at and has no invitations. #destroy now calls @workshop.deletable?; the controller constant and its two private helpers are gone. The logic is the same two checks, moved as is, so flash messages and redirects are unchanged.

Testing

  • New model specs for #deletable?: just after creation, one minute before the window ends, one minute after it ends, and with an invitation
  • Existing spec/controllers/admin/workshops_controller_spec.rb destroy specs pass (the constant reference now points at Workshop::DELETION_WINDOW)
  • bundle exec rspec spec/models/workshop_spec.rb spec/controllers/admin/workshops_controller_spec.rb: 106 examples, 0 failures; rubocop clean

@mroderick mroderick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified in a worktree of the PR branch:

  • Workshop#deletable? is the old controller logic moved expression for expression, same check order: invitations.blank? && Time.zone.now.between?(created_at, created_at + DELETION_WINDOW). between? stays inclusive at both ends, so behaviour is unchanged.
  • Nothing else references the deleted constant or helpers — the controller specs were the only external consumers and are updated to Workshop::DELETION_WINDOW.
  • New model specs cover both sides of each condition: just after creation, one minute inside the window, one minute outside, and with an invitation.
  • Ran bundle exec rspec spec/models/workshop_spec.rb spec/controllers/admin/workshops_controller_spec.rb: 106 examples, 0 failures. rubocop on both app files: clean.

Non-blocking nit: DELETION_WINDOW sits between resourcify and the has_many block rather than with the other constants at the top of the model — cosmetic only.

@mroderick
mroderick merged commit 77db4ea into codebar:master Sep 28, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Workshop#deletable? and use it in Admin::WorkshopsController#destroy

2 participants