From 140f11ecc6e31ac782a6510a56407c7cdc947f2c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 5 Mar 2024 10:47:59 +0100 Subject: [PATCH] Ensure route_to action works if code is blank string --- lib/custom_wizard/action.rb | 2 +- spec/components/custom_wizard/action_spec.rb | 22 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index ac0799f3..d3109a22 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -425,7 +425,7 @@ class CustomWizard::Action ).perform end - if action['code'] + if action['code'].present? @submission.fields[action['code']] = SecureRandom.hex(8) url += "&#{action['code']}=#{@submission.fields[action['code']]}" end diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index fb34ea03..53276289 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -212,11 +212,23 @@ describe CustomWizard::Action do end end - it 're-routes a user' do - wizard = CustomWizard::Builder.new(@template[:id], user).build - updater = wizard.create_updater(wizard.steps.last.id, {}) - updater.update - expect(updater.result[:redirect_on_next]).to eq("https://google.com") + context "route to action" do + it 're-routes a user' do + wizard = CustomWizard::Builder.new(@template[:id], user).build + updater = wizard.create_updater(wizard.steps.last.id, {}) + updater.update + expect(updater.result[:redirect_on_next]).to eq("https://google.com") + end + + it "works if the code field has a blank string" do + wizard_template[:actions].last[:code] = " " + update_template(wizard_template) + + wizard = CustomWizard::Builder.new(@template[:id], user).build + updater = wizard.create_updater(wizard.steps.last.id, {}) + updater.update + expect(updater.result[:redirect_on_next]).to eq("https://google.com") + end end context "standard subscription actions" do