From cc4ff102fde08a95f2e55d033393ebc7153e74f5 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Wed, 24 Apr 2024 14:14:21 +0100 Subject: [PATCH] alter redirect after support user creates an organisation --- app/controllers/organisations_controller.rb | 11 ++++++----- app/views/organisations/new.html.erb | 4 ++-- config/locales/en.yml | 1 + spec/requests/organisations_controller_spec.rb | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 486489cbe..5689d6ab6 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -73,19 +73,20 @@ class OrganisationsController < ApplicationController end def new - @resource = Organisation.new + @organisation = Organisation.new @rent_periods = helpers.rent_periods_with_checked_attr render "new", layout: "application" end def create selected_rent_periods = params.require(:organisation).permit(rent_periods: [])[:rent_periods].compact_blank - @resource = Organisation.new(org_params) - if @resource.save + @organisation = Organisation.new(org_params) + if @organisation.save OrganisationRentPeriod.transaction do - selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @resource, rent_period: period) } + selected_rent_periods.each { |period| OrganisationRentPeriod.create!(organisation: @organisation, rent_period: period) } end - redirect_to organisations_path + flash[:notice] = I18n.t("organisation.created", organisation: @organisation.name) + redirect_to organisation_path @organisation else @rent_periods = helpers.rent_periods_with_checked_attr(checked_periods: selected_rent_periods) render :new, status: :unprocessable_entity diff --git a/app/views/organisations/new.html.erb b/app/views/organisations/new.html.erb index cb62157df..cf58a5de9 100644 --- a/app/views/organisations/new.html.erb +++ b/app/views/organisations/new.html.erb @@ -4,7 +4,7 @@ <%= govuk_back_link(href: :back) %> <% end %> -<%= form_for(@resource, as: :organisation, html: { method: :post }) do |f| %> +<%= form_for(@organisation, as: :organisation, html: { method: :post }) do |f| %>
<%= f.govuk_error_summary %> @@ -48,7 +48,7 @@ :id, :name, label: { text: "Organisation type", size: "m" }, - options: { disabled: [""], selected: @resource.provider_type || "" } %> + options: { disabled: [""], selected: @organisation.provider_type || "" } %> <%= f.govuk_collection_radio_buttons :holds_own_stock, [OpenStruct.new(id: true, name: "Yes"), OpenStruct.new(id: false, name: "No")], diff --git a/config/locales/en.yml b/config/locales/en.yml index 941c12c52..63b159b32 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -33,6 +33,7 @@ en: service_name: "Submit social housing lettings and sales data (CORE)" feedback_form: "https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u" organisation: + created: "%{organisation} was created" updated: "Organisation details updated" reactivated: "%{organisation} has been reactivated." deactivated: "%{organisation} has been deactivated." diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index bed20ae15..00d8cb125 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1569,7 +1569,8 @@ RSpec.describe OrganisationsController, type: :request do it "redirects to the organisation list" do request - expect(response).to redirect_to("/organisations") + organisation = Organisation.find_by(housing_registration_no:) + expect(response).to redirect_to organisation_path(organisation) end context "when required params are missing" do