simple_form 3.3.1 → 3.5.1
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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +43 -33
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/_form.html.erb +1 -0
- data/lib/generators/simple_form/templates/_form.html.haml +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +5 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +6 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +7 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
- data/lib/simple_form/components/errors.rb +2 -1
- data/lib/simple_form/components/hints.rb +1 -0
- data/lib/simple_form/components/html5.rb +1 -0
- data/lib/simple_form/components/label_input.rb +2 -1
- data/lib/simple_form/components/labels.rb +2 -1
- data/lib/simple_form/components/maxlength.rb +1 -0
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +48 -0
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +1 -0
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +2 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +9 -3
- data/lib/simple_form/helpers/autofocus.rb +1 -0
- data/lib/simple_form/helpers/disabled.rb +1 -0
- data/lib/simple_form/helpers/readonly.rb +1 -0
- data/lib/simple_form/helpers/required.rb +1 -0
- data/lib/simple_form/helpers/validators.rb +2 -1
- data/lib/simple_form/helpers.rb +1 -0
- data/lib/simple_form/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs/base.rb +4 -2
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +9 -4
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +7 -5
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
- data/lib/simple_form/inputs/collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/date_time_input.rb +1 -0
- data/lib/simple_form/inputs/file_input.rb +1 -0
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
- data/lib/simple_form/inputs/hidden_input.rb +1 -0
- data/lib/simple_form/inputs/numeric_input.rb +1 -0
- data/lib/simple_form/inputs/password_input.rb +2 -1
- data/lib/simple_form/inputs/priority_input.rb +1 -0
- data/lib/simple_form/inputs/range_input.rb +1 -0
- data/lib/simple_form/inputs/string_input.rb +2 -1
- data/lib/simple_form/inputs/text_input.rb +2 -1
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/map_type.rb +1 -0
- data/lib/simple_form/railtie.rb +1 -0
- data/lib/simple_form/tags.rb +1 -0
- data/lib/simple_form/version.rb +2 -1
- data/lib/simple_form/wrappers/builder.rb +1 -0
- data/lib/simple_form/wrappers/leaf.rb +2 -1
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form/wrappers/root.rb +1 -0
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +9 -6
- data/test/action_view_extensions/builder_test.rb +6 -5
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/label_test.rb +5 -4
- data/test/form_builder/association_test.rb +27 -2
- data/test/form_builder/button_test.rb +1 -0
- data/test/form_builder/error_notification_test.rb +1 -0
- data/test/form_builder/error_test.rb +6 -0
- data/test/form_builder/general_test.rb +27 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +17 -2
- data/test/form_builder/label_test.rb +9 -3
- data/test/form_builder/wrapper_test.rb +3 -2
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +19 -0
- data/test/inputs/collection_check_boxes_input_test.rb +30 -14
- data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
- data/test/inputs/collection_select_input_test.rb +40 -39
- data/test/inputs/datetime_input_test.rb +5 -4
- data/test/inputs/disabled_test.rb +1 -0
- data/test/inputs/discovery_test.rb +1 -0
- data/test/inputs/file_input_test.rb +1 -0
- data/test/inputs/general_test.rb +3 -2
- data/test/inputs/grouped_collection_select_input_test.rb +11 -10
- data/test/inputs/hidden_input_test.rb +1 -0
- data/test/inputs/numeric_input_test.rb +2 -1
- data/test/inputs/priority_input_test.rb +1 -0
- data/test/inputs/readonly_test.rb +1 -0
- data/test/inputs/required_test.rb +1 -0
- data/test/inputs/string_input_test.rb +17 -1
- data/test/inputs/text_input_test.rb +6 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +1 -0
- data/test/support/misc_helpers.rb +2 -1
- data/test/support/mock_controller.rb +7 -1
- data/test/support/models.rb +47 -14
- data/test/test_helper.rb +4 -0
- metadata +8 -7
data/test/support/models.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
Association = Struct.new(:klass, :name, :macro, :scope, :options)
|
|
2
3
|
|
|
3
4
|
Column = Struct.new(:name, :type, :limit) do
|
|
@@ -7,7 +8,7 @@ Relation = Struct.new(:records) do
|
|
|
7
8
|
delegate :each, to: :records
|
|
8
9
|
|
|
9
10
|
def where(conditions = nil)
|
|
10
|
-
self.class.new conditions ? records.first : records
|
|
11
|
+
self.class.new conditions ? [records.first] : records
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def order(conditions = nil)
|
|
@@ -18,6 +19,12 @@ Relation = Struct.new(:records) do
|
|
|
18
19
|
alias_method :to_ary, :records
|
|
19
20
|
end
|
|
20
21
|
|
|
22
|
+
Decorator = Struct.new(:object) do
|
|
23
|
+
def to_model
|
|
24
|
+
object
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
21
28
|
Picture = Struct.new(:id, :name) do
|
|
22
29
|
extend ActiveModel::Naming
|
|
23
30
|
include ActiveModel::Conversion
|
|
@@ -56,6 +63,19 @@ Company = Struct.new(:id, :name) do
|
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
|
66
|
+
Friend = Struct.new(:id, :name) do
|
|
67
|
+
extend ActiveModel::Naming
|
|
68
|
+
include ActiveModel::Conversion
|
|
69
|
+
|
|
70
|
+
def self.all
|
|
71
|
+
(1..3).map { |i| new(i, "#{name} #{i}") }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def persisted?
|
|
75
|
+
true
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
59
79
|
class Tag < Company; end
|
|
60
80
|
|
|
61
81
|
TagGroup = Struct.new(:id, :name, :tags)
|
|
@@ -70,7 +90,7 @@ class User
|
|
|
70
90
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
|
71
91
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
|
72
92
|
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
|
73
|
-
:special_picture_ids, :uuid
|
|
93
|
+
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids
|
|
74
94
|
|
|
75
95
|
def self.build(extra_attributes = {})
|
|
76
96
|
attributes = {
|
|
@@ -128,6 +148,15 @@ class User
|
|
|
128
148
|
|
|
129
149
|
begin
|
|
130
150
|
require 'active_model/type'
|
|
151
|
+
begin
|
|
152
|
+
ActiveModel::Type.lookup(:text)
|
|
153
|
+
rescue ArgumentError # :text is no longer an ActiveModel::Type
|
|
154
|
+
# But we don't want our tests to depend on ActiveRecord
|
|
155
|
+
class ::ActiveModel::Type::Text < ActiveModel::Type::String
|
|
156
|
+
def type; :text; end
|
|
157
|
+
end
|
|
158
|
+
ActiveModel::Type.register(:text, ActiveModel::Type::Text)
|
|
159
|
+
end
|
|
131
160
|
def type_for_attribute(attribute)
|
|
132
161
|
column_type, limit = case attribute
|
|
133
162
|
when 'name', 'status', 'password' then [:string, 100]
|
|
@@ -182,16 +211,20 @@ class User
|
|
|
182
211
|
Association.new(Company, association, :belongs_to, nil, {})
|
|
183
212
|
when :tags
|
|
184
213
|
Association.new(Tag, association, :has_many, nil, {})
|
|
214
|
+
when :special_tags
|
|
215
|
+
Association.new(Tag, association, :has_many, ->(user) { where(id: user.id) }, {})
|
|
185
216
|
when :first_company
|
|
186
217
|
Association.new(Company, association, :has_one, nil, {})
|
|
187
218
|
when :special_company
|
|
188
|
-
Association.new(Company, association, :belongs_to, nil,
|
|
219
|
+
Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
|
|
189
220
|
when :extra_special_company
|
|
190
|
-
Association.new(Company, association, :belongs_to, nil,
|
|
221
|
+
Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
|
|
191
222
|
when :pictures
|
|
192
223
|
Association.new(Picture, association, :has_many, nil, {})
|
|
193
224
|
when :special_pictures
|
|
194
225
|
Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
|
|
226
|
+
when :friends
|
|
227
|
+
Association.new(Friend, association, :has_many, nil, {})
|
|
195
228
|
end
|
|
196
229
|
end
|
|
197
230
|
|
|
@@ -217,8 +250,8 @@ class ValidatingUser < User
|
|
|
217
250
|
include ActiveModel::Validations
|
|
218
251
|
validates :name, presence: true
|
|
219
252
|
validates :company, presence: true
|
|
220
|
-
validates :age, presence: true, if:
|
|
221
|
-
validates :amount, presence: true, unless:
|
|
253
|
+
validates :age, presence: true, if: proc { |user| user.name }
|
|
254
|
+
validates :amount, presence: true, unless: proc { |user| user.age }
|
|
222
255
|
|
|
223
256
|
validates :action, presence: true, on: :create
|
|
224
257
|
validates :credit_limit, presence: true, on: :save
|
|
@@ -236,10 +269,10 @@ class ValidatingUser < User
|
|
|
236
269
|
greater_than_or_equal_to: :min_attempts,
|
|
237
270
|
less_than_or_equal_to: :max_attempts,
|
|
238
271
|
only_integer: true
|
|
239
|
-
validates_length_of :name, maximum: 25
|
|
240
|
-
validates_length_of :description,
|
|
272
|
+
validates_length_of :name, maximum: 25, minimum: 5
|
|
273
|
+
validates_length_of :description, in: 15..50
|
|
241
274
|
if ActionPack::VERSION::STRING < '5'
|
|
242
|
-
validates_length_of :action, maximum: 10, tokenizer:
|
|
275
|
+
validates_length_of :action, maximum: 10, tokenizer: ->(str) { str.scan(/\w+/) }
|
|
243
276
|
end
|
|
244
277
|
validates_length_of :home_picture, is: 12
|
|
245
278
|
|
|
@@ -267,16 +300,16 @@ class OtherValidatingUser < User
|
|
|
267
300
|
less_than: 100,
|
|
268
301
|
only_integer: true
|
|
269
302
|
validates_numericality_of :amount,
|
|
270
|
-
greater_than:
|
|
271
|
-
less_than:
|
|
303
|
+
greater_than: proc { |user| user.age },
|
|
304
|
+
less_than: proc { |user| user.age + 100 },
|
|
272
305
|
only_integer: true
|
|
273
306
|
validates_numericality_of :attempts,
|
|
274
|
-
greater_than_or_equal_to:
|
|
275
|
-
less_than_or_equal_to:
|
|
307
|
+
greater_than_or_equal_to: proc { |user| user.age },
|
|
308
|
+
less_than_or_equal_to: proc { |user| user.age + 100 },
|
|
276
309
|
only_integer: true
|
|
277
310
|
|
|
278
311
|
validates_format_of :country, with: /\w+/
|
|
279
|
-
validates_format_of :name, with:
|
|
312
|
+
validates_format_of :name, with: proc { /\w+/ }
|
|
280
313
|
validates_format_of :description, without: /\d+/
|
|
281
314
|
end
|
|
282
315
|
|
data/test/test_helper.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'bundler/setup'
|
|
2
3
|
|
|
3
4
|
require 'minitest/autorun'
|
|
@@ -53,8 +54,11 @@ class ActionView::TestCase
|
|
|
53
54
|
|
|
54
55
|
def setup_users(extra_attributes = {})
|
|
55
56
|
@user = User.build(extra_attributes)
|
|
57
|
+
@decorated_user = Decorator.new(@user)
|
|
56
58
|
|
|
57
59
|
@validating_user = ValidatingUser.build({
|
|
60
|
+
name: 'Tester McTesterson',
|
|
61
|
+
description: 'A test user of the most distinguised caliber',
|
|
58
62
|
home_picture: 'Home picture',
|
|
59
63
|
age: 19,
|
|
60
64
|
amount: 15,
|
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.
|
|
4
|
+
version: 3.5.1
|
|
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:
|
|
13
|
+
date: 2018-02-15 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
@@ -21,7 +21,7 @@ dependencies:
|
|
|
21
21
|
version: '4'
|
|
22
22
|
- - "<"
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: '5.
|
|
24
|
+
version: '5.2'
|
|
25
25
|
type: :runtime
|
|
26
26
|
prerelease: false
|
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -31,7 +31,7 @@ dependencies:
|
|
|
31
31
|
version: '4'
|
|
32
32
|
- - "<"
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '5.
|
|
34
|
+
version: '5.2'
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
36
|
name: actionpack
|
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -41,7 +41,7 @@ dependencies:
|
|
|
41
41
|
version: '4'
|
|
42
42
|
- - "<"
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: '5.
|
|
44
|
+
version: '5.2'
|
|
45
45
|
type: :runtime
|
|
46
46
|
prerelease: false
|
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -51,7 +51,7 @@ dependencies:
|
|
|
51
51
|
version: '4'
|
|
52
52
|
- - "<"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '5.
|
|
54
|
+
version: '5.2'
|
|
55
55
|
description: Forms made easy!
|
|
56
56
|
email: opensource@plataformatec.com.br
|
|
57
57
|
executables: []
|
|
@@ -82,6 +82,7 @@ files:
|
|
|
82
82
|
- lib/simple_form/components/labels.rb
|
|
83
83
|
- lib/simple_form/components/maxlength.rb
|
|
84
84
|
- lib/simple_form/components/min_max.rb
|
|
85
|
+
- lib/simple_form/components/minlength.rb
|
|
85
86
|
- lib/simple_form/components/pattern.rb
|
|
86
87
|
- lib/simple_form/components/placeholders.rb
|
|
87
88
|
- lib/simple_form/components/readonly.rb
|
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
178
179
|
version: '0'
|
|
179
180
|
requirements: []
|
|
180
181
|
rubyforge_project: simple_form
|
|
181
|
-
rubygems_version: 2.
|
|
182
|
+
rubygems_version: 2.6.11
|
|
182
183
|
signing_key:
|
|
183
184
|
specification_version: 4
|
|
184
185
|
summary: Forms made easy!
|