Skip to content

Commit 9a98627

Browse files
authored
5036 catch partner user create errors (#5139)
* Add spec * Catch erro and redirect to partner users path * Update the it string * Fix spec
1 parent 1386046 commit 9a98627

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/controllers/partner_users_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def create
2424
@users = @partner.users
2525
render :index
2626
end
27+
rescue => e
28+
flash[:error] = e.message
29+
redirect_to partner_users_path(@partner)
2730
end
2831

2932
def destroy

spec/requests/partner_users_requests_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@
7070
expect(flash[:alert]).to eq("Invitation failed. Check the form for errors.")
7171
end
7272
end
73+
74+
context "with existing user params" do
75+
it "renders the index template with error" do
76+
expect {
77+
post partner_users_path(default_params.merge(partner_id: partner)), params: {user: {email: partner.email}}
78+
}.not_to change(User, :count)
79+
80+
expect(response).to redirect_to(partner_users_path)
81+
expect(flash[:error]).to eq("User already has the requested role!")
82+
end
83+
end
7384
end
7485

7586
context "while signed in as org user" do

0 commit comments

Comments
 (0)