File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,8 @@ def handle_new_signature(petition)
149149 format . html { render :new }
150150 end
151151 end
152+ rescue ActiveRecord ::RecordNotUnique => e
153+ redirect_to thank_you_petition_signatures_url ( petition )
152154 end
153155
154156 def validate_sponsor
Original file line number Diff line number Diff line change @@ -430,6 +430,19 @@ def do_post(options = {})
430430 expect ( response ) . to render_template ( :new )
431431 end
432432 end
433+
434+ context "when a race condition occurs" do
435+ let ( :exception ) { ActiveRecord ::RecordNotUnique . new ( "PG::UniqueViolation" ) }
436+ before do
437+ FactoryGirl . create ( :validated_signature , signature_params . merge ( petition_id : petition . id ) )
438+ allow_any_instance_of ( Signature ) . to receive ( :save ) . and_raise ( exception )
439+ end
440+
441+ it "redirects to the thank you page" do
442+ do_post ( stage : 'done' )
443+ expect ( response ) . to redirect_to ( "https://petition.parliament.uk/petitions/#{ petition . id } /signatures/thank-you" )
444+ end
445+ end
433446 end
434447
435448 context "when the petition is closed" do
You can’t perform that action at this time.
0 commit comments