File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ def update
3131 format . html { render :show }
3232 end
3333 end
34+ rescue ActiveRecord ::RecordNotUnique => e
35+ redirect_to thank_you_petition_sponsor_url ( @petition , token : @petition . sponsor_token )
3436 end
3537
3638 def thank_you
Original file line number Diff line number Diff line change @@ -477,6 +477,7 @@ def do_post(options = {})
477477
478478 context "when a race condition occurs" do
479479 let ( :exception ) { ActiveRecord ::RecordNotUnique . new ( "PG::UniqueViolation" ) }
480+
480481 before do
481482 FactoryGirl . create ( :validated_signature , signature_params . merge ( petition_id : petition . id ) )
482483 allow_any_instance_of ( Signature ) . to receive ( :save ) . and_raise ( exception )
Original file line number Diff line number Diff line change @@ -284,6 +284,20 @@ def do_patch(options = {})
284284 expect ( assigns [ :stage_manager ] . stage ) . to eq 'signer'
285285 end
286286 end
287+
288+ context "when a race condition occurs" do
289+ let ( :exception ) { ActiveRecord ::RecordNotUnique . new ( "PG::UniqueViolation" ) }
290+
291+ before do
292+ FactoryGirl . create ( :sponsor , :validated , petition : petition )
293+ allow_any_instance_of ( Signature ) . to receive ( :save ) . and_raise ( exception )
294+ end
295+
296+ it "redirects to the thank you page" do
297+ do_patch
298+ expect ( response ) . to redirect_to ( "https://petition.parliament.uk/petitions/#{ petition . id } /sponsors/#{ petition . sponsor_token } /thank-you" )
299+ end
300+ end
287301 end
288302
289303 context 'GET thank-you' do
You can’t perform that action at this time.
0 commit comments