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

Aberta
#2,939 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
78/100
Tipo de issue
Refatoração
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
rails, ruby
Domínio
backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
Linguagem predominante
Ruby
Estrelas
106
Forks
208
Merge médio
19h 51min
PRs com merge (30d)
57

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de codebar/planner

Todas as issues de codebar/planner

Issues semelhantes

Mais issues de Ruby

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.