From a5f94ba38b2cd557640aafd9384d01a07b59b4c9 Mon Sep 17 00:00:00 2001 From: Petr Gazarov Date: Sat, 13 Aug 2016 16:34:02 -0400 Subject: [PATCH] Add specs for required option when not using browser validations --- test/inputs/required_test.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/inputs/required_test.rb b/test/inputs/required_test.rb index 11c784d6..ae187bac 100644 --- a/test/inputs/required_test.rb +++ b/test/inputs/required_test.rb @@ -34,6 +34,38 @@ class RequiredTest < ActionView::TestCase with_input_for @user, :name, :string assert_select 'input[type=text].required' assert_no_select 'input[type=text][required]' + assert_no_select 'input[type=text][aria-required]' + end + end + + test 'when not using browser validations, when required option is set to false, input does not generate required html attribute' do + swap SimpleForm, browser_validations: false do + with_input_for @user, :name, :string, required: false + assert_no_select 'input[type=text].required' + assert_no_select 'input[type=text][required]' + assert_no_select 'input[type=text][aria-required]' + end + end + + test 'when not using browser validations, when required option is set to true, input generates required html attribute' do + swap SimpleForm, browser_validations: false do + with_input_for @user, :name, :string, required: true + assert_select 'input[type=text].required' + assert_select 'input[type=text][required]' + assert_select 'input[type=text][aria-required]' + end + end + + test 'when not using browser validations, when required option is true in the wrapper, input does not generate required html attribute' do + swap SimpleForm, browser_validations: false do + swap_wrapper :default, self.custom_wrapper_with_required_input do + with_concat_form_for(@user) do |f| + concat f.input :name + end + assert_select 'input[type=text].required' + assert_no_select 'input[type=text][required]' + assert_no_select 'input[type=text][aria-required]' + end end end