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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +203 -31
  4. data/lib/generators/simple_form/install_generator.rb +1 -0
  5. data/lib/generators/simple_form/templates/README +3 -3
  6. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  7. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +15 -2
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +358 -73
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +18 -6
  12. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  13. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -0
  14. data/lib/simple_form/components/errors.rb +10 -1
  15. data/lib/simple_form/components/hints.rb +1 -0
  16. data/lib/simple_form/components/html5.rb +1 -0
  17. data/lib/simple_form/components/label_input.rb +2 -1
  18. data/lib/simple_form/components/labels.rb +11 -4
  19. data/lib/simple_form/components/maxlength.rb +4 -13
  20. data/lib/simple_form/components/min_max.rb +1 -0
  21. data/lib/simple_form/components/minlength.rb +5 -14
  22. data/lib/simple_form/components/pattern.rb +1 -0
  23. data/lib/simple_form/components/placeholders.rb +2 -1
  24. data/lib/simple_form/components/readonly.rb +1 -0
  25. data/lib/simple_form/components.rb +1 -0
  26. data/lib/simple_form/error_notification.rb +1 -0
  27. data/lib/simple_form/form_builder.rb +74 -19
  28. data/lib/simple_form/helpers/autofocus.rb +1 -0
  29. data/lib/simple_form/helpers/disabled.rb +1 -0
  30. data/lib/simple_form/helpers/readonly.rb +1 -0
  31. data/lib/simple_form/helpers/required.rb +1 -0
  32. data/lib/simple_form/helpers/validators.rb +2 -1
  33. data/lib/simple_form/helpers.rb +1 -0
  34. data/lib/simple_form/i18n_cache.rb +1 -0
  35. data/lib/simple_form/inputs/base.rb +20 -1
  36. data/lib/simple_form/inputs/block_input.rb +1 -0
  37. data/lib/simple_form/inputs/boolean_input.rb +3 -2
  38. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  39. data/lib/simple_form/inputs/collection_input.rb +3 -2
  40. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -1
  41. data/lib/simple_form/inputs/collection_select_input.rb +1 -0
  42. data/lib/simple_form/inputs/date_time_input.rb +1 -0
  43. data/lib/simple_form/inputs/file_input.rb +1 -0
  44. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
  45. data/lib/simple_form/inputs/hidden_input.rb +1 -0
  46. data/lib/simple_form/inputs/numeric_input.rb +1 -0
  47. data/lib/simple_form/inputs/password_input.rb +1 -0
  48. data/lib/simple_form/inputs/priority_input.rb +1 -0
  49. data/lib/simple_form/inputs/range_input.rb +1 -0
  50. data/lib/simple_form/inputs/string_input.rb +1 -0
  51. data/lib/simple_form/inputs/text_input.rb +1 -0
  52. data/lib/simple_form/inputs.rb +1 -0
  53. data/lib/simple_form/map_type.rb +1 -0
  54. data/lib/simple_form/railtie.rb +1 -0
  55. data/lib/simple_form/tags.rb +1 -0
  56. data/lib/simple_form/version.rb +2 -1
  57. data/lib/simple_form/wrappers/builder.rb +1 -0
  58. data/lib/simple_form/wrappers/leaf.rb +2 -1
  59. data/lib/simple_form/wrappers/many.rb +1 -0
  60. data/lib/simple_form/wrappers/root.rb +2 -0
  61. data/lib/simple_form/wrappers/single.rb +2 -1
  62. data/lib/simple_form/wrappers.rb +1 -0
  63. data/lib/simple_form.rb +58 -7
  64. data/test/action_view_extensions/builder_test.rb +6 -5
  65. data/test/action_view_extensions/form_helper_test.rb +3 -2
  66. data/test/components/custom_components_test.rb +62 -0
  67. data/test/components/label_test.rb +33 -4
  68. data/test/form_builder/association_test.rb +27 -2
  69. data/test/form_builder/button_test.rb +1 -0
  70. data/test/form_builder/error_notification_test.rb +1 -0
  71. data/test/form_builder/error_test.rb +6 -0
  72. data/test/form_builder/general_test.rb +44 -3
  73. data/test/form_builder/hint_test.rb +6 -0
  74. data/test/form_builder/input_field_test.rb +27 -1
  75. data/test/form_builder/label_test.rb +9 -3
  76. data/test/form_builder/wrapper_test.rb +24 -4
  77. data/test/generators/simple_form_generator_test.rb +4 -3
  78. data/test/inputs/boolean_input_test.rb +9 -0
  79. data/test/inputs/collection_check_boxes_input_test.rb +30 -14
  80. data/test/inputs/collection_radio_buttons_input_test.rb +40 -24
  81. data/test/inputs/collection_select_input_test.rb +40 -39
  82. data/test/inputs/datetime_input_test.rb +5 -4
  83. data/test/inputs/disabled_test.rb +1 -0
  84. data/test/inputs/discovery_test.rb +1 -0
  85. data/test/inputs/file_input_test.rb +1 -0
  86. data/test/inputs/general_test.rb +3 -2
  87. data/test/inputs/grouped_collection_select_input_test.rb +11 -10
  88. data/test/inputs/hidden_input_test.rb +1 -0
  89. data/test/inputs/numeric_input_test.rb +2 -1
  90. data/test/inputs/priority_input_test.rb +1 -0
  91. data/test/inputs/readonly_test.rb +1 -0
  92. data/test/inputs/required_test.rb +1 -0
  93. data/test/inputs/string_input_test.rb +2 -1
  94. data/test/inputs/text_input_test.rb +1 -0
  95. data/test/simple_form_test.rb +1 -0
  96. data/test/support/discovery_inputs.rb +1 -0
  97. data/test/support/misc_helpers.rb +16 -1
  98. data/test/support/mock_controller.rb +4 -0
  99. data/test/support/models.rb +44 -14
  100. data/test/test_helper.rb +2 -0
  101. metadata +5 -15
@@ -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
- when :uuid then :uuid
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 then true
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, { conditions: { id: 1 } })
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, { conditions: proc { { id: self.id } } })
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: Proc.new { |user| user.name }
230
- validates :amount, presence: true, unless: Proc.new { |user| user.age }
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: lambda { |str| str.scan(/\w+/) }
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: Proc.new { |user| user.age },
280
- less_than: Proc.new { |user| user.age + 100 },
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: Proc.new { |user| user.age },
284
- less_than_or_equal_to: Proc.new { |user| user.age + 100 },
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: Proc.new { /\w+/ }
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: 3.5.0
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: 2017-05-17 00:00:00.000000000 Z
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.10
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