simple_form 3.5.0 → 4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +203 -31
- data/lib/generators/simple_form/install_generator.rb +1 -0
- data/lib/generators/simple_form/templates/README +3 -3
- data/lib/generators/simple_form/templates/_form.html.erb +2 -0
- data/lib/generators/simple_form/templates/_form.html.haml +2 -0
- data/lib/generators/simple_form/templates/_form.html.slim +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +15 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +358 -73
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +18 -6
- 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 +10 -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 +11 -4
- data/lib/simple_form/components/maxlength.rb +4 -13
- data/lib/simple_form/components/min_max.rb +1 -0
- data/lib/simple_form/components/minlength.rb +5 -14
- data/lib/simple_form/components/pattern.rb +1 -0
- data/lib/simple_form/components/placeholders.rb +2 -1
- data/lib/simple_form/components/readonly.rb +1 -0
- data/lib/simple_form/components.rb +1 -0
- data/lib/simple_form/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +74 -19
- 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 +20 -1
- data/lib/simple_form/inputs/block_input.rb +1 -0
- data/lib/simple_form/inputs/boolean_input.rb +3 -2
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -2
- 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 +1 -0
- 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 +1 -0
- data/lib/simple_form/inputs/text_input.rb +1 -0
- 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 +2 -0
- data/lib/simple_form/wrappers/single.rb +2 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +58 -7
- data/test/action_view_extensions/builder_test.rb +6 -5
- data/test/action_view_extensions/form_helper_test.rb +3 -2
- data/test/components/custom_components_test.rb +62 -0
- data/test/components/label_test.rb +33 -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 +44 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +27 -1
- data/test/form_builder/label_test.rb +9 -3
- data/test/form_builder/wrapper_test.rb +24 -4
- data/test/generators/simple_form_generator_test.rb +4 -3
- data/test/inputs/boolean_input_test.rb +9 -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 +2 -1
- data/test/inputs/text_input_test.rb +1 -0
- data/test/simple_form_test.rb +1 -0
- data/test/support/discovery_inputs.rb +1 -0
- data/test/support/misc_helpers.rb +16 -1
- data/test/support/mock_controller.rb +4 -0
- data/test/support/models.rb +44 -14
- data/test/test_helper.rb +2 -0
- metadata +5 -15
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,8 @@ 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,
|
|
94
|
+
:citext, :hstore, :json, :jsonb
|
|
74
95
|
|
|
75
96
|
def self.build(extra_attributes = {})
|
|
76
97
|
attributes = {
|
|
@@ -121,7 +142,7 @@ class User
|
|
|
121
142
|
when :attempts then :integer
|
|
122
143
|
when :action then :string
|
|
123
144
|
when :credit_card then :string
|
|
124
|
-
|
|
145
|
+
else attribute.to_sym
|
|
125
146
|
end
|
|
126
147
|
Column.new(attribute, column_type, limit)
|
|
127
148
|
end
|
|
@@ -155,6 +176,10 @@ class User
|
|
|
155
176
|
when 'action' then :string
|
|
156
177
|
when 'credit_card' then :string
|
|
157
178
|
when 'uuid' then :string
|
|
179
|
+
when 'citext' then :string
|
|
180
|
+
when 'hstore' then [:text, 200]
|
|
181
|
+
when 'json' then [:text, 200]
|
|
182
|
+
when 'jsonb' then [:text, 200]
|
|
158
183
|
end
|
|
159
184
|
|
|
160
185
|
ActiveModel::Type.lookup(column_type, limit: limit)
|
|
@@ -167,7 +192,8 @@ class User
|
|
|
167
192
|
when :name, :status, :password, :description, :age,
|
|
168
193
|
:credit_limit, :active, :born_at, :delivery_time,
|
|
169
194
|
:created_at, :updated_at, :lock_version, :home_picture,
|
|
170
|
-
:amount, :attempts, :action, :credit_card, :uuid
|
|
195
|
+
:amount, :attempts, :action, :credit_card, :uuid,
|
|
196
|
+
:citext, :hstore, :json, :jsonb then true
|
|
171
197
|
else false
|
|
172
198
|
end
|
|
173
199
|
end
|
|
@@ -191,16 +217,20 @@ class User
|
|
|
191
217
|
Association.new(Company, association, :belongs_to, nil, {})
|
|
192
218
|
when :tags
|
|
193
219
|
Association.new(Tag, association, :has_many, nil, {})
|
|
220
|
+
when :special_tags
|
|
221
|
+
Association.new(Tag, association, :has_many, ->(user) { where(id: user.id) }, {})
|
|
194
222
|
when :first_company
|
|
195
223
|
Association.new(Company, association, :has_one, nil, {})
|
|
196
224
|
when :special_company
|
|
197
|
-
Association.new(Company, association, :belongs_to, nil,
|
|
225
|
+
Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
|
|
198
226
|
when :extra_special_company
|
|
199
|
-
Association.new(Company, association, :belongs_to, nil,
|
|
227
|
+
Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
|
|
200
228
|
when :pictures
|
|
201
229
|
Association.new(Picture, association, :has_many, nil, {})
|
|
202
230
|
when :special_pictures
|
|
203
231
|
Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
|
|
232
|
+
when :friends
|
|
233
|
+
Association.new(Friend, association, :has_many, nil, {})
|
|
204
234
|
end
|
|
205
235
|
end
|
|
206
236
|
|
|
@@ -226,8 +256,8 @@ class ValidatingUser < User
|
|
|
226
256
|
include ActiveModel::Validations
|
|
227
257
|
validates :name, presence: true
|
|
228
258
|
validates :company, presence: true
|
|
229
|
-
validates :age, presence: true, if:
|
|
230
|
-
validates :amount, presence: true, unless:
|
|
259
|
+
validates :age, presence: true, if: proc { |user| user.name }
|
|
260
|
+
validates :amount, presence: true, unless: proc { |user| user.age }
|
|
231
261
|
|
|
232
262
|
validates :action, presence: true, on: :create
|
|
233
263
|
validates :credit_limit, presence: true, on: :save
|
|
@@ -248,7 +278,7 @@ class ValidatingUser < User
|
|
|
248
278
|
validates_length_of :name, maximum: 25, minimum: 5
|
|
249
279
|
validates_length_of :description, in: 15..50
|
|
250
280
|
if ActionPack::VERSION::STRING < '5'
|
|
251
|
-
validates_length_of :action, maximum: 10, tokenizer:
|
|
281
|
+
validates_length_of :action, maximum: 10, tokenizer: ->(str) { str.scan(/\w+/) }
|
|
252
282
|
end
|
|
253
283
|
validates_length_of :home_picture, is: 12
|
|
254
284
|
|
|
@@ -276,16 +306,16 @@ class OtherValidatingUser < User
|
|
|
276
306
|
less_than: 100,
|
|
277
307
|
only_integer: true
|
|
278
308
|
validates_numericality_of :amount,
|
|
279
|
-
greater_than:
|
|
280
|
-
less_than:
|
|
309
|
+
greater_than: proc { |user| user.age },
|
|
310
|
+
less_than: proc { |user| user.age + 100 },
|
|
281
311
|
only_integer: true
|
|
282
312
|
validates_numericality_of :attempts,
|
|
283
|
-
greater_than_or_equal_to:
|
|
284
|
-
less_than_or_equal_to:
|
|
313
|
+
greater_than_or_equal_to: proc { |user| user.age },
|
|
314
|
+
less_than_or_equal_to: proc { |user| user.age + 100 },
|
|
285
315
|
only_integer: true
|
|
286
316
|
|
|
287
317
|
validates_format_of :country, with: /\w+/
|
|
288
|
-
validates_format_of :name, with:
|
|
318
|
+
validates_format_of :name, with: proc { /\w+/ }
|
|
289
319
|
validates_format_of :description, without: /\d+/
|
|
290
320
|
end
|
|
291
321
|
|
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,6 +54,7 @@ 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({
|
|
58
60
|
name: 'Tester McTesterson',
|
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:
|
|
4
|
+
version: 4.0.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:
|
|
13
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
@@ -19,9 +19,6 @@ dependencies:
|
|
|
19
19
|
- - ">"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: '4'
|
|
22
|
-
- - "<"
|
|
23
|
-
- !ruby/object:Gem::Version
|
|
24
|
-
version: '5.2'
|
|
25
22
|
type: :runtime
|
|
26
23
|
prerelease: false
|
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -29,9 +26,6 @@ dependencies:
|
|
|
29
26
|
- - ">"
|
|
30
27
|
- !ruby/object:Gem::Version
|
|
31
28
|
version: '4'
|
|
32
|
-
- - "<"
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '5.2'
|
|
35
29
|
- !ruby/object:Gem::Dependency
|
|
36
30
|
name: actionpack
|
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,9 +33,6 @@ dependencies:
|
|
|
39
33
|
- - ">"
|
|
40
34
|
- !ruby/object:Gem::Version
|
|
41
35
|
version: '4'
|
|
42
|
-
- - "<"
|
|
43
|
-
- !ruby/object:Gem::Version
|
|
44
|
-
version: '5.2'
|
|
45
36
|
type: :runtime
|
|
46
37
|
prerelease: false
|
|
47
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -49,9 +40,6 @@ dependencies:
|
|
|
49
40
|
- - ">"
|
|
50
41
|
- !ruby/object:Gem::Version
|
|
51
42
|
version: '4'
|
|
52
|
-
- - "<"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '5.2'
|
|
55
43
|
description: Forms made easy!
|
|
56
44
|
email: opensource@plataformatec.com.br
|
|
57
45
|
executables: []
|
|
@@ -125,6 +113,7 @@ files:
|
|
|
125
113
|
- lib/simple_form/wrappers/single.rb
|
|
126
114
|
- test/action_view_extensions/builder_test.rb
|
|
127
115
|
- test/action_view_extensions/form_helper_test.rb
|
|
116
|
+
- test/components/custom_components_test.rb
|
|
128
117
|
- test/components/label_test.rb
|
|
129
118
|
- test/form_builder/association_test.rb
|
|
130
119
|
- test/form_builder/button_test.rb
|
|
@@ -179,13 +168,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
179
168
|
version: '0'
|
|
180
169
|
requirements: []
|
|
181
170
|
rubyforge_project: simple_form
|
|
182
|
-
rubygems_version: 2.6.
|
|
171
|
+
rubygems_version: 2.6.11
|
|
183
172
|
signing_key:
|
|
184
173
|
specification_version: 4
|
|
185
174
|
summary: Forms made easy!
|
|
186
175
|
test_files:
|
|
187
176
|
- test/action_view_extensions/builder_test.rb
|
|
188
177
|
- test/action_view_extensions/form_helper_test.rb
|
|
178
|
+
- test/components/custom_components_test.rb
|
|
189
179
|
- test/components/label_test.rb
|
|
190
180
|
- test/form_builder/association_test.rb
|
|
191
181
|
- test/form_builder/button_test.rb
|