Skip to content

Commit e8dd85d

Browse files
authored
4523: Fix user info disappearing on validation failure for new org requests (#4779)
1 parent 2877cc2 commit e8dd85d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

app/controllers/admin/organizations_controller.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ def new
4646

4747
def create
4848
@organization = Organization.new(organization_params)
49+
@user = User.new(user_params)
4950

5051
if @organization.save
5152
Organization.seed_items(@organization)
52-
@user = UserInviteService.invite(name: user_params[:name],
53-
email: user_params[:email],
54-
roles: [Role::ORG_USER, Role::ORG_ADMIN],
55-
resource: @organization)
53+
UserInviteService.invite(name: user_params[:name],
54+
email: user_params[:email],
55+
roles: [Role::ORG_USER, Role::ORG_ADMIN],
56+
resource: @organization)
5657
SnapshotEvent.publish(@organization) # need one to start with
5758
redirect_to admin_organizations_path, notice: "Organization added!"
5859
else

spec/requests/admin/organizations_requests_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@
8585
expect(subject).to render_template("new")
8686
expect(flash[:error]).to be_present
8787
end
88+
89+
it "preserves user attributes" do
90+
post admin_organizations_path({ organization: invalid_params })
91+
92+
expect(subject).to render_template("new")
93+
expect(response.body).to include(invalid_params[:user][:name])
94+
expect(response.body).to include(invalid_params[:user][:email])
95+
end
8896
end
8997
end
9098

0 commit comments

Comments
 (0)