Skip to content

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

Closed

Description

@mroderick

Parent: #2938

Problem

Admin::WorkshopsController#destroy encodes the deletion policy in the controller:

WORKSHOP_DELETION_TIME_FRAME_SINCE_CREATION = 4.hours

def workshop_has_no_invitees?
  @workshop.invitations.blank?
end

def workshop_created_within_specific_time_frame?
  Time.zone.now.between?(@workshop.created_at,
                         @workshop.created_at + WORKSHOP_DELETION_TIME_FRAME_SINCE_CREATION)
end

This is a domain policy — "a workshop can be deleted within 4 hours of creation if it has no invitees" — living in HTTP coordination code.

Proposed change

  • Add Workshop#deletable? encapsulating both conditions and the 4-hour constant.
  • #destroy calls it; the controller loses the constant and both helpers.

Acceptance

  • Same behaviour: success/failure flash messages and redirects unchanged.
  • Model specs cover deletable? on both sides of the 4-hour window and with/without invitees; existing controller specs pass.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions