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

Aperta
#2,939 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rails, ruby
Ambito
backend

Direzione di ricerca

Start with Admin::WorkshopsController, especially workshop_type_valid? and physical_workshop_and_no_host?, then inspect the Workshop model and existing admin workshop controller specs. Move the physical-workshop host rule into Workshop while preserving the host error message, add model specs for the validation, and run the existing controller specs to confirm the flash behaviour remains unchanged.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

refactoring tech debt

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.
Lingua principale
Ruby
Stelle
106
Fork
208
Merge medio
19h 51m
PR unite (30g)
57

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codebar/planner

Tutte le issue di codebar/planner

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.