Skip to content

Move the "physical workshop needs a host" validation onto Workshop #2939

Open

Description

@mroderick

Parent: #2938

Problem

Admin::WorkshopsController enforces the rule "a physical workshop must have a host" in the controller (workshop_type_valid? plus physical_workshop_and_no_host?), adding a validation error from the controller:

def workshop_type_valid?
  return true unless physical_workshop_and_no_host?(@workshop)

  @workshop.errors.add(:host, "can't be blank")
  false
end

Validation rules belong on the model so create, update, and any future caller get them for free.

Proposed change

  • Move the rule into a Workshop validation, reusing the controller's intent and error message (host "can't be blank").
  • Delete workshop_type_valid? and physical_workshop_and_no_host? from the controller; the create/update flows keep their existing flash behaviour via @workshop.errors.

Acceptance

  • Creating/updating a physical workshop without a host fails with the same error message as today.
  • Model specs cover the new validation; existing admin workshop 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