simple_form 3.5.0 → 3.5.1
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 +17 -0
- data/README.md +38 -28
- 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 +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +1 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +2 -1
- data/lib/simple_form.rb +8 -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.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 +2 -1
- 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/error_notification.rb +1 -0
- data/lib/simple_form/form_builder.rb +9 -3
- data/lib/simple_form/helpers.rb +1 -0
- 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/i18n_cache.rb +1 -0
- data/lib/simple_form/inputs.rb +1 -0
- data/lib/simple_form/inputs/base.rb +2 -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/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.rb +1 -0
- 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/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 +10 -3
- data/test/form_builder/hint_test.rb +6 -0
- data/test/form_builder/input_field_test.rb +2 -1
- 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 +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 +2 -1
- data/test/support/mock_controller.rb +4 -0
- data/test/support/models.rb +36 -12
- data/test/test_helper.rb +2 -0
- metadata +3 -3
data/test/simple_form_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module MiscHelpers
|
2
3
|
def store_translations(locale, translations, &block)
|
3
4
|
I18n.backend.store_translations locale, translations
|
@@ -181,7 +182,7 @@ module MiscHelpers
|
|
181
182
|
end
|
182
183
|
|
183
184
|
def custom_wrapper_with_label_text
|
184
|
-
SimpleForm.build :
|
185
|
+
SimpleForm.build label_text: proc { |label, required| "**#{label}**" } do |b|
|
185
186
|
b.use :label_input
|
186
187
|
end
|
187
188
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
class MockController
|
2
3
|
attr_writer :action_name
|
3
4
|
|
@@ -20,7 +21,10 @@ class MockController
|
|
20
21
|
def polymorphic_mappings(*); {}; end
|
21
22
|
|
22
23
|
def hash_for_user_path(*); end
|
24
|
+
|
23
25
|
def hash_for_validating_user_path(*); end
|
26
|
+
|
24
27
|
def hash_for_other_validating_user_path(*); end
|
28
|
+
|
25
29
|
def hash_for_users_path(*); end
|
26
30
|
end
|
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 = {
|
@@ -191,16 +211,20 @@ class User
|
|
191
211
|
Association.new(Company, association, :belongs_to, nil, {})
|
192
212
|
when :tags
|
193
213
|
Association.new(Tag, association, :has_many, nil, {})
|
214
|
+
when :special_tags
|
215
|
+
Association.new(Tag, association, :has_many, ->(user) { where(id: user.id) }, {})
|
194
216
|
when :first_company
|
195
217
|
Association.new(Company, association, :has_one, nil, {})
|
196
218
|
when :special_company
|
197
|
-
Association.new(Company, association, :belongs_to, nil,
|
219
|
+
Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
|
198
220
|
when :extra_special_company
|
199
|
-
Association.new(Company, association, :belongs_to, nil,
|
221
|
+
Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
|
200
222
|
when :pictures
|
201
223
|
Association.new(Picture, association, :has_many, nil, {})
|
202
224
|
when :special_pictures
|
203
225
|
Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
|
226
|
+
when :friends
|
227
|
+
Association.new(Friend, association, :has_many, nil, {})
|
204
228
|
end
|
205
229
|
end
|
206
230
|
|
@@ -226,8 +250,8 @@ class ValidatingUser < User
|
|
226
250
|
include ActiveModel::Validations
|
227
251
|
validates :name, presence: true
|
228
252
|
validates :company, presence: true
|
229
|
-
validates :age, presence: true, if:
|
230
|
-
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 }
|
231
255
|
|
232
256
|
validates :action, presence: true, on: :create
|
233
257
|
validates :credit_limit, presence: true, on: :save
|
@@ -248,7 +272,7 @@ class ValidatingUser < User
|
|
248
272
|
validates_length_of :name, maximum: 25, minimum: 5
|
249
273
|
validates_length_of :description, in: 15..50
|
250
274
|
if ActionPack::VERSION::STRING < '5'
|
251
|
-
validates_length_of :action, maximum: 10, tokenizer:
|
275
|
+
validates_length_of :action, maximum: 10, tokenizer: ->(str) { str.scan(/\w+/) }
|
252
276
|
end
|
253
277
|
validates_length_of :home_picture, is: 12
|
254
278
|
|
@@ -276,16 +300,16 @@ class OtherValidatingUser < User
|
|
276
300
|
less_than: 100,
|
277
301
|
only_integer: true
|
278
302
|
validates_numericality_of :amount,
|
279
|
-
greater_than:
|
280
|
-
less_than:
|
303
|
+
greater_than: proc { |user| user.age },
|
304
|
+
less_than: proc { |user| user.age + 100 },
|
281
305
|
only_integer: true
|
282
306
|
validates_numericality_of :attempts,
|
283
|
-
greater_than_or_equal_to:
|
284
|
-
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 },
|
285
309
|
only_integer: true
|
286
310
|
|
287
311
|
validates_format_of :country, with: /\w+/
|
288
|
-
validates_format_of :name, with:
|
312
|
+
validates_format_of :name, with: proc { /\w+/ }
|
289
313
|
validates_format_of :description, without: /\d+/
|
290
314
|
end
|
291
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,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: 3.5.
|
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
|
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
requirements: []
|
181
181
|
rubyforge_project: simple_form
|
182
|
-
rubygems_version: 2.6.
|
182
|
+
rubygems_version: 2.6.11
|
183
183
|
signing_key:
|
184
184
|
specification_version: 4
|
185
185
|
summary: Forms made easy!
|