From 1f1c911439f3387d02fe3d89eefa55c8a16126a4 Mon Sep 17 00:00:00 2001 From: OrbitalOwen <44505297+OrbitalOwen@users.noreply.github.com> Date: Wed, 11 Nov 2020 15:24:58 +0000 Subject: [PATCH 1/2] Add composer to valid text fields for min length option --- lib/custom_wizard/builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index 66d2f5df..9ac4bb73 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -333,7 +333,7 @@ class CustomWizard::Builder end def is_text_type(field) - ['text', 'textarea'].include? field['type'] + ['text', 'textarea', 'composer'].include? field['type'] end def is_url_type(field) From 5a7d8ea3551f05ac455276899adf1de70ccb23c9 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 13 Nov 2020 11:39:59 +1100 Subject: [PATCH 2/2] Add spec to ensure min_length applied to all text fields --- spec/components/custom_wizard/builder_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index 699f5ce9..dd3b110f 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -318,11 +318,26 @@ describe CustomWizard::Builder do end context 'validation' do - it 'applies min length' do + it 'applies min length to fields that support min length' do + min_length = 3 + + @template[:steps][0][:fields][0][:min_length] = min_length + @template[:steps][0][:fields][1][:min_length] = min_length + @template[:steps][0][:fields][2][:min_length] = min_length + CustomWizard::Template.save(@template.as_json) + expect( perform_update('step_1', step_1_field_1: 'Te') .errors.messages[:step_1_field_1].first - ).to eq(I18n.t('wizard.field.too_short', label: 'Text', min: 3)) + ).to eq(I18n.t('wizard.field.too_short', label: 'Text', min: min_length)) + expect( + perform_update('step_1', step_1_field_2: 'Te') + .errors.messages[:step_1_field_2].first + ).to eq(I18n.t('wizard.field.too_short', label: 'Textarea', min: min_length)) + expect( + perform_update('step_1', step_1_field_3: 'Te') + .errors.messages[:step_1_field_3].first + ).to eq(I18n.t('wizard.field.too_short', label: 'Composer', min: min_length)) end it 'standardises boolean entries' do