simple_form 4.1.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +57 -9
- data/MIT-LICENSE +2 -1
- data/README.md +47 -51
- data/lib/generators/simple_form/templates/README +2 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +26 -25
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/simple_form.rb +22 -5
- data/lib/simple_form/components/labels.rb +3 -5
- data/lib/simple_form/components/maxlength.rb +0 -4
- data/lib/simple_form/components/minlength.rb +0 -4
- data/lib/simple_form/form_builder.rb +23 -3
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/inputs/base.rb +0 -3
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -5
- data/lib/simple_form/inputs/priority_input.rb +0 -4
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/tags.rb +6 -2
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +8 -3
- data/test/action_view_extensions/builder_test.rb +22 -4
- data/test/components/label_test.rb +0 -4
- data/test/form_builder/association_test.rb +6 -0
- data/test/form_builder/general_test.rb +17 -19
- data/test/form_builder/label_test.rb +1 -1
- data/test/form_builder/wrapper_test.rb +8 -1
- data/test/inputs/collection_check_boxes_input_test.rb +8 -4
- data/test/inputs/collection_radio_buttons_input_test.rb +8 -4
- data/test/inputs/collection_select_input_test.rb +6 -4
- data/test/inputs/priority_input_test.rb +4 -4
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/support/misc_helpers.rb +2 -2
- data/test/support/models.rb +28 -2
- data/test/test_helper.rb +7 -4
- metadata +16 -15
- data/lib/simple_form/i18n_cache.rb +0 -23
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class CollectionRadioButtonsInputTest < ActionView::TestCase
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionRadioButtonsInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
6
|
test 'input generates boolean radio buttons by default for radio types' do
|
11
7
|
with_input_for @user, :active, :radio_buttons
|
12
8
|
assert_select 'input[type=radio][value=true].radio_buttons#user_active_true'
|
@@ -439,4 +435,12 @@ class CollectionRadioButtonsInputTest < ActionView::TestCase
|
|
439
435
|
assert_select 'span.radio > label', '200'
|
440
436
|
end
|
441
437
|
end
|
438
|
+
|
439
|
+
test 'input check boxes with inline style support label custom classes' do
|
440
|
+
swap SimpleForm, boolean_style: :inline do
|
441
|
+
with_input_for @user, :gender, :radio_buttons, collection: %i[male female], item_label_class: 'beautiful-label'
|
442
|
+
|
443
|
+
assert_select 'label.beautiful-label', count: 2
|
444
|
+
end
|
445
|
+
end
|
442
446
|
end
|
@@ -3,10 +3,6 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
class CollectionSelectInputTest < ActionView::TestCase
|
6
|
-
setup do
|
7
|
-
SimpleForm::Inputs::CollectionSelectInput.reset_i18n_cache :boolean_collection
|
8
|
-
end
|
9
|
-
|
10
6
|
test 'input generates a boolean select with options by default for select types' do
|
11
7
|
with_input_for @user, :active, :select
|
12
8
|
assert_select 'select.select#user_active'
|
@@ -284,6 +280,12 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
284
280
|
assert_select 'select[required]'
|
285
281
|
end
|
286
282
|
|
283
|
+
test "collection input generated aria-label should contain 'true'" do
|
284
|
+
with_input_for @user, :age, :select, collection: 18..30, prompt: "Please select foo"
|
285
|
+
assert_select 'select.required'
|
286
|
+
assert_select 'select[aria-required=true]'
|
287
|
+
end
|
288
|
+
|
287
289
|
test 'collection input with select type does not generate required html attribute without blank option' do
|
288
290
|
with_input_for @user, :name, :select, include_blank: false, collection: %w[Jose Carlos]
|
289
291
|
assert_select 'select.required'
|
@@ -36,15 +36,15 @@ class PriorityInputTest < ActionView::TestCase
|
|
36
36
|
assert_no_select 'select option[value=""]', /^$/
|
37
37
|
end
|
38
38
|
|
39
|
-
test 'priority input does
|
39
|
+
test 'priority input does generate select element with required html attribute' do
|
40
40
|
with_input_for @user, :country, :country
|
41
41
|
assert_select 'select.required'
|
42
|
-
|
42
|
+
assert_select 'select[required]'
|
43
43
|
end
|
44
44
|
|
45
|
-
test 'priority input does
|
45
|
+
test 'priority input does generate select element with aria-required html attribute' do
|
46
46
|
with_input_for @user, :country, :country
|
47
47
|
assert_select 'select.required'
|
48
|
-
|
48
|
+
assert_select 'select[aria-required]'
|
49
49
|
end
|
50
50
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: UTF-8
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class RichTextAreaInputTest < ActionView::TestCase
|
6
|
+
test 'input generates a text area for text attributes' do
|
7
|
+
with_input_for @user, :description, :text
|
8
|
+
assert_select 'textarea.text#user_description'
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'input generates a text area for text attributes that accept placeholder' do
|
12
|
+
with_input_for @user, :description, :text, placeholder: 'Put in some text'
|
13
|
+
assert_select 'textarea.text[placeholder="Put in some text"]'
|
14
|
+
end
|
15
|
+
end
|
@@ -213,8 +213,8 @@ module MiscHelpers
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
def custom_wrapper_with_input_valid_class
|
217
|
-
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class:
|
216
|
+
def custom_wrapper_with_input_valid_class(valid_class: :field_without_errors)
|
217
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: valid_class do |b|
|
218
218
|
b.use :label
|
219
219
|
b.use :input, class: 'inline-class', valid_class: 'is-valid'
|
220
220
|
end
|
data/test/support/models.rb
CHANGED
@@ -76,7 +76,11 @@ Friend = Struct.new(:id, :name) do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class Tag < Company
|
79
|
+
class Tag < Company
|
80
|
+
def group_method
|
81
|
+
["category-1"]
|
82
|
+
end
|
83
|
+
end
|
80
84
|
|
81
85
|
TagGroup = Struct.new(:id, :name, :tags)
|
82
86
|
|
@@ -200,7 +204,7 @@ class User
|
|
200
204
|
|
201
205
|
def self.human_attribute_name(attribute, options = {})
|
202
206
|
case attribute
|
203
|
-
when 'name'
|
207
|
+
when 'name', :name
|
204
208
|
'Super User Name!'
|
205
209
|
when 'description'
|
206
210
|
'User Description!'
|
@@ -329,3 +333,25 @@ end
|
|
329
333
|
|
330
334
|
class UserNumber1And2 < User
|
331
335
|
end
|
336
|
+
|
337
|
+
class UserWithAttachment < User
|
338
|
+
def avatar_attachment
|
339
|
+
OpenStruct.new
|
340
|
+
end
|
341
|
+
|
342
|
+
def avatars_attachments
|
343
|
+
OpenStruct.new
|
344
|
+
end
|
345
|
+
|
346
|
+
def remote_cover_url
|
347
|
+
"/uploads/cover.png"
|
348
|
+
end
|
349
|
+
|
350
|
+
def profile_image_attacher
|
351
|
+
OpenStruct.new
|
352
|
+
end
|
353
|
+
|
354
|
+
def portrait_file_name
|
355
|
+
"portrait.png"
|
356
|
+
end
|
357
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
2
|
require 'minitest/autorun'
|
5
3
|
|
6
4
|
require 'active_model'
|
7
5
|
require 'action_controller'
|
8
6
|
require 'action_view'
|
7
|
+
|
9
8
|
ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
|
10
9
|
|
11
10
|
require 'action_view/template'
|
12
|
-
|
13
11
|
require 'action_view/test_case'
|
14
12
|
|
15
13
|
module Rails
|
@@ -41,10 +39,14 @@ if ActiveSupport::TestCase.respond_to?(:test_order=)
|
|
41
39
|
ActiveSupport::TestCase.test_order = :random
|
42
40
|
end
|
43
41
|
|
42
|
+
require "rails/test_unit/line_filtering"
|
43
|
+
|
44
44
|
class ActionView::TestCase
|
45
45
|
include MiscHelpers
|
46
46
|
include SimpleForm::ActionViewExtensions::FormHelper
|
47
47
|
|
48
|
+
extend Rails::LineFiltering
|
49
|
+
|
48
50
|
setup :set_controller
|
49
51
|
setup :setup_users
|
50
52
|
|
@@ -58,7 +60,7 @@ class ActionView::TestCase
|
|
58
60
|
|
59
61
|
@validating_user = ValidatingUser.build({
|
60
62
|
name: 'Tester McTesterson',
|
61
|
-
description: 'A test user of the most
|
63
|
+
description: 'A test user of the most distinguished caliber',
|
62
64
|
home_picture: 'Home picture',
|
63
65
|
age: 19,
|
64
66
|
amount: 15,
|
@@ -89,4 +91,5 @@ class ActionView::TestCase
|
|
89
91
|
alias :validating_user_path :user_path
|
90
92
|
alias :validating_users_path :user_path
|
91
93
|
alias :other_validating_user_path :user_path
|
94
|
+
alias :user_with_attachment_path :user_path
|
92
95
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Carlos Antônio
|
9
9
|
- Rafael França
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -18,30 +18,30 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '5.
|
21
|
+
version: '5.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '5.
|
28
|
+
version: '5.2'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: actionpack
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '5.
|
35
|
+
version: '5.2'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '5.
|
42
|
+
version: '5.2'
|
43
43
|
description: Forms made easy!
|
44
|
-
email:
|
44
|
+
email: heartcombo@googlegroups.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- lib/simple_form/helpers/readonly.rb
|
83
83
|
- lib/simple_form/helpers/required.rb
|
84
84
|
- lib/simple_form/helpers/validators.rb
|
85
|
-
- lib/simple_form/i18n_cache.rb
|
86
85
|
- lib/simple_form/inputs.rb
|
87
86
|
- lib/simple_form/inputs/base.rb
|
88
87
|
- lib/simple_form/inputs/block_input.rb
|
@@ -100,6 +99,7 @@ files:
|
|
100
99
|
- lib/simple_form/inputs/password_input.rb
|
101
100
|
- lib/simple_form/inputs/priority_input.rb
|
102
101
|
- lib/simple_form/inputs/range_input.rb
|
102
|
+
- lib/simple_form/inputs/rich_text_area_input.rb
|
103
103
|
- lib/simple_form/inputs/string_input.rb
|
104
104
|
- lib/simple_form/inputs/text_input.rb
|
105
105
|
- lib/simple_form/map_type.rb
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- test/inputs/priority_input_test.rb
|
143
143
|
- test/inputs/readonly_test.rb
|
144
144
|
- test/inputs/required_test.rb
|
145
|
+
- test/inputs/rich_text_area_input_test.rb
|
145
146
|
- test/inputs/string_input_test.rb
|
146
147
|
- test/inputs/text_input_test.rb
|
147
148
|
- test/simple_form_test.rb
|
@@ -150,11 +151,11 @@ files:
|
|
150
151
|
- test/support/mock_controller.rb
|
151
152
|
- test/support/models.rb
|
152
153
|
- test/test_helper.rb
|
153
|
-
homepage: https://github.com/
|
154
|
+
homepage: https://github.com/heartcombo/simple_form
|
154
155
|
licenses:
|
155
156
|
- MIT
|
156
157
|
metadata: {}
|
157
|
-
post_install_message:
|
158
|
+
post_install_message:
|
158
159
|
rdoc_options: []
|
159
160
|
require_paths:
|
160
161
|
- lib
|
@@ -162,16 +163,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
163
|
requirements:
|
163
164
|
- - ">="
|
164
165
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
166
|
+
version: 2.5.0
|
166
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
168
|
requirements:
|
168
169
|
- - ">="
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.2.6
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Forms made easy!
|
177
177
|
test_files:
|
@@ -197,6 +197,7 @@ test_files:
|
|
197
197
|
- test/simple_form_test.rb
|
198
198
|
- test/inputs/string_input_test.rb
|
199
199
|
- test/inputs/numeric_input_test.rb
|
200
|
+
- test/inputs/rich_text_area_input_test.rb
|
200
201
|
- test/inputs/readonly_test.rb
|
201
202
|
- test/inputs/grouped_collection_select_input_test.rb
|
202
203
|
- test/inputs/text_input_test.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module SimpleForm
|
3
|
-
# A lot of configuration values are retrived from I18n,
|
4
|
-
# like boolean collection, required string. This module provides
|
5
|
-
# caching facility to speed up form construction.
|
6
|
-
module I18nCache
|
7
|
-
def i18n_cache(key)
|
8
|
-
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_i18n_cache(key)
|
12
|
-
if class_variable_defined?(:"@@#{key}")
|
13
|
-
class_variable_get(:"@@#{key}")
|
14
|
-
else
|
15
|
-
reset_i18n_cache(key)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset_i18n_cache(key)
|
20
|
-
class_variable_set(:"@@#{key}", {})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|