Browse Source

Fixed failed scheme editing (#716)

Co-authored-by: Stéphane Meny <smeny@users.noreply.github.com>
pull/718/head
J G 3 years ago committed by GitHub
parent
commit
19bb7e98fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/schemes_controller.rb
  2. 6
      app/views/schemes/details.html.erb
  3. 3
      config/locales/en.yml
  4. 2
      spec/requests/schemes_controller_spec.rb

2
app/controllers/schemes_controller.rb

@ -30,7 +30,7 @@ class SchemesController < ApplicationController
render "schemes/primary_client_group" render "schemes/primary_client_group"
else else
@scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:organisation) @scheme.errors.delete(:owning_organisation)
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
end end

6
app/views/schemes/details.html.erb

@ -27,10 +27,10 @@
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %> <% null_option = [OpenStruct.new(id: "", name: "Select an option")] %>
<% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %> <% organisations = Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) } %>
<% stock_org_answer_options = null_option + organisations %> <% managing_org_answer_options = null_option + organisations %>
<%= f.govuk_collection_select :managing_organisation_id, <%= f.govuk_collection_select :managing_organisation_id,
organisations, managing_org_answer_options,
:id, :id,
:name, :name,
label: { text: "Which organisation manages this scheme?", size: "m" }, label: { text: "Which organisation manages this scheme?", size: "m" },
@ -39,7 +39,7 @@
<% if current_user.support? %> <% if current_user.support? %>
<%= f.govuk_collection_select :owning_organisation_id, <%= f.govuk_collection_select :owning_organisation_id,
stock_org_answer_options, organisations,
:id, :id,
:name, :name,
label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" }, label: { text: "Which organisation owns the housing stock for this scheme?", size: "m" },

3
config/locales/en.yml

@ -43,8 +43,9 @@ en:
models: models:
scheme: scheme:
attributes: attributes:
owning_organisation: owning_organisation_id:
required: "Enter the existing organisation’s name" required: "Enter the existing organisation’s name"
invalid: "Enter the existing organisation’s name"
validations: validations:
organisation: organisation:

2
spec/requests/schemes_controller_spec.rb

@ -406,7 +406,7 @@ RSpec.describe SchemesController, type: :request do
it "displays the new page with an error message" do it "displays the new page with an error message" do
post "/schemes", params: params post "/schemes", params: params
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation.required")) expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.owning_organisation_id.required"))
end end
end end
end end

Loading…
Cancel
Save