simple_form 3.1.0.rc2 → 3.1.0
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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +27 -10
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +3 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +8 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
- data/lib/simple_form.rb +13 -2
- 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/form_builder.rb +5 -4
- data/lib/simple_form/inputs/boolean_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/tags.rb +2 -4
- data/lib/simple_form/version.rb +1 -1
- data/test/action_view_extensions/builder_test.rb +31 -31
- data/test/action_view_extensions/form_helper_test.rb +20 -1
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +37 -37
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_test.rb +70 -11
- data/test/form_builder/general_test.rb +24 -4
- data/test/form_builder/hint_test.rb +3 -3
- data/test/form_builder/input_field_test.rb +43 -3
- data/test/form_builder/label_test.rb +1 -1
- data/test/form_builder/wrapper_test.rb +18 -3
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +9 -1
- data/test/inputs/collection_check_boxes_input_test.rb +22 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +25 -3
- data/test/inputs/collection_select_input_test.rb +17 -17
- data/test/inputs/datetime_input_test.rb +1 -1
- data/test/inputs/grouped_collection_select_input_test.rb +8 -8
- data/test/inputs/numeric_input_test.rb +19 -19
- data/test/inputs/priority_input_test.rb +6 -6
- data/test/inputs/string_input_test.rb +10 -10
- data/test/inputs/text_input_test.rb +3 -3
- data/test/support/misc_helpers.rb +6 -0
- data/test/support/models.rb +11 -1
- data/test/test_helper.rb +5 -1
- metadata +4 -4
@@ -6,13 +6,13 @@ class PriorityInputTest < ActionView::TestCase
|
|
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
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
|
|
@@ -20,19 +20,19 @@ class PriorityInputTest < ActionView::TestCase
|
|
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
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
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
38
|
test 'priority input does not generate invalid required html attribute' do
|
@@ -4,7 +4,7 @@ require 'test_helper'
|
|
4
4
|
class StringInputTest < ActionView::TestCase
|
5
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
10
|
test 'input generates a password field for password attributes' do
|
@@ -14,7 +14,7 @@ class StringInputTest < ActionView::TestCase
|
|
14
14
|
|
15
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
20
|
test 'input does not get maxlength from column without size definition for string attributes' do
|
@@ -24,12 +24,12 @@ class StringInputTest < ActionView::TestCase
|
|
24
24
|
|
25
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
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
35
|
test 'input does not get maxlength from validation when tokenizer present' do
|
@@ -39,13 +39,13 @@ class StringInputTest < ActionView::TestCase
|
|
39
39
|
|
40
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
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
51
|
test 'input does not generate placeholder by default' do
|
@@ -55,12 +55,12 @@ class StringInputTest < ActionView::TestCase
|
|
55
55
|
|
56
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
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
66
|
test 'input does not infer pattern from attributes by default' do
|
@@ -100,7 +100,7 @@ class StringInputTest < ActionView::TestCase
|
|
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
|
|
@@ -110,7 +110,7 @@ class StringInputTest < ActionView::TestCase
|
|
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
|
@@ -9,16 +9,16 @@ class TextInputTest < ActionView::TestCase
|
|
9
9
|
|
10
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
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
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
|
@@ -178,6 +178,12 @@ module MiscHelpers
|
|
178
178
|
end
|
179
179
|
end
|
180
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
|
+
|
181
187
|
def custom_form_for(object, *args, &block)
|
182
188
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
183
189
|
end
|
data/test/support/models.rb
CHANGED
@@ -130,6 +130,16 @@ class User
|
|
130
130
|
Column.new(attribute, column_type, limit)
|
131
131
|
end
|
132
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
|
+
|
133
143
|
def self.human_attribute_name(attribute, options = {})
|
134
144
|
case attribute
|
135
145
|
when 'name'
|
@@ -165,7 +175,7 @@ class User
|
|
165
175
|
def errors
|
166
176
|
@errors ||= begin
|
167
177
|
errors = ActiveModel::Errors.new(self)
|
168
|
-
errors.add(:name, "
|
178
|
+
errors.add(:name, "cannot be blank")
|
169
179
|
errors.add(:description, 'must be longer than 15 characters')
|
170
180
|
errors.add(:age, 'is not a number')
|
171
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
|