simple_form 1.5.2 → 2.0.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.
- data/CHANGELOG.md +234 -0
- data/MIT-LICENSE +1 -1
- data/README.md +816 -0
- data/lib/generators/simple_form/install_generator.rb +15 -1
- data/lib/generators/simple_form/templates/README +12 -0
- data/lib/generators/simple_form/templates/_form.html.erb +2 -2
- data/lib/generators/simple_form/templates/_form.html.haml +2 -2
- data/lib/generators/simple_form/templates/_form.html.slim +4 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +176 -0
- data/lib/simple_form/action_view_extensions/builder.rb +206 -59
- data/lib/simple_form/action_view_extensions/form_helper.rb +30 -23
- data/lib/simple_form/components/errors.rb +6 -24
- data/lib/simple_form/components/hints.rb +7 -21
- data/lib/simple_form/components/html5.rb +26 -0
- data/lib/simple_form/components/labels.rb +22 -14
- data/lib/simple_form/components/maxlength.rb +41 -0
- data/lib/simple_form/components/min_max.rb +49 -0
- data/lib/simple_form/components/pattern.rb +34 -0
- data/lib/simple_form/components/placeholders.rb +5 -17
- data/lib/simple_form/components/readonly.rb +22 -0
- data/lib/simple_form/components.rb +11 -1
- data/lib/simple_form/core_ext/hash.rb +16 -0
- data/lib/simple_form/error_notification.rb +9 -3
- data/lib/simple_form/form_builder.rb +105 -28
- data/lib/simple_form/helpers/autofocus.rb +11 -0
- data/lib/simple_form/helpers/disabled.rb +15 -0
- data/lib/simple_form/helpers/readonly.rb +15 -0
- data/lib/simple_form/helpers/required.rb +10 -11
- data/lib/simple_form/helpers/validators.rb +4 -4
- data/lib/simple_form/helpers.rb +7 -4
- data/lib/simple_form/inputs/base.rb +53 -81
- data/lib/simple_form/inputs/boolean_input.rb +46 -4
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
- data/lib/simple_form/inputs/collection_input.rb +27 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +67 -0
- data/lib/simple_form/inputs/collection_select_input.rb +14 -0
- data/lib/simple_form/inputs/date_time_input.rb +10 -6
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
- data/lib/simple_form/inputs/hidden_input.rb +3 -6
- data/lib/simple_form/inputs/numeric_input.rb +3 -51
- data/lib/simple_form/inputs/password_input.rb +1 -2
- data/lib/simple_form/inputs/priority_input.rb +2 -2
- data/lib/simple_form/inputs/range_input.rb +1 -3
- data/lib/simple_form/inputs/string_input.rb +6 -8
- data/lib/simple_form/inputs/text_input.rb +1 -2
- data/lib/simple_form/inputs.rb +17 -13
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +103 -0
- data/lib/simple_form/wrappers/many.rb +69 -0
- data/lib/simple_form/wrappers/root.rb +34 -0
- data/lib/simple_form/wrappers/single.rb +18 -0
- data/lib/simple_form/wrappers.rb +8 -0
- data/lib/simple_form.rb +118 -48
- data/test/action_view_extensions/builder_test.rb +285 -102
- data/test/action_view_extensions/form_helper_test.rb +32 -10
- data/test/components/label_test.rb +44 -5
- data/test/form_builder/association_test.rb +177 -0
- data/test/form_builder/button_test.rb +47 -0
- data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +18 -1
- data/test/form_builder/error_test.rb +121 -0
- data/test/form_builder/general_test.rb +356 -0
- data/test/form_builder/hint_test.rb +123 -0
- data/test/form_builder/input_field_test.rb +63 -0
- data/test/form_builder/label_test.rb +65 -0
- data/test/form_builder/wrapper_test.rb +149 -0
- data/test/generators/simple_form_generator_test.rb +32 -0
- data/test/inputs/boolean_input_test.rb +101 -0
- data/test/inputs/collection_check_boxes_input_test.rb +224 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
- data/test/inputs/collection_select_input_test.rb +241 -0
- data/test/inputs/datetime_input_test.rb +99 -0
- data/test/inputs/disabled_test.rb +38 -0
- data/test/inputs/discovery_test.rb +61 -0
- data/test/inputs/file_input_test.rb +16 -0
- data/test/inputs/general_test.rb +69 -0
- data/test/inputs/grouped_collection_select_input_test.rb +118 -0
- data/test/inputs/hidden_input_test.rb +30 -0
- data/test/inputs/numeric_input_test.rb +167 -0
- data/test/inputs/priority_input_test.rb +43 -0
- data/test/inputs/readonly_test.rb +61 -0
- data/test/inputs/required_test.rb +113 -0
- data/test/inputs/string_input_test.rb +140 -0
- data/test/inputs/text_input_test.rb +24 -0
- data/test/support/misc_helpers.rb +53 -12
- data/test/support/mock_controller.rb +2 -2
- data/test/support/models.rb +20 -5
- data/test/test_helper.rb +11 -12
- metadata +124 -96
- data/.gitignore +0 -3
- data/.gitmodules +0 -3
- data/.travis.yml +0 -15
- data/CHANGELOG.rdoc +0 -159
- data/Gemfile +0 -9
- data/README.rdoc +0 -466
- data/Rakefile +0 -27
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
- data/lib/simple_form/components/wrapper.rb +0 -38
- data/lib/simple_form/helpers/has_errors.rb +0 -15
- data/lib/simple_form/helpers/maxlength.rb +0 -24
- data/lib/simple_form/helpers/pattern.rb +0 -28
- data/simple_form.gemspec +0 -25
- data/test/components/error_test.rb +0 -56
- data/test/components/hint_test.rb +0 -74
- data/test/components/wrapper_test.rb +0 -63
- data/test/custom_components.rb +0 -7
- data/test/form_builder_test.rb +0 -930
- data/test/inputs_test.rb +0 -995
- /data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DisabledTest < ActionView::TestCase
|
|
4
|
+
test 'input should generate disabled elements based on the disabled option' do
|
|
5
|
+
with_input_for @user, :name, :string, :disabled => true
|
|
6
|
+
assert_select 'input.string.disabled[disabled]'
|
|
7
|
+
with_input_for @user, :description, :text, :disabled => true
|
|
8
|
+
assert_select 'textarea.text.disabled[disabled]'
|
|
9
|
+
with_input_for @user, :age, :integer, :disabled => true
|
|
10
|
+
assert_select 'input.integer.disabled[disabled]'
|
|
11
|
+
with_input_for @user, :born_at, :date, :disabled => true
|
|
12
|
+
assert_select 'select.date.disabled[disabled]'
|
|
13
|
+
with_input_for @user, :created_at, :datetime, :disabled => true
|
|
14
|
+
assert_select 'select.datetime.disabled[disabled]'
|
|
15
|
+
|
|
16
|
+
with_input_for @user, :name, :string, :disabled => false
|
|
17
|
+
assert_select 'input.string:not(.disabled[disabled])'
|
|
18
|
+
with_input_for @user, :description, :text, :disabled => false
|
|
19
|
+
assert_select 'textarea.text:not(.disabled[disabled])'
|
|
20
|
+
with_input_for @user, :age, :integer, :disabled => false
|
|
21
|
+
assert_select 'input.integer:not(.disabled[disabled])'
|
|
22
|
+
with_input_for @user, :born_at, :date, :disabled => false
|
|
23
|
+
assert_select 'select.date:not(.disabled[disabled])'
|
|
24
|
+
with_input_for @user, :created_at, :datetime, :disabled => false
|
|
25
|
+
assert_select 'select.datetime:not(.disabled[disabled])'
|
|
26
|
+
|
|
27
|
+
with_input_for @user, :name, :string
|
|
28
|
+
assert_select 'input.string:not(.disabled[disabled])'
|
|
29
|
+
with_input_for @user, :description, :text
|
|
30
|
+
assert_select 'textarea.text:not(.disabled[disabled])'
|
|
31
|
+
with_input_for @user, :age, :integer
|
|
32
|
+
assert_select 'input.integer:not(.disabled[disabled])'
|
|
33
|
+
with_input_for @user, :born_at, :date
|
|
34
|
+
assert_select 'select.date:not(.disabled[disabled])'
|
|
35
|
+
with_input_for @user, :created_at, :datetime
|
|
36
|
+
assert_select 'select.datetime:not(.disabled[disabled])'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DiscoveryTest < ActionView::TestCase
|
|
4
|
+
# Setup new inputs and remove them after the test.
|
|
5
|
+
def discovery(value=false)
|
|
6
|
+
swap SimpleForm, :cache_discovery => value do
|
|
7
|
+
begin
|
|
8
|
+
load "support/discovery_inputs.rb"
|
|
9
|
+
yield
|
|
10
|
+
ensure
|
|
11
|
+
SimpleForm::FormBuilder.discovery_cache.clear
|
|
12
|
+
Object.send :remove_const, :StringInput
|
|
13
|
+
Object.send :remove_const, :NumericInput
|
|
14
|
+
Object.send :remove_const, :CustomizedInput
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'builder should not discover new inputs if cached' do
|
|
20
|
+
with_form_for @user, :name
|
|
21
|
+
assert_select 'form input#user_name.string'
|
|
22
|
+
|
|
23
|
+
discovery(true) do
|
|
24
|
+
with_form_for @user, :name
|
|
25
|
+
assert_no_select 'form section input#user_name.string'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'builder should discover new inputs' do
|
|
30
|
+
discovery do
|
|
31
|
+
with_form_for @user, :name, :as => :customized
|
|
32
|
+
assert_select 'form section input#user_name.string'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'builder should not discover new inputs if discovery is off' do
|
|
37
|
+
with_form_for @user, :name
|
|
38
|
+
assert_select 'form input#user_name.string'
|
|
39
|
+
|
|
40
|
+
swap SimpleForm, :inputs_discovery => false do
|
|
41
|
+
discovery do
|
|
42
|
+
with_form_for @user, :name
|
|
43
|
+
assert_no_select 'form section input#user_name.string'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'builder should discover new inputs from mappings if not cached' do
|
|
49
|
+
discovery do
|
|
50
|
+
with_form_for @user, :name
|
|
51
|
+
assert_select 'form section input#user_name.string'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'builder should discover new inputs from internal fallbacks if not cached' do
|
|
56
|
+
discovery do
|
|
57
|
+
with_form_for @user, :age
|
|
58
|
+
assert_select 'form section input#user_age.numeric.integer'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class FileInputTest < ActionView::TestCase
|
|
5
|
+
test 'input should generate a file field' do
|
|
6
|
+
with_input_for @user, :name, :file
|
|
7
|
+
assert_select 'input#user_name[type=file]'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "input should generate a file field that doesn't accept placeholder" do
|
|
11
|
+
store_translations(:en, :simple_form => { :placeholders => { :user => { :name => "text" } } }) do
|
|
12
|
+
with_input_for @user, :name, :file
|
|
13
|
+
assert_no_select 'input[placeholder]'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class InputTest < ActionView::TestCase
|
|
5
|
+
test 'input should generate css class based on default input type' do
|
|
6
|
+
with_input_for @user, :name, :string
|
|
7
|
+
assert_select 'input.string'
|
|
8
|
+
with_input_for @user, :description, :text
|
|
9
|
+
assert_select 'textarea.text'
|
|
10
|
+
with_input_for @user, :age, :integer
|
|
11
|
+
assert_select 'input.integer'
|
|
12
|
+
with_input_for @user, :born_at, :date
|
|
13
|
+
assert_select 'select.date'
|
|
14
|
+
with_input_for @user, :created_at, :datetime
|
|
15
|
+
assert_select 'select.datetime'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'input should generate autofocus attribute based on the autofocus option' do
|
|
19
|
+
with_input_for @user, :name, :string, :autofocus => true
|
|
20
|
+
assert_select 'input.string[autofocus]'
|
|
21
|
+
with_input_for @user, :description, :text, :autofocus => true
|
|
22
|
+
assert_select 'textarea.text[autofocus]'
|
|
23
|
+
with_input_for @user, :age, :integer, :autofocus => true
|
|
24
|
+
assert_select 'input.integer[autofocus]'
|
|
25
|
+
with_input_for @user, :born_at, :date, :autofocus => true
|
|
26
|
+
assert_select 'select.date[autofocus]'
|
|
27
|
+
with_input_for @user, :created_at, :datetime, :autofocus => true
|
|
28
|
+
assert_select 'select.datetime[autofocus]'
|
|
29
|
+
|
|
30
|
+
with_input_for @user, :name, :string, :autofocus => false
|
|
31
|
+
assert_select 'input.string:not([autofocus])'
|
|
32
|
+
with_input_for @user, :description, :text, :autofocus => false
|
|
33
|
+
assert_select 'textarea.text:not([autofocus])'
|
|
34
|
+
with_input_for @user, :age, :integer, :autofocus => false
|
|
35
|
+
assert_select 'input.integer:not([autofocus])'
|
|
36
|
+
with_input_for @user, :born_at, :date, :autofocus => false
|
|
37
|
+
assert_select 'select.date:not([autofocus])'
|
|
38
|
+
with_input_for @user, :created_at, :datetime, :autofocus => false
|
|
39
|
+
assert_select 'select.datetime:not([autofocus])'
|
|
40
|
+
|
|
41
|
+
with_input_for @user, :name, :string
|
|
42
|
+
assert_select 'input.string:not([autofocus])'
|
|
43
|
+
with_input_for @user, :description, :text
|
|
44
|
+
assert_select 'textarea.text:not([autofocus])'
|
|
45
|
+
with_input_for @user, :age, :integer
|
|
46
|
+
assert_select 'input.integer:not([autofocus])'
|
|
47
|
+
with_input_for @user, :born_at, :date
|
|
48
|
+
assert_select 'select.date:not([autofocus])'
|
|
49
|
+
with_input_for @user, :created_at, :datetime
|
|
50
|
+
assert_select 'select.datetime:not([autofocus])'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# With no object
|
|
54
|
+
test 'input should be generated properly when object is not present' do
|
|
55
|
+
with_input_for :project, :name, :string
|
|
56
|
+
assert_select 'input.string.required#project_name'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
test 'input as radio should be generated properly when object is not present ' do
|
|
60
|
+
with_input_for :project, :name, :radio_buttons
|
|
61
|
+
assert_select 'input.radio_buttons#project_name_true'
|
|
62
|
+
assert_select 'input.radio_buttons#project_name_false'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'input as select with collection should be generated properly when object is not present' do
|
|
66
|
+
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
|
|
67
|
+
assert_select 'select.select#project_name'
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class GroupedCollectionSelectInputTest < ActionView::TestCase
|
|
5
|
+
test 'grouped collection accepts array collection form' do
|
|
6
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
7
|
+
:collection => [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]],
|
|
8
|
+
:group_method => :last
|
|
9
|
+
|
|
10
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
11
|
+
assert_select 'optgroup[label=Authors]' do
|
|
12
|
+
assert_select 'option', 'Jose'
|
|
13
|
+
assert_select 'option', 'Carlos'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
assert_select 'optgroup[label=General]' do
|
|
17
|
+
assert_select 'option', 'Bob'
|
|
18
|
+
assert_select 'option', 'John'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'grouped collection accepts empty array collection form' do
|
|
24
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
25
|
+
:collection => [],
|
|
26
|
+
:group_method => :last
|
|
27
|
+
|
|
28
|
+
assert_select 'select.grouped_select#user_tag_ids'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
test 'grouped collection accepts proc as collection' do
|
|
33
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
34
|
+
:collection => Proc.new { [['Authors', ['Jose', 'Carlos']], ['General', ['Bob', 'John']]] },
|
|
35
|
+
:group_method => :last
|
|
36
|
+
|
|
37
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
38
|
+
assert_select 'optgroup[label=Authors]' do
|
|
39
|
+
assert_select 'option', 'Jose'
|
|
40
|
+
assert_select 'option', 'Carlos'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
assert_select 'optgroup[label=General]' do
|
|
44
|
+
assert_select 'option', 'Bob'
|
|
45
|
+
assert_select 'option', 'John'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'grouped collection accepts hash collection form' do
|
|
51
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
52
|
+
:collection => { 'Authors' => ['Jose', 'Carlos'], 'General' => ['Bob', 'John'] },
|
|
53
|
+
:group_method => :last
|
|
54
|
+
|
|
55
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
56
|
+
assert_select 'optgroup[label=Authors]' do
|
|
57
|
+
assert_select 'option', 'Jose'
|
|
58
|
+
assert_select 'option', 'Carlos'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
assert_select 'optgroup[label=General]' do
|
|
62
|
+
assert_select 'option', 'Bob'
|
|
63
|
+
assert_select 'option', 'John'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
test 'grouped collection accepts group_label_method option' do
|
|
69
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
70
|
+
:collection => { ['Jose', 'Carlos'] => 'Authors' },
|
|
71
|
+
:group_method => :first,
|
|
72
|
+
:group_label_method => :last
|
|
73
|
+
|
|
74
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
75
|
+
assert_select 'optgroup[label=Authors]' do
|
|
76
|
+
assert_select 'option', 'Jose'
|
|
77
|
+
assert_select 'option', 'Carlos'
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
test 'grouped collection accepts label and value methods options' do
|
|
83
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
84
|
+
:collection => { 'Authors' => ['Jose', 'Carlos'] },
|
|
85
|
+
:group_method => :last,
|
|
86
|
+
:label_method => :upcase,
|
|
87
|
+
:value_method => :downcase
|
|
88
|
+
|
|
89
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
90
|
+
assert_select 'optgroup[label=Authors]' do
|
|
91
|
+
assert_select 'option[value=jose]', 'JOSE'
|
|
92
|
+
assert_select 'option[value=carlos]', 'CARLOS'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test 'grouped collection with associations' do
|
|
98
|
+
tag_groups = [
|
|
99
|
+
TagGroup.new(1, "Group of Tags", [Tag.new(1, "Tag 1"), Tag.new(2, "Tag 2")]),
|
|
100
|
+
TagGroup.new(2, "Other group", [Tag.new(3, "Tag 3"), Tag.new(4,"Tag 4")])
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
with_input_for @user, :tag_ids, :grouped_select,
|
|
104
|
+
:collection => tag_groups, :group_method => :tags
|
|
105
|
+
|
|
106
|
+
assert_select 'select.grouped_select#user_tag_ids' do
|
|
107
|
+
assert_select 'optgroup[label=Group of Tags]' do
|
|
108
|
+
assert_select 'option[value=1]', 'Tag 1'
|
|
109
|
+
assert_select 'option[value=2]', 'Tag 2'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
assert_select 'optgroup[label=Other group]' do
|
|
113
|
+
assert_select 'option[value=3]', 'Tag 3'
|
|
114
|
+
assert_select 'option[value=4]', 'Tag 4'
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class HiddenInputTest < ActionView::TestCase
|
|
5
|
+
test 'input should generate a hidden field' do
|
|
6
|
+
with_input_for @user, :name, :hidden
|
|
7
|
+
assert_no_select 'input[type=text]'
|
|
8
|
+
assert_select 'input#user_name[type=hidden]'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'hint should not be generated for hidden fields' do
|
|
12
|
+
store_translations(:en, :simple_form => { :hints => { :user => { :name => "text" } } }) do
|
|
13
|
+
with_input_for @user, :name, :hidden
|
|
14
|
+
assert_no_select 'span.hint'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'label should not be generated for hidden inputs' do
|
|
19
|
+
with_input_for @user, :name, :hidden
|
|
20
|
+
assert_no_select 'label'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'required/optional options should not be generated for hidden inputs' do
|
|
24
|
+
with_input_for @user, :name, :hidden
|
|
25
|
+
assert_no_select 'input.required'
|
|
26
|
+
assert_no_select 'input[required]'
|
|
27
|
+
assert_no_select 'input.optional'
|
|
28
|
+
assert_select 'input.hidden#user_name'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class NumericInputTest < ActionView::TestCase
|
|
5
|
+
test 'input should generate an integer text field for integer attributes ' do
|
|
6
|
+
with_input_for @user, :age, :integer
|
|
7
|
+
assert_select 'input[type=number].integer#user_age'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test 'input should generate a float text field for float attributes ' do
|
|
11
|
+
with_input_for @user, :age, :float
|
|
12
|
+
assert_select 'input[type=number].float#user_age'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'input should generate a decimal text field for decimal attributes ' do
|
|
16
|
+
with_input_for @user, :age, :decimal
|
|
17
|
+
assert_select 'input[type=number].decimal#user_age'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'input should not generate min attribute by default' do
|
|
21
|
+
with_input_for @user, :age, :integer
|
|
22
|
+
assert_no_select 'input[min]'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'input should not generate max attribute by default' do
|
|
26
|
+
with_input_for @user, :age, :integer
|
|
27
|
+
assert_no_select 'input[max]'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'input should infer min value from integer attributes with greater than validation' do
|
|
31
|
+
with_input_for @other_validating_user, :age, :float
|
|
32
|
+
assert_no_select 'input[min]'
|
|
33
|
+
|
|
34
|
+
with_input_for @other_validating_user, :age, :integer
|
|
35
|
+
assert_select 'input[min=18]'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'input should infer min value from integer attributes with greater than validation using symbol' do
|
|
39
|
+
with_input_for @validating_user, :amount, :float
|
|
40
|
+
assert_no_select 'input[min]'
|
|
41
|
+
|
|
42
|
+
with_input_for @validating_user, :amount, :integer
|
|
43
|
+
assert_select 'input[min=11]'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
test 'input should infer min value from integer attributes with greater than or equal to validation using symbol' do
|
|
47
|
+
with_input_for @validating_user, :attempts, :float
|
|
48
|
+
assert_select 'input[min=1]'
|
|
49
|
+
|
|
50
|
+
with_input_for @validating_user, :attempts, :integer
|
|
51
|
+
assert_select 'input[min=1]'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
test 'input should infer min value from integer attributes with greater than validation using proc' do
|
|
55
|
+
with_input_for @other_validating_user, :amount, :float
|
|
56
|
+
assert_no_select 'input[min]'
|
|
57
|
+
|
|
58
|
+
with_input_for @other_validating_user, :amount, :integer
|
|
59
|
+
assert_select 'input[min=20]'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'input should infer min value from integer attributes with greater than or equal to validation using proc' do
|
|
63
|
+
with_input_for @other_validating_user, :attempts, :float
|
|
64
|
+
assert_select 'input[min=19]'
|
|
65
|
+
|
|
66
|
+
with_input_for @other_validating_user, :attempts, :integer
|
|
67
|
+
assert_select 'input[min=19]'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
test 'input should infer max value from attributes with less than validation' do
|
|
71
|
+
with_input_for @other_validating_user, :age, :float
|
|
72
|
+
assert_no_select 'input[max]'
|
|
73
|
+
|
|
74
|
+
with_input_for @other_validating_user, :age, :integer
|
|
75
|
+
assert_select 'input[max=99]'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
test 'input should infer max value from attributes with less than validation using symbol' do
|
|
79
|
+
with_input_for @validating_user, :amount, :float
|
|
80
|
+
assert_no_select 'input[max]'
|
|
81
|
+
|
|
82
|
+
with_input_for @validating_user, :amount, :integer
|
|
83
|
+
assert_select 'input[max=99]'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
test 'input should infer max value from attributes with less than or equal to validation using symbol' do
|
|
87
|
+
with_input_for @validating_user, :attempts, :float
|
|
88
|
+
assert_select 'input[max=100]'
|
|
89
|
+
|
|
90
|
+
with_input_for @validating_user, :attempts, :integer
|
|
91
|
+
assert_select 'input[max=100]'
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test 'input should infer max value from attributes with less than validation using proc' do
|
|
95
|
+
with_input_for @other_validating_user, :amount, :float
|
|
96
|
+
assert_no_select 'input[max]'
|
|
97
|
+
|
|
98
|
+
with_input_for @other_validating_user, :amount, :integer
|
|
99
|
+
assert_select 'input[max=118]'
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
test 'input should infer max value from attributes with less than or equal to validation using proc' do
|
|
103
|
+
with_input_for @other_validating_user, :attempts, :float
|
|
104
|
+
assert_select 'input[max=119]'
|
|
105
|
+
|
|
106
|
+
with_input_for @other_validating_user, :attempts, :integer
|
|
107
|
+
assert_select 'input[max=119]'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
test 'input should have step value of any except for integer attribute' do
|
|
111
|
+
with_input_for @validating_user, :age, :float
|
|
112
|
+
assert_select 'input[step="any"]'
|
|
113
|
+
|
|
114
|
+
with_input_for @validating_user, :age, :integer
|
|
115
|
+
assert_select 'input[step=1]'
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
test 'numeric input should not generate placeholder by default' do
|
|
119
|
+
with_input_for @user, :age, :integer
|
|
120
|
+
assert_no_select 'input[placeholder]'
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test 'numeric input should accept the placeholder option' do
|
|
124
|
+
with_input_for @user, :age, :integer, :placeholder => 'Put in your age'
|
|
125
|
+
assert_select 'input.integer[placeholder=Put in your age]'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
test 'numeric input should use i18n to translate placeholder text' do
|
|
129
|
+
store_translations(:en, :simple_form => { :placeholders => { :user => {
|
|
130
|
+
:age => 'Age goes here'
|
|
131
|
+
} } }) do
|
|
132
|
+
with_input_for @user, :age, :integer
|
|
133
|
+
assert_select 'input.integer[placeholder=Age goes here]'
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Numeric input but HTML5 disabled
|
|
138
|
+
test ' when not using HTML5 input should not generate field with type number and use text instead' do
|
|
139
|
+
swap_wrapper do
|
|
140
|
+
with_input_for @user, :age, :integer
|
|
141
|
+
assert_no_select "input[type=number]"
|
|
142
|
+
assert_no_select "input#user_age[text]"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
test 'when not using HTML5 input should not use min or max or step attributes' do
|
|
147
|
+
swap_wrapper do
|
|
148
|
+
with_input_for @validating_user, :age, :integer
|
|
149
|
+
assert_no_select "input[type=number]"
|
|
150
|
+
assert_no_select "input[min]"
|
|
151
|
+
assert_no_select "input[max]"
|
|
152
|
+
assert_no_select "input[step]"
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
[:integer, :float, :decimal].each do |type|
|
|
157
|
+
test "#{type} input should infer min value from attributes with greater than or equal validation" do
|
|
158
|
+
with_input_for @validating_user, :age, type
|
|
159
|
+
assert_select 'input[min=18]'
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
test "#{type} input should infer the max value from attributes with less than or equal to validation" do
|
|
163
|
+
with_input_for @validating_user, :age, type
|
|
164
|
+
assert_select 'input[max=99]'
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'test_helper'
|
|
3
|
+
|
|
4
|
+
class PriorityInputTest < ActionView::TestCase
|
|
5
|
+
test 'input should generate a country select field' do
|
|
6
|
+
with_input_for @user, :country, :country
|
|
7
|
+
assert_select 'select#user_country'
|
|
8
|
+
assert_select 'select option[value=Brazil]', 'Brazil'
|
|
9
|
+
assert_no_select 'select option[value=][disabled=disabled]'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test 'input should generate a country select with SimpleForm default' do
|
|
13
|
+
swap SimpleForm, :country_priority => [ 'Brazil' ] do
|
|
14
|
+
with_input_for @user, :country, :country
|
|
15
|
+
assert_select 'select option[value=][disabled=disabled]'
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'input should generate a time zone select field' do
|
|
20
|
+
with_input_for @user, :time_zone, :time_zone
|
|
21
|
+
assert_select 'select#user_time_zone'
|
|
22
|
+
assert_select 'select option[value=Brasilia]', '(GMT-03:00) Brasilia'
|
|
23
|
+
assert_no_select 'select option[value=][disabled=disabled]'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'input should generate a time zone select field with default' do
|
|
27
|
+
with_input_for @user, :time_zone, :time_zone, :default => 'Brasilia'
|
|
28
|
+
assert_select 'select option[value=Brasilia][selected=selected]'
|
|
29
|
+
assert_no_select 'select option[value=]'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'input should generate a time zone select using options priority' do
|
|
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=]', /^$/
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'priority input should not generate invalid required html attribute' do
|
|
39
|
+
with_input_for @user, :country, :country
|
|
40
|
+
assert_select 'select.required'
|
|
41
|
+
assert_no_select 'select[required]'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ReadonlyTest < ActionView::TestCase
|
|
4
|
+
test 'input should generate readonly elements based on the readonly option' do
|
|
5
|
+
with_input_for @user, :name, :string, :readonly => true
|
|
6
|
+
assert_select 'input.string.readonly[readonly]'
|
|
7
|
+
with_input_for @user, :description, :text, :readonly => true
|
|
8
|
+
assert_select 'textarea.text.readonly[readonly]'
|
|
9
|
+
with_input_for @user, :age, :integer, :readonly => true
|
|
10
|
+
assert_select 'input.integer.readonly[readonly]'
|
|
11
|
+
with_input_for @user, :born_at, :date, :readonly => true
|
|
12
|
+
assert_select 'select.date.readonly[readonly]'
|
|
13
|
+
with_input_for @user, :created_at, :datetime, :readonly => true
|
|
14
|
+
assert_select 'select.datetime.readonly[readonly]'
|
|
15
|
+
|
|
16
|
+
with_input_for @user, :name, :string, :readonly => false
|
|
17
|
+
assert_select 'input.string:not(.readonly[readonly])'
|
|
18
|
+
with_input_for @user, :description, :text, :readonly => false
|
|
19
|
+
assert_select 'textarea.text:not(.readonly[readonly])'
|
|
20
|
+
with_input_for @user, :age, :integer, :readonly => false
|
|
21
|
+
assert_select 'input.integer:not(.readonly[readonly])'
|
|
22
|
+
with_input_for @user, :born_at, :date, :readonly => false
|
|
23
|
+
assert_select 'select.date:not(.readonly[readonly])'
|
|
24
|
+
with_input_for @user, :created_at, :datetime, :readonly => false
|
|
25
|
+
assert_select 'select.datetime:not(.readonly[readonly])'
|
|
26
|
+
|
|
27
|
+
with_input_for @user, :name, :string
|
|
28
|
+
assert_select 'input.string:not(.readonly[readonly])'
|
|
29
|
+
with_input_for @user, :description, :text
|
|
30
|
+
assert_select 'textarea.text:not(.readonly[readonly])'
|
|
31
|
+
with_input_for @user, :age, :integer
|
|
32
|
+
assert_select 'input.integer:not(.readonly[readonly])'
|
|
33
|
+
with_input_for @user, :born_at, :date
|
|
34
|
+
assert_select 'select.date:not(.readonly[readonly])'
|
|
35
|
+
with_input_for @user, :created_at, :datetime
|
|
36
|
+
assert_select 'select.datetime:not(.readonly[readonly])'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
test 'input should generate readonly attribute when the field is readonly and the object is persisted' do
|
|
40
|
+
with_input_for @user, :credit_card, :string, :readonly => :lookup
|
|
41
|
+
assert_select 'input.string.readonly[readonly]'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test 'input should not generate readonly attribute when the field is readonly and the object is not persisted' do
|
|
45
|
+
@user.new_record!
|
|
46
|
+
with_input_for @user, :credit_card, :string, :readonly => :lookup
|
|
47
|
+
assert_no_select 'input.string.readonly[readonly]'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'input should not generate readonly attribute when the field is not readonly and the object is persisted' do
|
|
51
|
+
with_input_for @user, :name, :string
|
|
52
|
+
assert_no_select 'input.string.readonly[readonly]'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'input should not generate readonly attribute when the component is not used' do
|
|
56
|
+
swap_wrapper do
|
|
57
|
+
with_input_for @user, :credit_card, :string
|
|
58
|
+
assert_no_select 'input.string.readonly[readonly]'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|