simple_form 3.1.0.rc1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +64 -16
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +9 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -15
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
- data/lib/simple_form/components/errors.rb +3 -5
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +34 -19
- data/lib/simple_form/inputs/boolean_input.rb +8 -5
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/tags.rb +3 -4
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +2 -2
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form.rb +21 -2
- data/test/action_view_extensions/builder_test.rb +34 -34
- data/test/action_view_extensions/form_helper_test.rb +33 -14
- data/test/components/label_test.rb +36 -36
- data/test/form_builder/association_test.rb +41 -41
- data/test/form_builder/button_test.rb +10 -10
- data/test/form_builder/error_test.rb +88 -29
- data/test/form_builder/general_test.rb +89 -64
- data/test/form_builder/hint_test.rb +18 -18
- data/test/form_builder/input_field_test.rb +59 -19
- data/test/form_builder/label_test.rb +23 -14
- data/test/form_builder/wrapper_test.rb +70 -21
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +17 -9
- data/test/inputs/collection_check_boxes_input_test.rb +46 -7
- data/test/inputs/collection_radio_buttons_input_test.rb +65 -26
- data/test/inputs/collection_select_input_test.rb +62 -62
- data/test/inputs/datetime_input_test.rb +24 -24
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +44 -5
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +10 -10
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +43 -43
- data/test/inputs/priority_input_test.rb +13 -13
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +33 -33
- data/test/inputs/text_input_test.rb +7 -7
- data/test/support/discovery_inputs.rb +20 -0
- data/test/support/misc_helpers.rb +28 -0
- data/test/support/models.rb +13 -2
- data/test/test_helper.rb +5 -1
- metadata +4 -4
|
@@ -2,46 +2,46 @@
|
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
4
|
class PriorityInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
5
|
+
test 'input generates a country select field' do
|
|
6
6
|
with_input_for @user, :country, :country
|
|
7
7
|
assert_select 'select#user_country'
|
|
8
8
|
assert_select 'select option[value=Brazil]', 'Brazil'
|
|
9
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
|
9
|
+
assert_no_select 'select option[value=""][disabled=disabled]'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
test 'input
|
|
12
|
+
test 'input generates a country select with SimpleForm default' do
|
|
13
13
|
swap SimpleForm, country_priority: [ 'Brazil' ] do
|
|
14
14
|
with_input_for @user, :country, :country
|
|
15
|
-
assert_select 'select option[value=][disabled=disabled]'
|
|
15
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
test 'input
|
|
19
|
+
test 'input generates a time zone select field' do
|
|
20
20
|
with_input_for @user, :time_zone, :time_zone
|
|
21
21
|
assert_select 'select#user_time_zone'
|
|
22
22
|
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
|
23
|
-
assert_no_select 'select option[value=][disabled=disabled]'
|
|
23
|
+
assert_no_select 'select option[value=""][disabled=disabled]'
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
test 'input
|
|
26
|
+
test 'input generates a time zone select field with default' do
|
|
27
27
|
with_input_for @user, :time_zone, :time_zone, default: 'Brasilia'
|
|
28
28
|
assert_select 'select option[value=Brasilia][selected=selected]'
|
|
29
|
-
assert_no_select 'select option[value=]'
|
|
29
|
+
assert_no_select 'select option[value=""]'
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
test 'input
|
|
32
|
+
test 'input generates a time zone select using options priority' do
|
|
33
33
|
with_input_for @user, :time_zone, :time_zone, priority: /Brasilia/
|
|
34
|
-
assert_select 'select option[value=][disabled=disabled]'
|
|
35
|
-
assert_no_select 'select option[value=]', /^$/
|
|
34
|
+
assert_select 'select option[value=""][disabled=disabled]'
|
|
35
|
+
assert_no_select 'select option[value=""]', /^$/
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
test 'priority input
|
|
38
|
+
test 'priority input does not generate invalid required html attribute' do
|
|
39
39
|
with_input_for @user, :country, :country
|
|
40
40
|
assert_select 'select.required'
|
|
41
41
|
assert_no_select 'select[required]'
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
test 'priority input
|
|
44
|
+
test 'priority input does not generate invalid aria-required html attribute' do
|
|
45
45
|
with_input_for @user, :country, :country
|
|
46
46
|
assert_select 'select.required'
|
|
47
47
|
assert_no_select 'select[aria-required]'
|
|
@@ -1,98 +1,98 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
3
|
class ReadonlyTest < ActionView::TestCase
|
|
4
|
-
test 'string input
|
|
4
|
+
test 'string input generates readonly elements when readonly option is true' do
|
|
5
5
|
with_input_for @user, :name, :string, readonly: true
|
|
6
6
|
assert_select 'input.string.readonly[readonly]'
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
test 'text input
|
|
9
|
+
test 'text input generates readonly elements when readonly option is true' do
|
|
10
10
|
with_input_for @user, :description, :text, readonly: true
|
|
11
11
|
assert_select 'textarea.text.readonly[readonly]'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
test 'numeric input
|
|
14
|
+
test 'numeric input generates readonly elements when readonly option is true' do
|
|
15
15
|
with_input_for @user, :age, :integer, readonly: true
|
|
16
16
|
assert_select 'input.integer.readonly[readonly]'
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
test 'date input
|
|
19
|
+
test 'date input generates readonly elements when readonly option is true' do
|
|
20
20
|
with_input_for @user, :born_at, :date, readonly: true
|
|
21
21
|
assert_select 'select.date.readonly[readonly]'
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
test 'datetime input
|
|
24
|
+
test 'datetime input generates readonly elements when readonly option is true' do
|
|
25
25
|
with_input_for @user, :created_at, :datetime, readonly: true
|
|
26
26
|
assert_select 'select.datetime.readonly[readonly]'
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
test 'string input
|
|
29
|
+
test 'string input generates readonly elements when readonly option is false' do
|
|
30
30
|
with_input_for @user, :name, :string, readonly: false
|
|
31
31
|
assert_no_select 'input.string.readonly[readonly]'
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
test 'text input
|
|
34
|
+
test 'text input generates readonly elements when readonly option is false' do
|
|
35
35
|
with_input_for @user, :description, :text, readonly: false
|
|
36
36
|
assert_no_select 'textarea.text.readonly[readonly]'
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
test 'numeric input
|
|
39
|
+
test 'numeric input generates readonly elements when readonly option is false' do
|
|
40
40
|
with_input_for @user, :age, :integer, readonly: false
|
|
41
41
|
assert_no_select 'input.integer.readonly[readonly]'
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
test 'date input
|
|
44
|
+
test 'date input generates readonly elements when readonly option is false' do
|
|
45
45
|
with_input_for @user, :born_at, :date, readonly: false
|
|
46
46
|
assert_no_select 'select.date.readonly[readonly]'
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
test 'datetime input
|
|
49
|
+
test 'datetime input generates readonly elements when readonly option is false' do
|
|
50
50
|
with_input_for @user, :created_at, :datetime, readonly: false
|
|
51
51
|
assert_no_select 'select.datetime.readonly[readonly]'
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
test 'string input
|
|
54
|
+
test 'string input generates readonly elements when readonly option is not present' do
|
|
55
55
|
with_input_for @user, :name, :string
|
|
56
56
|
assert_no_select 'input.string.readonly[readonly]'
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
test 'text input
|
|
59
|
+
test 'text input generates readonly elements when readonly option is not present' do
|
|
60
60
|
with_input_for @user, :description, :text
|
|
61
61
|
assert_no_select 'textarea.text.readonly[readonly]'
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
test 'numeric input
|
|
64
|
+
test 'numeric input generates readonly elements when readonly option is not present' do
|
|
65
65
|
with_input_for @user, :age, :integer
|
|
66
66
|
assert_no_select 'input.integer.readonly[readonly]'
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
test 'date input
|
|
69
|
+
test 'date input generates readonly elements when readonly option is not present' do
|
|
70
70
|
with_input_for @user, :born_at, :date
|
|
71
71
|
assert_no_select 'select.date.readonly[readonly]'
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
test 'datetime input
|
|
74
|
+
test 'datetime input generates readonly elements when readonly option is not present' do
|
|
75
75
|
with_input_for @user, :created_at, :datetime
|
|
76
76
|
assert_no_select 'select.datetime.readonly[readonly]'
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
test 'input
|
|
79
|
+
test 'input generates readonly attribute when the field is readonly and the object is persisted' do
|
|
80
80
|
with_input_for @user, :credit_card, :string, readonly: :lookup
|
|
81
81
|
assert_select 'input.string.readonly[readonly]'
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
test 'input
|
|
84
|
+
test 'input does not generate readonly attribute when the field is readonly and the object is not persisted' do
|
|
85
85
|
@user.new_record!
|
|
86
86
|
with_input_for @user, :credit_card, :string, readonly: :lookup
|
|
87
87
|
assert_no_select 'input.string.readonly[readonly]'
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
test 'input
|
|
90
|
+
test 'input does not generate readonly attribute when the field is not readonly and the object is persisted' do
|
|
91
91
|
with_input_for @user, :name, :string
|
|
92
92
|
assert_no_select 'input.string.readonly[readonly]'
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
test 'input
|
|
95
|
+
test 'input does not generate readonly attribute when the component is not used' do
|
|
96
96
|
swap_wrapper do
|
|
97
97
|
with_input_for @user, :credit_card, :string
|
|
98
98
|
assert_no_select 'input.string.readonly[readonly]'
|
|
@@ -2,26 +2,26 @@ require 'test_helper'
|
|
|
2
2
|
|
|
3
3
|
class RequiredTest < ActionView::TestCase
|
|
4
4
|
# REQUIRED AND PRESENCE VALIDATION
|
|
5
|
-
test 'builder input
|
|
5
|
+
test 'builder input obtains required from ActiveModel::Validations when it is included' do
|
|
6
6
|
with_form_for @validating_user, :name
|
|
7
7
|
assert_select 'input.required[required]#validating_user_name'
|
|
8
8
|
with_form_for @validating_user, :status
|
|
9
9
|
assert_select 'input.optional#validating_user_status'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
test 'builder input
|
|
12
|
+
test 'builder input allows overriding required when ActiveModel::Validations is included' do
|
|
13
13
|
with_form_for @validating_user, :name, required: false
|
|
14
14
|
assert_select 'input.optional#validating_user_name'
|
|
15
15
|
with_form_for @validating_user, :status, required: true
|
|
16
16
|
assert_select 'input.required[required]#validating_user_status'
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
test 'builder input
|
|
19
|
+
test 'builder input is required by default when ActiveModel::Validations is not included' do
|
|
20
20
|
with_form_for @user, :name
|
|
21
21
|
assert_select 'input.required[required]#user_name'
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
test 'builder input
|
|
24
|
+
test 'builder input does not be required by default when ActiveModel::Validations is not included if option is set to false' do
|
|
25
25
|
swap SimpleForm, required_by_default: false do
|
|
26
26
|
with_form_for @user, :name
|
|
27
27
|
assert_select 'input.optional#user_name'
|
|
@@ -29,7 +29,7 @@ class RequiredTest < ActionView::TestCase
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
test 'when not using browser validations, input
|
|
32
|
+
test 'when not using browser validations, input does not generate required html attribute' do
|
|
33
33
|
swap SimpleForm, browser_validations: false do
|
|
34
34
|
with_input_for @user, :name, :string
|
|
35
35
|
assert_select 'input[type=text].required'
|
|
@@ -37,7 +37,7 @@ class RequiredTest < ActionView::TestCase
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
test 'builder input
|
|
40
|
+
test 'builder input allows disabling required when ActiveModel::Validations is not included' do
|
|
41
41
|
with_form_for @user, :name, required: false
|
|
42
42
|
assert_no_select 'input.required'
|
|
43
43
|
assert_no_select 'input[required]'
|
|
@@ -53,14 +53,14 @@ class RequiredTest < ActionView::TestCase
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# VALIDATORS :if :unless
|
|
56
|
-
test 'builder input
|
|
56
|
+
test 'builder input does not be required when ActiveModel::Validations is included and if option is present' do
|
|
57
57
|
with_form_for @validating_user, :age
|
|
58
58
|
assert_no_select 'input.required'
|
|
59
59
|
assert_no_select 'input[required]'
|
|
60
60
|
assert_select 'input.optional#validating_user_age'
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
test 'builder input
|
|
63
|
+
test 'builder input does not be required when ActiveModel::Validations is included and unless option is present' do
|
|
64
64
|
with_form_for @validating_user, :amount
|
|
65
65
|
assert_no_select 'input.required'
|
|
66
66
|
assert_no_select 'input[required]'
|
|
@@ -68,7 +68,7 @@ class RequiredTest < ActionView::TestCase
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
# VALIDATORS :on
|
|
71
|
-
test 'builder input
|
|
71
|
+
test 'builder input is required when validation is on create and is not persisted' do
|
|
72
72
|
@validating_user.new_record!
|
|
73
73
|
with_form_for @validating_user, :action
|
|
74
74
|
assert_select 'input.required'
|
|
@@ -76,14 +76,14 @@ class RequiredTest < ActionView::TestCase
|
|
|
76
76
|
assert_select 'input.required[required]#validating_user_action'
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
test 'builder input
|
|
79
|
+
test 'builder input does not be required when validation is on create and is persisted' do
|
|
80
80
|
with_form_for @validating_user, :action
|
|
81
81
|
assert_no_select 'input.required'
|
|
82
82
|
assert_no_select 'input[required]'
|
|
83
83
|
assert_select 'input.optional#validating_user_action'
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
test 'builder input
|
|
86
|
+
test 'builder input is required when validation is on save' do
|
|
87
87
|
with_form_for @validating_user, :credit_limit
|
|
88
88
|
assert_select 'input.required'
|
|
89
89
|
assert_select 'input[required]'
|
|
@@ -96,14 +96,14 @@ class RequiredTest < ActionView::TestCase
|
|
|
96
96
|
assert_select 'input.required[required]#validating_user_credit_limit'
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
test 'builder input
|
|
99
|
+
test 'builder input is required when validation is on update and is persisted' do
|
|
100
100
|
with_form_for @validating_user, :phone_number
|
|
101
101
|
assert_select 'input.required'
|
|
102
102
|
assert_select 'input[required]'
|
|
103
103
|
assert_select 'input.required[required]#validating_user_phone_number'
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
test 'builder input
|
|
106
|
+
test 'builder input does not be required when validation is on update and is not persisted' do
|
|
107
107
|
@validating_user.new_record!
|
|
108
108
|
with_form_for @validating_user, :phone_number
|
|
109
109
|
assert_no_select 'input.required'
|
|
@@ -2,120 +2,120 @@
|
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
4
|
class StringInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
5
|
+
test 'input maps text field to string attribute' do
|
|
6
6
|
with_input_for @user, :name, :string
|
|
7
|
-
assert_select "input#user_name[type=text][name='user[name]'][value=New in SimpleForm!]"
|
|
7
|
+
assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
test 'input
|
|
10
|
+
test 'input generates a password field for password attributes' do
|
|
11
11
|
with_input_for @user, :password, :password
|
|
12
12
|
assert_select "input#user_password.password[type=password][name='user[password]']"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
test 'input
|
|
15
|
+
test 'input gets maxlength from column definition for string attributes' do
|
|
16
16
|
with_input_for @user, :name, :string
|
|
17
|
-
assert_select 'input.string[maxlength=100]'
|
|
17
|
+
assert_select 'input.string[maxlength="100"]'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
test 'input
|
|
20
|
+
test 'input does not get maxlength from column without size definition for string attributes' do
|
|
21
21
|
with_input_for @user, :action, :string
|
|
22
22
|
assert_no_select 'input.string[maxlength]'
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
test 'input
|
|
25
|
+
test 'input gets maxlength from column definition for password attributes' do
|
|
26
26
|
with_input_for @user, :password, :password
|
|
27
|
-
assert_select 'input.password[type=password][maxlength=100]'
|
|
27
|
+
assert_select 'input.password[type=password][maxlength="100"]'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
test 'input
|
|
30
|
+
test 'input infers maxlength column definition from validation when present' do
|
|
31
31
|
with_input_for @validating_user, :name, :string
|
|
32
|
-
assert_select 'input.string[maxlength=25]'
|
|
32
|
+
assert_select 'input.string[maxlength="25"]'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
test 'input
|
|
35
|
+
test 'input does not get maxlength from validation when tokenizer present' do
|
|
36
36
|
with_input_for @validating_user, :action, :string
|
|
37
37
|
assert_no_select 'input.string[maxlength]'
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
test 'input
|
|
40
|
+
test 'input gets maxlength from validation when :is option present' do
|
|
41
41
|
with_input_for @validating_user, :home_picture, :string
|
|
42
|
-
assert_select 'input.string[maxlength=12]'
|
|
42
|
+
assert_select 'input.string[maxlength="12"]'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
test 'input maxlength
|
|
45
|
+
test 'input maxlength is the column limit plus one to make room for decimal point' do
|
|
46
46
|
with_input_for @user, :credit_limit, :string
|
|
47
47
|
|
|
48
|
-
assert_select
|
|
48
|
+
assert_select 'input.string[maxlength="16"]'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
test 'input
|
|
51
|
+
test 'input does not generate placeholder by default' do
|
|
52
52
|
with_input_for @user, :name, :string
|
|
53
53
|
assert_no_select 'input[placeholder]'
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
test 'input
|
|
56
|
+
test 'input accepts the placeholder option' do
|
|
57
57
|
with_input_for @user, :name, :string, placeholder: 'Put in some text'
|
|
58
|
-
assert_select 'input.string[placeholder=Put in some text]'
|
|
58
|
+
assert_select 'input.string[placeholder="Put in some text"]'
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
test 'input
|
|
61
|
+
test 'input generates a password field for password attributes that accept placeholder' do
|
|
62
62
|
with_input_for @user, :password, :password, placeholder: 'Password Confirmation'
|
|
63
|
-
assert_select 'input[type=password].password[placeholder=Password Confirmation]#user_password'
|
|
63
|
+
assert_select 'input[type=password].password[placeholder="Password Confirmation"]#user_password'
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
test 'input
|
|
66
|
+
test 'input does not infer pattern from attributes by default' do
|
|
67
67
|
with_input_for @other_validating_user, :country, :string
|
|
68
68
|
assert_no_select 'input[pattern="\w+"]'
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
test 'input
|
|
71
|
+
test 'input infers pattern from attributes' do
|
|
72
72
|
with_input_for @other_validating_user, :country, :string, pattern: true
|
|
73
73
|
assert_select 'input[pattern="\w+"]'
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
test 'input
|
|
76
|
+
test 'input infers pattern from attributes using proc' do
|
|
77
77
|
with_input_for @other_validating_user, :name, :string, pattern: true
|
|
78
78
|
assert_select 'input[pattern="\w+"]'
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
test 'input
|
|
81
|
+
test 'input does not infer pattern from attributes if root default is false' do
|
|
82
82
|
swap_wrapper do
|
|
83
83
|
with_input_for @other_validating_user, :country, :string
|
|
84
84
|
assert_no_select 'input[pattern="\w+"]'
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
test 'input
|
|
88
|
+
test 'input uses given pattern from attributes' do
|
|
89
89
|
with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
|
|
90
90
|
assert_select 'input[pattern="\d+"]'
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
test 'input
|
|
93
|
+
test 'input does not use pattern if model has :without validation option' do
|
|
94
94
|
with_input_for @other_validating_user, :description, :string, pattern: true
|
|
95
95
|
assert_no_select 'input[pattern="\d+"]'
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
test 'input
|
|
98
|
+
test 'input uses i18n to translate placeholder text' do
|
|
99
99
|
store_translations(:en, simple_form: { placeholders: { user: {
|
|
100
100
|
name: 'Name goes here'
|
|
101
101
|
} } }) do
|
|
102
102
|
with_input_for @user, :name, :string
|
|
103
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
|
103
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
test 'input
|
|
107
|
+
test 'input uses custom i18n scope to translate placeholder text' do
|
|
108
108
|
store_translations(:en, my_scope: { placeholders: { user: {
|
|
109
109
|
name: 'Name goes here'
|
|
110
110
|
} } }) do
|
|
111
111
|
swap SimpleForm, i18n_scope: :my_scope do
|
|
112
112
|
with_input_for @user, :name, :string
|
|
113
|
-
assert_select 'input.string[placeholder=Name goes here]'
|
|
113
|
+
assert_select 'input.string[placeholder="Name goes here"]'
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
test 'input
|
|
118
|
+
test 'input translates a key prefixed with _html and return the html markup' do
|
|
119
119
|
store_translations(:en, simple_form: { labels: { user: {
|
|
120
120
|
name_html: '<b>Name</b>'
|
|
121
121
|
} } }) do
|
|
@@ -125,13 +125,13 @@ class StringInputTest < ActionView::TestCase
|
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
[:email, :url, :search, :tel].each do |type|
|
|
128
|
-
test "input
|
|
128
|
+
test "input allows type #{type}" do
|
|
129
129
|
with_input_for @user, :name, type
|
|
130
130
|
assert_select "input.string.#{type}"
|
|
131
131
|
assert_select "input[type=#{type}]"
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
test "input
|
|
134
|
+
test "input does not allow type #{type} if HTML5 compatibility is disabled" do
|
|
135
135
|
swap_wrapper do
|
|
136
136
|
with_input_for @user, :name, type
|
|
137
137
|
assert_select "input[type=text]"
|
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
require 'test_helper'
|
|
3
3
|
|
|
4
4
|
class TextInputTest < ActionView::TestCase
|
|
5
|
-
test 'input
|
|
5
|
+
test 'input generates a text area for text attributes' do
|
|
6
6
|
with_input_for @user, :description, :text
|
|
7
7
|
assert_select 'textarea.text#user_description'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
test 'input
|
|
10
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
|
11
11
|
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
|
12
|
-
assert_select 'textarea.text[placeholder=Put in some text]'
|
|
12
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
test 'input
|
|
15
|
+
test 'input gets maxlength from column definition for text attributes' do
|
|
16
16
|
with_input_for @user, :description, :text
|
|
17
|
-
assert_select 'textarea.text[maxlength=200]'
|
|
17
|
+
assert_select 'textarea.text[maxlength="200"]'
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
test 'input
|
|
20
|
+
test 'input infers maxlength column definition from validation when present for text attributes' do
|
|
21
21
|
with_input_for @validating_user, :description, :text
|
|
22
|
-
assert_select 'textarea.text[maxlength=50]'
|
|
22
|
+
assert_select 'textarea.text[maxlength="50"]'
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -35,3 +35,23 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
|
|
35
35
|
super.push('chosen')
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
module CustomInputs
|
|
40
|
+
class CustomizedInput < SimpleForm::Inputs::StringInput
|
|
41
|
+
def input_html_classes
|
|
42
|
+
super.push('customized-namespace-custom-input')
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class PasswordInput < SimpleForm::Inputs::PasswordInput
|
|
47
|
+
def input_html_classes
|
|
48
|
+
super.push('password-custom-input')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class NumericInput < SimpleForm::Inputs::PasswordInput
|
|
53
|
+
def input_html_classes
|
|
54
|
+
super.push('numeric-custom-input')
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -68,6 +68,22 @@ module MiscHelpers
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
def custom_wrapper_with_wrapped_optional_component
|
|
72
|
+
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
|
|
73
|
+
b.wrapper tag: :div, class: 'no_output_wrapper' do |ba|
|
|
74
|
+
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def custom_wrapper_with_unless_blank
|
|
80
|
+
SimpleForm.build tag: :section, class: "custom_wrapper" do |b|
|
|
81
|
+
b.wrapper tag: :div, class: 'no_output_wrapper', unless_blank: true do |ba|
|
|
82
|
+
ba.optional :hint, wrap_with: { tag: :p, class: 'omg_hint' }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
71
87
|
def custom_wrapper_with_input_class
|
|
72
88
|
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
73
89
|
b.use :label
|
|
@@ -156,6 +172,18 @@ module MiscHelpers
|
|
|
156
172
|
end
|
|
157
173
|
end
|
|
158
174
|
|
|
175
|
+
def custom_wrapper_with_custom_label_component
|
|
176
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
|
177
|
+
b.use :label_text
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def custom_wrapper_with_html5_components
|
|
182
|
+
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
|
|
183
|
+
b.use :label_text
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
159
187
|
def custom_form_for(object, *args, &block)
|
|
160
188
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
|
161
189
|
end
|
data/test/support/models.rb
CHANGED
|
@@ -74,7 +74,7 @@ class User
|
|
|
74
74
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
|
75
75
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
|
76
76
|
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
|
77
|
-
:special_picture_ids
|
|
77
|
+
:special_picture_ids, :uuid
|
|
78
78
|
|
|
79
79
|
def self.build(extra_attributes = {})
|
|
80
80
|
attributes = {
|
|
@@ -125,10 +125,21 @@ class User
|
|
|
125
125
|
when :attempts then :integer
|
|
126
126
|
when :action then :string
|
|
127
127
|
when :credit_card then :string
|
|
128
|
+
when :uuid then :uuid
|
|
128
129
|
end
|
|
129
130
|
Column.new(attribute, column_type, limit)
|
|
130
131
|
end
|
|
131
132
|
|
|
133
|
+
def has_attribute?(attribute)
|
|
134
|
+
case attribute.to_sym
|
|
135
|
+
when :name, :status, :password, :description, :age,
|
|
136
|
+
:credit_limit, :active, :born_at, :delivery_time,
|
|
137
|
+
:created_at, :updated_at, :lock_version, :home_picture,
|
|
138
|
+
:amount, :attempts, :action, :credit_card, :uuid then true
|
|
139
|
+
else false
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
132
143
|
def self.human_attribute_name(attribute, options = {})
|
|
133
144
|
case attribute
|
|
134
145
|
when 'name'
|
|
@@ -164,7 +175,7 @@ class User
|
|
|
164
175
|
def errors
|
|
165
176
|
@errors ||= begin
|
|
166
177
|
errors = ActiveModel::Errors.new(self)
|
|
167
|
-
errors.add(:name, "
|
|
178
|
+
errors.add(:name, "cannot be blank")
|
|
168
179
|
errors.add(:description, 'must be longer than 15 characters')
|
|
169
180
|
errors.add(:age, 'is not a number')
|
|
170
181
|
errors.add(:age, 'must be greater than 18')
|
data/test/test_helper.rb
CHANGED
|
@@ -30,7 +30,11 @@ I18n.default_locale = :en
|
|
|
30
30
|
|
|
31
31
|
require 'country_select'
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
if defined?(HTMLSelector::NO_STRIP)
|
|
34
|
+
HTMLSelector::NO_STRIP << "label"
|
|
35
|
+
else
|
|
36
|
+
ActionDispatch::Assertions::NO_STRIP << "label"
|
|
37
|
+
end
|
|
34
38
|
|
|
35
39
|
class ActionView::TestCase
|
|
36
40
|
include MiscHelpers
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.0
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- José Valim
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-
|
|
13
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
@@ -161,9 +161,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
161
161
|
version: '0'
|
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
requirements:
|
|
164
|
-
- - "
|
|
164
|
+
- - ">="
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
|
-
version:
|
|
166
|
+
version: '0'
|
|
167
167
|
requirements: []
|
|
168
168
|
rubyforge_project: simple_form
|
|
169
169
|
rubygems_version: 2.2.2
|