simple_form 3.0.0.beta1 → 3.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/README.md +16 -10
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +5 -2
- data/lib/simple_form.rb +8 -0
- data/lib/simple_form/action_view_extensions/builder.rb +1 -1
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -8
- data/lib/simple_form/components/html5.rb +4 -1
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/form_builder.rb +4 -4
- data/lib/simple_form/version.rb +1 -1
- data/test/action_view_extensions/builder_test.rb +8 -8
- data/test/action_view_extensions/form_helper_test.rb +9 -0
- data/test/form_builder/association_test.rb +16 -6
- data/test/form_builder/general_test.rb +16 -10
- data/test/form_builder/hint_test.rb +1 -1
- data/test/inputs/collection_check_boxes_input_test.rb +7 -1
- data/test/inputs/collection_radio_buttons_input_test.rb +11 -5
- data/test/inputs/collection_select_input_test.rb +32 -7
- data/test/inputs/datetime_input_test.rb +6 -0
- data/test/inputs/hidden_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +6 -0
- data/test/inputs/string_input_test.rb +5 -0
- data/test/support/misc_helpers.rb +25 -3
- data/test/support/models.rb +27 -20
- data/test/test_helper.rb +1 -5
- metadata +17 -28
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eebdc48d53472ed80e668fd6c2fa30ebf30695a1
|
4
|
+
data.tar.gz: 368a258b70c60fcb73ed568a21f357b39c1fa93f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd1c37c0fffa1d3f3b5a06d19790f37a6aec133ab9d98d792c0c60ba40ea64628085ef8f26ab8f44a50bb17af3b0ee3e8dfdcd6d2997dfea021bc41240c300ed
|
7
|
+
data.tar.gz: ee7024a3684a698d0267fd2469723bfca7775270f064b0e11680cc85891c8d6d235189bd608d636fc551c7d3726b3d8167577ebc49869bc8c6969254c7ee5d00
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
### enhancements
|
4
|
+
* Make `field_error_proc` configurable [@dfens](https://github.com/dfens)
|
5
|
+
|
6
|
+
### bug fix
|
7
|
+
* Remove deprecation warnings related to `Relation#all` from Rails 4.
|
8
|
+
* Form builder can be used outside the context of a controller [@jasonwebster](https://github.com/jasonwebster)
|
9
|
+
* Skip pattern attribute when using `validates_format_of` with `:without` option [@glebm](https://github.com/glebm)
|
10
|
+
|
1
11
|
## 3.0.0.beta1
|
2
12
|
|
3
13
|
### enhancements
|
@@ -5,5 +15,6 @@
|
|
5
15
|
* Removed deprecated methods.
|
6
16
|
* SimpleForm no longer sets the `size` attribute automatically and the `default_input_size` setting
|
7
17
|
is now deprecated.
|
18
|
+
* Support to aria-required attribute to required fields [@ckundo](https://github.com/ckundo)
|
8
19
|
|
9
20
|
Please check [v2.1](https://github.com/plataformatec/simple_form/blob/v2.1/CHANGELOG.md) for previous changes.
|
data/README.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
![Simple Form Logo](https://raw.github.com/plataformatec/simple_form/master/simple_form.png)
|
2
|
+
|
3
|
+
By [Plataformatec](http://plataformatec.com.br/).
|
4
|
+
|
5
|
+
[![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
|
6
|
+
[![Build Status](https://api.travis-ci.org/plataformatec/simple_form.png?branch=master)](http://travis-ci.org/plataformatec/simple_form)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/plataformatec/simple_form.png)](https://codeclimate.com/github/plataformatec/simple_form)
|
8
|
+
|
9
|
+
Rails forms made easy.
|
3
10
|
|
4
11
|
**SimpleForm** aims to be as flexible as possible while helping you with powerful components to create
|
5
12
|
your forms. The basic goal of SimpleForm is to not touch your way of defining the layout, letting
|
@@ -7,10 +14,7 @@ you find the better design for your eyes. Most of the DSL was inherited from For
|
|
7
14
|
which we are thankful for and should make you feel right at home.
|
8
15
|
|
9
16
|
INFO: This README is [also available in a friendly navigable format](http://simple-form.plataformatec.com.br/)
|
10
|
-
and refers to **SimpleForm**
|
11
|
-
check this branch:
|
12
|
-
|
13
|
-
https://github.com/plataformatec/simple_form/tree/v1.5
|
17
|
+
and refers to **SimpleForm** 3.0. For older releases, check the related branch for your version.
|
14
18
|
|
15
19
|
## Installation
|
16
20
|
|
@@ -41,7 +45,7 @@ gem 'country_select'
|
|
41
45
|
|
42
46
|
### Twitter Bootstrap
|
43
47
|
|
44
|
-
**SimpleForm**
|
48
|
+
**SimpleForm** can be easily integrated to the [Twitter Bootstrap](http://twitter.github.com/bootstrap).
|
45
49
|
To do that you have to use the `bootstrap` option in the install generator, like this:
|
46
50
|
|
47
51
|
```console
|
@@ -67,7 +71,7 @@ rails generate simple_form:install --foundation
|
|
67
71
|
|
68
72
|
Please note that the Foundation wrapper does not support the `:hint` option by default. In order to enable hints, please uncomment the appropriate line in `config/initializers/simple_form_foundation.rb`. You will need to provide your own CSS styles for hints.
|
69
73
|
|
70
|
-
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/rails.php).
|
74
|
+
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/old-docs/f3/rails.php).
|
71
75
|
|
72
76
|
## Usage
|
73
77
|
|
@@ -809,7 +813,7 @@ end
|
|
809
813
|
|
810
814
|
**SimpleForm** also allows you to use optional elements. For instance, let's suppose you want to use
|
811
815
|
hints or placeholders, but you don't want them to be generated automatically. You can set their
|
812
|
-
default values to `false` or use the `optional` method. Is
|
816
|
+
default values to `false` or use the `optional` method. Is preferable to use the `optional` syntax:
|
813
817
|
|
814
818
|
```ruby
|
815
819
|
config.wrappers placeholder: false do |b|
|
@@ -823,7 +827,7 @@ end
|
|
823
827
|
```
|
824
828
|
|
825
829
|
By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
|
826
|
-
The same for
|
830
|
+
The same for placeholder.
|
827
831
|
|
828
832
|
## HTML 5 Notice
|
829
833
|
|
@@ -902,3 +906,5 @@ https://github.com/plataformatec/simple_form/issues
|
|
902
906
|
## License
|
903
907
|
|
904
908
|
MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br
|
909
|
+
|
910
|
+
You are not granted rights or licenses to the trademarks of the Plataformatec, including without limitation the Simple Form name or logo.
|
@@ -106,8 +106,11 @@ SimpleForm.setup do |config|
|
|
106
106
|
# Whether attributes are required by default (or not). Default is true.
|
107
107
|
# config.required_by_default = true
|
108
108
|
|
109
|
-
# Tell browsers whether to use
|
110
|
-
#
|
109
|
+
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
|
110
|
+
# These validations are enabled in SimpleForm's internal config but disabled by default
|
111
|
+
# in this configuration, which is recommended due to some quirks from different browsers.
|
112
|
+
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
|
113
|
+
# change this configuration to true.
|
111
114
|
config.browser_validations = false
|
112
115
|
|
113
116
|
# Collection of methods to detect if a file type was given.
|
data/lib/simple_form.rb
CHANGED
@@ -139,6 +139,14 @@ module SimpleForm
|
|
139
139
|
mattr_accessor :button_class
|
140
140
|
@@button_class = 'button'
|
141
141
|
|
142
|
+
# Override the default ActiveModelHelper behaviour of wrapping the input.
|
143
|
+
# This gets taken care of semantically by adding an error class to the wrapper tag
|
144
|
+
# containing the input.
|
145
|
+
mattr_accessor :field_error_proc
|
146
|
+
@@field_error_proc = proc do |html_tag, instance_tag|
|
147
|
+
html_tag
|
148
|
+
end
|
149
|
+
|
142
150
|
## WRAPPER CONFIGURATION
|
143
151
|
# The default wrapper to be used by the FormBuilder.
|
144
152
|
mattr_accessor :default_wrapper
|
@@ -9,13 +9,6 @@ module SimpleForm
|
|
9
9
|
# end
|
10
10
|
#
|
11
11
|
module FormHelper
|
12
|
-
# Override the default ActiveRecordHelper behaviour of wrapping the input.
|
13
|
-
# This gets taken care of semantically by adding an error class to the wrapper tag
|
14
|
-
# containing the input.
|
15
|
-
#
|
16
|
-
FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
|
17
|
-
html_tag
|
18
|
-
end
|
19
12
|
|
20
13
|
def simple_form_for(record, options={}, &block)
|
21
14
|
options[:builder] ||= SimpleForm::FormBuilder
|
@@ -44,7 +37,7 @@ module SimpleForm
|
|
44
37
|
def with_simple_form_field_error_proc
|
45
38
|
default_field_error_proc = ::ActionView::Base.field_error_proc
|
46
39
|
begin
|
47
|
-
::ActionView::Base.field_error_proc =
|
40
|
+
::ActionView::Base.field_error_proc = SimpleForm.field_error_proc
|
48
41
|
yield
|
49
42
|
ensure
|
50
43
|
::ActionView::Base.field_error_proc = default_field_error_proc
|
@@ -13,8 +13,8 @@ module SimpleForm
|
|
13
13
|
pattern = options[:pattern]
|
14
14
|
if pattern.is_a?(String)
|
15
15
|
pattern
|
16
|
-
elsif pattern_validator = find_pattern_validator
|
17
|
-
evaluate_format_validator_option(
|
16
|
+
elsif (pattern_validator = find_pattern_validator) && (with = pattern_validator.options[:with])
|
17
|
+
evaluate_format_validator_option(with).source
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -180,7 +180,7 @@ module SimpleForm
|
|
180
180
|
|
181
181
|
options[:as] ||= :select
|
182
182
|
options[:collection] ||= options.fetch(:collection) {
|
183
|
-
reflection.klass.
|
183
|
+
reflection.klass.where(reflection.options[:conditions]).order(reflection.options[:order]).to_a
|
184
184
|
}
|
185
185
|
|
186
186
|
attribute = case reflection.macro
|
@@ -443,7 +443,7 @@ module SimpleForm
|
|
443
443
|
# route[blocks_attributes][0][blocks_learning_object_attributes][1][foo_attributes]
|
444
444
|
# ["route", "blocks", "blocks_learning_object", "foo"]
|
445
445
|
#
|
446
|
-
def lookup_model_names
|
446
|
+
def lookup_model_names #:nodoc:
|
447
447
|
@lookup_model_names ||= begin
|
448
448
|
child_index = options[:child_index]
|
449
449
|
names = object_name.to_s.scan(/([a-zA-Z_]+)/).flatten
|
@@ -454,9 +454,9 @@ module SimpleForm
|
|
454
454
|
end
|
455
455
|
|
456
456
|
# The action to be used in lookup.
|
457
|
-
def lookup_action
|
457
|
+
def lookup_action #:nodoc:
|
458
458
|
@lookup_action ||= begin
|
459
|
-
action = template.controller.action_name
|
459
|
+
action = template.controller && template.controller.action_name
|
460
460
|
return unless action
|
461
461
|
action = action.to_sym
|
462
462
|
ACTIONS[action] || action
|
data/lib/simple_form/version.rb
CHANGED
@@ -299,7 +299,7 @@ class BuilderTest < ActionView::TestCase
|
|
299
299
|
test "collection check box checks the correct value to local variables" do
|
300
300
|
user = User.new
|
301
301
|
user.tag_ids = [1, 3]
|
302
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
302
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
303
303
|
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
304
304
|
|
305
305
|
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
@@ -308,7 +308,7 @@ class BuilderTest < ActionView::TestCase
|
|
308
308
|
end
|
309
309
|
|
310
310
|
test "collection check box accepts selected values as :checked option" do
|
311
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
311
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
312
312
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
313
313
|
|
314
314
|
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
@@ -317,7 +317,7 @@ class BuilderTest < ActionView::TestCase
|
|
317
317
|
end
|
318
318
|
|
319
319
|
test "collection check boxes accepts selected string values as :checked option" do
|
320
|
-
collection = (1..3).map{|i| [i, "Category #{i}"] }
|
320
|
+
collection = (1..3).map { |i| [i, "Category #{i}"] }
|
321
321
|
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
|
322
322
|
|
323
323
|
assert_select 'input[type=checkbox][value=1][checked=checked]'
|
@@ -326,7 +326,7 @@ class BuilderTest < ActionView::TestCase
|
|
326
326
|
end
|
327
327
|
|
328
328
|
test "collection check box accepts a single checked value" do
|
329
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
329
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
330
330
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
|
331
331
|
|
332
332
|
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
@@ -335,7 +335,7 @@ class BuilderTest < ActionView::TestCase
|
|
335
335
|
end
|
336
336
|
|
337
337
|
test "collection check box accepts selected values as :checked option and override the model values" do
|
338
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
338
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
339
339
|
@user.tag_ids = [2]
|
340
340
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
341
341
|
|
@@ -345,7 +345,7 @@ class BuilderTest < ActionView::TestCase
|
|
345
345
|
end
|
346
346
|
|
347
347
|
test "collection check box accepts multiple disabled items" do
|
348
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
348
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
349
349
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
|
350
350
|
|
351
351
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
@@ -354,7 +354,7 @@ class BuilderTest < ActionView::TestCase
|
|
354
354
|
end
|
355
355
|
|
356
356
|
test "collection check box accepts single disable item" do
|
357
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
357
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
358
358
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
|
359
359
|
|
360
360
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
@@ -363,7 +363,7 @@ class BuilderTest < ActionView::TestCase
|
|
363
363
|
end
|
364
364
|
|
365
365
|
test "collection check box accepts a proc to disabled items" do
|
366
|
-
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
366
|
+
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
367
367
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
|
368
368
|
|
369
369
|
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
@@ -131,6 +131,15 @@ class FormHelperTest < ActionView::TestCase
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
+
test 'SimpleForm for swaps default action view field_error_proc' do
|
135
|
+
expected_error_proc = lambda {}
|
136
|
+
swap SimpleForm, field_error_proc: expected_error_proc do
|
137
|
+
simple_form_for :user do |f|
|
138
|
+
assert_equal expected_error_proc, ::ActionView::Base.field_error_proc
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
134
143
|
private
|
135
144
|
|
136
145
|
def swap_field_error_proc(expected_error_proc = lambda {})
|
@@ -41,36 +41,46 @@ class AssociationTest < ActionView::TestCase
|
|
41
41
|
end
|
42
42
|
|
43
43
|
test 'builder preloads collection association' do
|
44
|
-
value = @user.tags =
|
45
|
-
value.
|
44
|
+
value = @user.tags = MiniTest::Mock.new
|
45
|
+
value.expect(:to_a, value)
|
46
46
|
|
47
47
|
with_association_for @user, :tags
|
48
48
|
assert_select 'form select.select#user_tag_ids'
|
49
49
|
assert_select 'form select option[value=1]', 'Tag 1'
|
50
50
|
assert_select 'form select option[value=2]', 'Tag 2'
|
51
51
|
assert_select 'form select option[value=3]', 'Tag 3'
|
52
|
+
|
53
|
+
value.verify
|
52
54
|
end
|
53
55
|
|
54
56
|
test 'builder does not preload collection association if preload is false' do
|
55
|
-
value = @user.tags =
|
56
|
-
value.
|
57
|
+
value = @user.tags = MiniTest::Mock.new
|
58
|
+
value.expect(:to_a, nil)
|
57
59
|
|
58
60
|
with_association_for @user, :tags, preload: false
|
59
61
|
assert_select 'form select.select#user_tag_ids'
|
60
62
|
assert_select 'form select option[value=1]', 'Tag 1'
|
61
63
|
assert_select 'form select option[value=2]', 'Tag 2'
|
62
64
|
assert_select 'form select option[value=3]', 'Tag 3'
|
65
|
+
|
66
|
+
assert_raises MockExpectationError do
|
67
|
+
value.verify
|
68
|
+
end
|
63
69
|
end
|
64
70
|
|
65
71
|
test 'builder does not preload non-collection association' do
|
66
|
-
value = @user.company =
|
67
|
-
value.
|
72
|
+
value = @user.company = MiniTest::Mock.new
|
73
|
+
value.expect(:to_a, nil)
|
68
74
|
|
69
75
|
with_association_for @user, :company
|
70
76
|
assert_select 'form select.select#user_company_id'
|
71
77
|
assert_select 'form select option[value=1]', 'Company 1'
|
72
78
|
assert_select 'form select option[value=2]', 'Company 2'
|
73
79
|
assert_select 'form select option[value=3]', 'Company 3'
|
80
|
+
|
81
|
+
assert_raises MockExpectationError do
|
82
|
+
value.verify
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
86
|
# ASSOCIATIONS - BELONGS TO
|
@@ -22,6 +22,14 @@ class FormBuilderTest < ActionView::TestCase
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
test 'builder should work without controller' do
|
26
|
+
stub_any_instance ActionView::TestCase, :controller, nil do
|
27
|
+
simple_form_for @user do |f|
|
28
|
+
assert f.input(:name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
test 'builder input should allow a block to configure input' do
|
26
34
|
with_form_for @user, :name do
|
27
35
|
text_field_tag :foo, :bar, id: :cool
|
@@ -156,18 +164,16 @@ class FormBuilderTest < ActionView::TestCase
|
|
156
164
|
end
|
157
165
|
|
158
166
|
test 'builder should generate file for file columns' do
|
159
|
-
@user.avatar =
|
160
|
-
@user.avatar.
|
161
|
-
@user.avatar.expects(:respond_to?).with(:file?).returns(false)
|
162
|
-
@user.avatar.expects(:respond_to?).with(:public_filename).returns(true)
|
167
|
+
@user.avatar = MiniTest::Mock.new
|
168
|
+
@user.avatar.expect(:public_filename, true)
|
163
169
|
|
164
170
|
with_form_for @user, :avatar
|
165
171
|
assert_select 'form input#user_avatar.file'
|
166
172
|
end
|
167
173
|
|
168
174
|
test 'builder should generate file for attributes that are real db columns but have file methods' do
|
169
|
-
@user.home_picture =
|
170
|
-
@user.home_picture.
|
175
|
+
@user.home_picture = MiniTest::Mock.new
|
176
|
+
@user.home_picture.expect(:mounted_as, true)
|
171
177
|
|
172
178
|
with_form_for @user, :home_picture
|
173
179
|
assert_select 'form input#user_home_picture.file'
|
@@ -264,10 +270,10 @@ class FormBuilderTest < ActionView::TestCase
|
|
264
270
|
|
265
271
|
test 'builder should be able to disable a hint even if it exists in i18n' do
|
266
272
|
store_translations(:en, simple_form: { hints: { name: 'Hint test' } }) do
|
267
|
-
SimpleForm::Inputs::Base
|
268
|
-
|
269
|
-
|
270
|
-
|
273
|
+
stub_any_instance(SimpleForm::Inputs::Base, :hint, -> { raise 'Never' }) do
|
274
|
+
with_form_for @user, :name, hint: false
|
275
|
+
assert_no_select 'span.hint'
|
276
|
+
end
|
271
277
|
end
|
272
278
|
end
|
273
279
|
|
@@ -94,7 +94,7 @@ class HintTest < ActionView::TestCase
|
|
94
94
|
|
95
95
|
test 'hint should use i18n under defaults namespace to lookup translation' do
|
96
96
|
store_translations(:en, simple_form: {
|
97
|
-
hints: {defaults: {name: 'Content of this input will be downcased...' } }
|
97
|
+
hints: { defaults: { name: 'Content of this input will be downcased...' } }
|
98
98
|
}) do
|
99
99
|
with_hint_for @user, :name
|
100
100
|
assert_select 'span.hint', 'Content of this input will be downcased...'
|
@@ -18,11 +18,17 @@ class CollectionCheckBoxesInputTest < ActionView::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'collection input with check_boxes type should not generate required html attribute' do
|
21
|
-
with_input_for @user, :name, :check_boxes, collection: ['Jose'
|
21
|
+
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
22
22
|
assert_select 'input.required'
|
23
23
|
assert_no_select 'input[required]'
|
24
24
|
end
|
25
25
|
|
26
|
+
test 'collection input with check_boxes type should not generate aria-required html attribute' do
|
27
|
+
with_input_for @user, :name, :check_boxes, collection: ['Jose', 'Carlos']
|
28
|
+
assert_select 'input.required'
|
29
|
+
assert_no_select 'input[aria-required]'
|
30
|
+
end
|
31
|
+
|
26
32
|
test 'input should do automatic collection translation for check_box types using defaults key' do
|
27
33
|
store_translations(:en, simple_form: { options: { defaults: {
|
28
34
|
gender: { male: 'Male', female: 'Female'}
|
@@ -98,7 +98,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
98
98
|
|
99
99
|
test 'input should allow overriding only label method for collections' do
|
100
100
|
with_input_for @user, :name, :radio_buttons,
|
101
|
-
collection: ['Jose'
|
101
|
+
collection: ['Jose', 'Carlos'],
|
102
102
|
label_method: :upcase
|
103
103
|
assert_select 'label.collection_radio_buttons', 'JOSE'
|
104
104
|
assert_select 'label.collection_radio_buttons', 'CARLOS'
|
@@ -106,7 +106,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
106
106
|
|
107
107
|
test 'input should allow overriding only value method for collections' do
|
108
108
|
with_input_for @user, :name, :radio_buttons,
|
109
|
-
collection: ['Jose'
|
109
|
+
collection: ['Jose', 'Carlos'],
|
110
110
|
value_method: :upcase
|
111
111
|
assert_select 'input[type=radio][value=JOSE]'
|
112
112
|
assert_select 'input[type=radio][value=CARLOS]'
|
@@ -114,7 +114,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
114
114
|
|
115
115
|
test 'input should allow overriding label and value method for collections' do
|
116
116
|
with_input_for @user, :name, :radio_buttons,
|
117
|
-
collection: ['Jose'
|
117
|
+
collection: ['Jose', 'Carlos'],
|
118
118
|
label_method: :upcase,
|
119
119
|
value_method: :downcase
|
120
120
|
assert_select 'input[type=radio][value=jose]'
|
@@ -125,7 +125,7 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
125
125
|
|
126
126
|
test 'input should allow overriding label and value method using a lambda for collections' do
|
127
127
|
with_input_for @user, :name, :radio_buttons,
|
128
|
-
collection: ['Jose'
|
128
|
+
collection: ['Jose', 'Carlos'],
|
129
129
|
label_method: lambda { |i| i.upcase },
|
130
130
|
value_method: lambda { |i| i.downcase }
|
131
131
|
assert_select 'input[type=radio][value=jose]'
|
@@ -135,11 +135,17 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
135
135
|
end
|
136
136
|
|
137
137
|
test 'collection input with radio type should generate required html attribute' do
|
138
|
-
with_input_for @user, :name, :radio_buttons, collection: ['Jose'
|
138
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
139
139
|
assert_select 'input[type=radio].required'
|
140
140
|
assert_select 'input[type=radio][required]'
|
141
141
|
end
|
142
142
|
|
143
|
+
test 'collection input with radio type should generate aria-required html attribute' do
|
144
|
+
with_input_for @user, :name, :radio_buttons, collection: ['Jose', 'Carlos']
|
145
|
+
assert_select 'input[type=radio].required'
|
146
|
+
assert_select 'input[type=radio][aria-required=true]'
|
147
|
+
end
|
148
|
+
|
143
149
|
test 'input radio does not wrap the collection by default' do
|
144
150
|
with_input_for @user, :active, :radio_buttons
|
145
151
|
|