Browse Source

validate all the required scheme questions are answered

pull/775/head
Kat 3 years ago
parent
commit
2bbecb0b9e
  1. 2
      app/controllers/schemes_controller.rb
  2. 10
      app/models/scheme.rb
  3. 8
      app/views/schemes/check_answers.html.erb
  4. 1
      spec/factories/scheme.rb

2
app/controllers/schemes_controller.rb

@ -128,6 +128,8 @@ private
"schemes/details" "schemes/details"
elsif page.include?("edit") elsif page.include?("edit")
"schemes/edit_name" "schemes/edit_name"
elsif page.include?("check-answers")
"schemes/check_answers"
end end
end end

10
app/models/scheme.rb

@ -9,6 +9,8 @@ class Scheme < ApplicationRecord
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct }
validate :validate_confirmed
SENSITIVE = { SENSITIVE = {
No: 0, No: 0,
Yes: 1, Yes: 1,
@ -205,4 +207,12 @@ class Scheme < ApplicationRecord
def arrangement_type_same? def arrangement_type_same?
arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D" arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D"
end end
def validate_confirmed
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group]
if confirmed == true && required_attributes.any? { |attribute| self[attribute].blank? }
errors.add :base, "Please answer all the required questions"
end
end
end end

8
app/views/schemes/check_answers.html.erb

@ -1,7 +1,9 @@
<% content_for :title, "Check your answers before creating this scheme" %> <% content_for :title, "Check your answers before creating this scheme" %>
<%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %> <%= render partial: "organisations/headings", locals: { main: "Check your changes before creating this scheme", sub: @scheme.service_name } %>
<div class="govuk-grid-row"> <%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
<%= f.govuk_error_summary %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters-from-desktop"> <div class="govuk-grid-column-three-quarters-from-desktop">
<%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %> <%= govuk_tabs(title: "Check your answers before creating this scheme") do |component| %>
<% component.tab(label: "Scheme") do %> <% component.tab(label: "Scheme") do %>
@ -129,9 +131,7 @@
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<%= form_for(@scheme, as: :scheme, method: :patch) do |f| %>
<%= f.hidden_field :page, value: "check-answers" %> <%= f.hidden_field :page, value: "check-answers" %>
<%= f.hidden_field :confirmed, value: "true" %> <%= f.hidden_field :confirmed, value: "true" %>
<% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %> <% button_label = @scheme.confirmed? ? "Save" : "Create scheme" %>

1
spec/factories/scheme.rb

@ -10,6 +10,7 @@ FactoryBot.define do
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample } secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
owning_organisation { FactoryBot.create(:organisation) } owning_organisation { FactoryBot.create(:organisation) }
managing_organisation { FactoryBot.create(:organisation) }
confirmed { true } confirmed { true }
created_at { Time.zone.now } created_at { Time.zone.now }
trait :export do trait :export do

Loading…
Cancel
Save