simple_form 5.2.0 → 5.3.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +3 -4
  5. data/lib/simple_form/components/label_input.rb +1 -1
  6. data/lib/simple_form/form_builder.rb +1 -5
  7. data/lib/simple_form/railtie.rb +4 -0
  8. data/lib/simple_form/version.rb +1 -1
  9. data/lib/simple_form/wrappers/leaf.rb +1 -1
  10. data/lib/simple_form.rb +8 -4
  11. metadata +5 -85
  12. data/test/action_view_extensions/builder_test.rb +0 -634
  13. data/test/action_view_extensions/form_helper_test.rb +0 -172
  14. data/test/components/custom_components_test.rb +0 -62
  15. data/test/components/label_test.rb +0 -352
  16. data/test/form_builder/association_test.rb +0 -252
  17. data/test/form_builder/button_test.rb +0 -48
  18. data/test/form_builder/error_notification_test.rb +0 -80
  19. data/test/form_builder/error_test.rb +0 -281
  20. data/test/form_builder/general_test.rb +0 -539
  21. data/test/form_builder/hint_test.rb +0 -150
  22. data/test/form_builder/input_field_test.rb +0 -195
  23. data/test/form_builder/label_test.rb +0 -136
  24. data/test/form_builder/wrapper_test.rb +0 -378
  25. data/test/generators/simple_form_generator_test.rb +0 -43
  26. data/test/inputs/boolean_input_test.rb +0 -256
  27. data/test/inputs/collection_check_boxes_input_test.rb +0 -323
  28. data/test/inputs/collection_radio_buttons_input_test.rb +0 -446
  29. data/test/inputs/collection_select_input_test.rb +0 -380
  30. data/test/inputs/color_input_test.rb +0 -10
  31. data/test/inputs/country_input_test.rb +0 -36
  32. data/test/inputs/datetime_input_test.rb +0 -176
  33. data/test/inputs/disabled_test.rb +0 -92
  34. data/test/inputs/discovery_test.rb +0 -142
  35. data/test/inputs/file_input_test.rb +0 -17
  36. data/test/inputs/general_test.rb +0 -133
  37. data/test/inputs/grouped_collection_select_input_test.rb +0 -196
  38. data/test/inputs/hidden_input_test.rb +0 -32
  39. data/test/inputs/numeric_input_test.rb +0 -177
  40. data/test/inputs/readonly_test.rb +0 -102
  41. data/test/inputs/required_test.rb +0 -158
  42. data/test/inputs/rich_text_area_input_test.rb +0 -15
  43. data/test/inputs/string_input_test.rb +0 -158
  44. data/test/inputs/text_input_test.rb +0 -37
  45. data/test/inputs/time_zone_input_test.rb +0 -36
  46. data/test/simple_form_test.rb +0 -18
  47. data/test/support/discovery_inputs.rb +0 -65
  48. data/test/support/misc_helpers.rb +0 -274
  49. data/test/support/mock_controller.rb +0 -30
  50. data/test/support/models.rb +0 -357
  51. data/test/test_helper.rb +0 -95
@@ -1,357 +0,0 @@
1
- # frozen_string_literal: true
2
- Association = Struct.new(:klass, :name, :macro, :scope, :options)
3
-
4
- Column = Struct.new(:name, :type, :limit) do
5
- end
6
-
7
- Relation = Struct.new(:records) do
8
- delegate :each, to: :records
9
-
10
- def where(conditions = nil)
11
- self.class.new conditions ? [records.first] : records
12
- end
13
-
14
- def order(conditions = nil)
15
- self.class.new conditions ? records.last : records
16
- end
17
-
18
- alias_method :to_a, :records
19
- alias_method :to_ary, :records
20
- end
21
-
22
- Decorator = Struct.new(:object) do
23
- def to_model
24
- object
25
- end
26
- end
27
-
28
- Picture = Struct.new(:id, :name) do
29
- extend ActiveModel::Naming
30
- include ActiveModel::Conversion
31
-
32
- def self.where(conditions = nil)
33
- if conditions.is_a?(Hash) && conditions[:name]
34
- all.to_a.last
35
- else
36
- all
37
- end
38
- end
39
-
40
- def self.all
41
- Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
42
- end
43
- end
44
-
45
- Company = Struct.new(:id, :name) do
46
- extend ActiveModel::Naming
47
- include ActiveModel::Conversion
48
-
49
- class << self
50
- delegate :order, :where, to: :_relation
51
- end
52
-
53
- def self._relation
54
- all
55
- end
56
-
57
- def self.all
58
- Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
59
- end
60
-
61
- def persisted?
62
- true
63
- end
64
- end
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
-
79
- class Tag < Company
80
- def group_method
81
- ["category-1"]
82
- end
83
- end
84
-
85
- TagGroup = Struct.new(:id, :name, :tags)
86
-
87
- class User
88
- extend ActiveModel::Naming
89
- include ActiveModel::Conversion
90
-
91
- attr_accessor :id, :name, :company, :company_id, :time_zone, :active, :age,
92
- :description, :created_at, :updated_at, :credit_limit, :password, :url,
93
- :delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
94
- :avatar, :home_picture, :email, :status, :residence_country, :phone_number,
95
- :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
96
- :extra_special_company_id, :pictures, :picture_ids, :special_pictures,
97
- :special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
98
- :citext, :hstore, :json, :jsonb, :hourly, :favorite_color
99
-
100
- def self.build(extra_attributes = {})
101
- attributes = {
102
- id: 1,
103
- name: 'New in SimpleForm!',
104
- description: 'Hello!',
105
- created_at: Time.now
106
- }.merge! extra_attributes
107
-
108
- new attributes
109
- end
110
-
111
- def initialize(options = {})
112
- @new_record = false
113
- options.each do |key, value|
114
- send("#{key}=", value)
115
- end if options
116
- end
117
-
118
- def new_record!
119
- @new_record = true
120
- end
121
-
122
- def persisted?
123
- !@new_record
124
- end
125
-
126
- def company_attributes=(*)
127
- end
128
-
129
- def tags_attributes=(*)
130
- end
131
-
132
- def column_for_attribute(attribute)
133
- column_type, limit = case attribute.to_sym
134
- when :name, :status, :password then [:string, 100]
135
- when :description then [:text, 200]
136
- when :age then :integer
137
- when :credit_limit then [:decimal, 15]
138
- when :active then :boolean
139
- when :born_at then :date
140
- when :delivery_time then :time
141
- when :created_at then :datetime
142
- when :updated_at then :timestamp
143
- when :lock_version then :integer
144
- when :home_picture then :string
145
- when :amount then :integer
146
- when :attempts then :integer
147
- when :action then :string
148
- when :credit_card then :string
149
- else attribute.to_sym
150
- end
151
- Column.new(attribute, column_type, limit)
152
- end
153
-
154
- begin
155
- require 'active_model/type'
156
- begin
157
- ActiveModel::Type.lookup(:text)
158
- rescue ArgumentError # :text is no longer an ActiveModel::Type
159
- # But we don't want our tests to depend on ActiveRecord
160
- class ::ActiveModel::Type::Text < ActiveModel::Type::String
161
- def type; :text; end
162
- end
163
- ActiveModel::Type.register(:text, ActiveModel::Type::Text)
164
- end
165
- def type_for_attribute(attribute)
166
- column_type, limit = case attribute
167
- when 'name', 'status', 'password' then [:string, 100]
168
- when 'description' then [:text, 200]
169
- when 'age' then :integer
170
- when 'credit_limit' then [:decimal, 15]
171
- when 'active' then :boolean
172
- when 'born_at' then :date
173
- when 'delivery_time' then :time
174
- when 'created_at' then :datetime
175
- when 'updated_at' then :datetime
176
- when 'lock_version' then :integer
177
- when 'home_picture' then :string
178
- when 'amount' then :integer
179
- when 'attempts' then :integer
180
- when 'action' then :string
181
- when 'credit_card' then :string
182
- when 'uuid' then :string
183
- when 'citext' then :string
184
- when 'hstore' then [:text, 200]
185
- when 'json' then [:text, 200]
186
- when 'jsonb' then [:text, 200]
187
- end
188
-
189
- ActiveModel::Type.lookup(column_type, limit: limit)
190
- end
191
- rescue LoadError
192
- end
193
-
194
- def has_attribute?(attribute)
195
- case attribute.to_sym
196
- when :name, :status, :password, :description, :age,
197
- :credit_limit, :active, :born_at, :delivery_time,
198
- :created_at, :updated_at, :lock_version, :home_picture,
199
- :amount, :attempts, :action, :credit_card, :uuid,
200
- :citext, :hstore, :json, :jsonb then true
201
- else false
202
- end
203
- end
204
-
205
- def self.human_attribute_name(attribute, options = {})
206
- case attribute
207
- when 'name', :name
208
- 'Super User Name!'
209
- when 'description'
210
- 'User Description!'
211
- when 'company'
212
- 'Company Human Name!'
213
- else
214
- attribute.to_s.humanize
215
- end
216
- end
217
-
218
- def self.reflect_on_association(association)
219
- case association
220
- when :company
221
- Association.new(Company, association, :belongs_to, nil, {})
222
- when :tags
223
- Association.new(Tag, association, :has_many, nil, {})
224
- when :special_tags
225
- Association.new(Tag, association, :has_many, ->(user) { where(id: user.id) }, {})
226
- when :first_company
227
- Association.new(Company, association, :has_one, nil, {})
228
- when :special_company
229
- Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
230
- when :extra_special_company
231
- Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
232
- when :pictures
233
- Association.new(Picture, association, :has_many, nil, {})
234
- when :special_pictures
235
- Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
236
- when :friends
237
- Association.new(Friend, association, :has_many, nil, {})
238
- end
239
- end
240
-
241
- def errors
242
- @errors ||= begin
243
- errors = ActiveModel::Errors.new(self)
244
- errors.add(:name, "cannot be blank")
245
- errors.add(:description, 'must be longer than 15 characters')
246
- errors.add(:age, 'is not a number')
247
- errors.add(:age, 'must be greater than 18')
248
- errors.add(:company, 'company must be present')
249
- errors.add(:company_id, 'must be valid')
250
- errors
251
- end
252
- end
253
-
254
- def self.readonly_attributes
255
- ["credit_card"]
256
- end
257
- end
258
-
259
- class ValidatingUser < User
260
- include ActiveModel::Validations
261
- validates :name, presence: true
262
- validates :company, presence: true
263
- validates :age, presence: true, if: proc { |user| user.name }
264
- validates :amount, presence: true, unless: proc { |user| user.age }
265
-
266
- validates :action, presence: true, on: :create
267
- validates :credit_limit, presence: true, on: :save
268
- validates :phone_number, presence: true, on: :update
269
-
270
- validates_numericality_of :age,
271
- greater_than_or_equal_to: 18,
272
- less_than_or_equal_to: 99,
273
- only_integer: true
274
- validates_numericality_of :amount,
275
- greater_than: :min_amount,
276
- less_than: :max_amount,
277
- only_integer: true
278
- validates_numericality_of :attempts,
279
- greater_than_or_equal_to: :min_attempts,
280
- less_than_or_equal_to: :max_attempts,
281
- only_integer: true
282
- validates_length_of :name, maximum: 25, minimum: 5
283
- validates_length_of :description, in: 15..50
284
- validates_length_of :home_picture, is: 12
285
-
286
- def min_amount
287
- 10
288
- end
289
-
290
- def max_amount
291
- 100
292
- end
293
-
294
- def min_attempts
295
- 1
296
- end
297
-
298
- def max_attempts
299
- 100
300
- end
301
- end
302
-
303
- class OtherValidatingUser < User
304
- include ActiveModel::Validations
305
- validates_numericality_of :age,
306
- greater_than: 17,
307
- less_than: 100,
308
- only_integer: true
309
- validates_numericality_of :amount,
310
- greater_than: proc { |user| user.age },
311
- less_than: proc { |user| user.age + 100 },
312
- only_integer: true
313
- validates_numericality_of :attempts,
314
- greater_than_or_equal_to: proc { |user| user.age },
315
- less_than_or_equal_to: proc { |user| user.age + 100 },
316
- only_integer: true
317
-
318
- validates_format_of :country, with: /\w+/
319
- validates_format_of :name, with: proc { /\w+/ }
320
- validates_format_of :description, without: /\d+/
321
- end
322
-
323
- class HashBackedAuthor < Hash
324
- extend ActiveModel::Naming
325
- include ActiveModel::Conversion
326
-
327
- def persisted?; false; end
328
-
329
- def name
330
- 'hash backed author'
331
- end
332
- end
333
-
334
- class UserNumber1And2 < User
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 DELETED
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'minitest/autorun'
3
-
4
- require 'active_model'
5
- require 'action_controller'
6
- require 'action_view'
7
-
8
- ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
9
-
10
- require 'action_view/template'
11
- require 'action_view/test_case'
12
-
13
- module Rails
14
- def self.env
15
- ActiveSupport::StringInquirer.new("test")
16
- end
17
- end
18
-
19
- $:.unshift File.expand_path("../../lib", __FILE__)
20
- require 'simple_form'
21
-
22
- require "rails/generators/test_case"
23
- require 'generators/simple_form/install_generator'
24
-
25
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
26
- require file unless file.end_with?('discovery_inputs.rb')
27
- end
28
- I18n.default_locale = :en
29
-
30
- require 'country_select'
31
-
32
- if defined?(HTMLSelector::NO_STRIP)
33
- HTMLSelector::NO_STRIP << "label"
34
- else
35
- ActionDispatch::Assertions::NO_STRIP << "label"
36
- end
37
-
38
- if ActiveSupport::TestCase.respond_to?(:test_order=)
39
- ActiveSupport::TestCase.test_order = :random
40
- end
41
-
42
- require "rails/test_unit/line_filtering"
43
-
44
- class ActionView::TestCase
45
- include MiscHelpers
46
- include SimpleForm::ActionViewExtensions::FormHelper
47
-
48
- extend Rails::LineFiltering
49
-
50
- setup :set_controller
51
- setup :setup_users
52
-
53
- def set_controller
54
- @controller = MockController.new
55
- end
56
-
57
- def setup_users(extra_attributes = {})
58
- @user = User.build(extra_attributes)
59
- @decorated_user = Decorator.new(@user)
60
-
61
- @validating_user = ValidatingUser.build({
62
- name: 'Tester McTesterson',
63
- description: 'A test user of the most distinguished caliber',
64
- home_picture: 'Home picture',
65
- age: 19,
66
- amount: 15,
67
- attempts: 1,
68
- company: [1]
69
- }.merge!(extra_attributes))
70
-
71
- @other_validating_user = OtherValidatingUser.build({
72
- age: 19,
73
- company: 1
74
- }.merge!(extra_attributes))
75
- end
76
-
77
- def protect_against_forgery?
78
- false
79
- end
80
-
81
- def user_path(*args)
82
- '/users'
83
- end
84
-
85
- def company_user_path(*args)
86
- '/company/users'
87
- end
88
-
89
- alias :users_path :user_path
90
- alias :super_user_path :user_path
91
- alias :validating_user_path :user_path
92
- alias :validating_users_path :user_path
93
- alias :other_validating_user_path :user_path
94
- alias :user_with_attachment_path :user_path
95
- end