From e8dd85d236c93b901a5b75ff51aa06f80785673a Mon Sep 17 00:00:00 2001 From: Cory Streiff <90390502+coalest@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:22:58 +0100 Subject: [PATCH] 4523: Fix user info disappearing on validation failure for new org requests (#4779) --- app/controllers/admin/organizations_controller.rb | 9 +++++---- spec/requests/admin/organizations_requests_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 11313338e7..33ef830d49 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -46,13 +46,14 @@ def new def create @organization = Organization.new(organization_params) + @user = User.new(user_params) if @organization.save Organization.seed_items(@organization) - @user = UserInviteService.invite(name: user_params[:name], - email: user_params[:email], - roles: [Role::ORG_USER, Role::ORG_ADMIN], - resource: @organization) + UserInviteService.invite(name: user_params[:name], + email: user_params[:email], + roles: [Role::ORG_USER, Role::ORG_ADMIN], + resource: @organization) SnapshotEvent.publish(@organization) # need one to start with redirect_to admin_organizations_path, notice: "Organization added!" else diff --git a/spec/requests/admin/organizations_requests_spec.rb b/spec/requests/admin/organizations_requests_spec.rb index 9b0410eb2e..ff49d755c5 100644 --- a/spec/requests/admin/organizations_requests_spec.rb +++ b/spec/requests/admin/organizations_requests_spec.rb @@ -85,6 +85,14 @@ expect(subject).to render_template("new") expect(flash[:error]).to be_present end + + it "preserves user attributes" do + post admin_organizations_path({ organization: invalid_params }) + + expect(subject).to render_template("new") + expect(response.body).to include(invalid_params[:user][:name]) + expect(response.body).to include(invalid_params[:user][:email]) + end end end