simple_form 3.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +148 -0
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +278 -68
  5. data/lib/generators/simple_form/install_generator.rb +1 -0
  6. data/lib/generators/simple_form/templates/README +3 -3
  7. data/lib/generators/simple_form/templates/_form.html.erb +2 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +2 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +1 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +19 -9
  11. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +367 -63
  12. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +23 -8
  13. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +4 -1
  15. data/lib/simple_form/components/errors.rb +15 -2
  16. data/lib/simple_form/components/hints.rb +1 -0
  17. data/lib/simple_form/components/html5.rb +15 -4
  18. data/lib/simple_form/components/label_input.rb +2 -1
  19. data/lib/simple_form/components/labels.rb +12 -5
  20. data/lib/simple_form/components/maxlength.rb +8 -4
  21. data/lib/simple_form/components/min_max.rb +1 -0
  22. data/lib/simple_form/components/minlength.rb +38 -0
  23. data/lib/simple_form/components/pattern.rb +1 -0
  24. data/lib/simple_form/components/placeholders.rb +2 -1
  25. data/lib/simple_form/components/readonly.rb +1 -0
  26. data/lib/simple_form/components.rb +2 -0
  27. data/lib/simple_form/error_notification.rb +1 -0
  28. data/lib/simple_form/form_builder.rb +117 -35
  29. data/lib/simple_form/helpers/autofocus.rb +1 -0
  30. data/lib/simple_form/helpers/disabled.rb +1 -0
  31. data/lib/simple_form/helpers/readonly.rb +1 -0
  32. data/lib/simple_form/helpers/required.rb +1 -0
  33. data/lib/simple_form/helpers/validators.rb +2 -1
  34. data/lib/simple_form/helpers.rb +1 -0
  35. data/lib/simple_form/i18n_cache.rb +1 -0
  36. data/lib/simple_form/inputs/base.rb +36 -12
  37. data/lib/simple_form/inputs/block_input.rb +1 -0
  38. data/lib/simple_form/inputs/boolean_input.rb +14 -3
  39. data/lib/simple_form/inputs/collection_check_boxes_input.rb +2 -1
  40. data/lib/simple_form/inputs/collection_input.rb +7 -5
  41. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +3 -2
  42. data/lib/simple_form/inputs/collection_select_input.rb +1 -0
  43. data/lib/simple_form/inputs/color_input.rb +14 -0
  44. data/lib/simple_form/inputs/date_time_input.rb +13 -8
  45. data/lib/simple_form/inputs/file_input.rb +1 -0
  46. data/lib/simple_form/inputs/grouped_collection_select_input.rb +1 -0
  47. data/lib/simple_form/inputs/hidden_input.rb +1 -0
  48. data/lib/simple_form/inputs/numeric_input.rb +1 -0
  49. data/lib/simple_form/inputs/password_input.rb +2 -1
  50. data/lib/simple_form/inputs/priority_input.rb +1 -4
  51. data/lib/simple_form/inputs/range_input.rb +1 -0
  52. data/lib/simple_form/inputs/string_input.rb +3 -2
  53. data/lib/simple_form/inputs/text_input.rb +2 -1
  54. data/lib/simple_form/inputs.rb +2 -0
  55. data/lib/simple_form/map_type.rb +1 -0
  56. data/lib/simple_form/railtie.rb +1 -0
  57. data/lib/simple_form/tags.rb +7 -2
  58. data/lib/simple_form/version.rb +2 -1
  59. data/lib/simple_form/wrappers/builder.rb +1 -0
  60. data/lib/simple_form/wrappers/leaf.rb +2 -1
  61. data/lib/simple_form/wrappers/many.rb +1 -0
  62. data/lib/simple_form/wrappers/root.rb +2 -0
  63. data/lib/simple_form/wrappers/single.rb +2 -1
  64. data/lib/simple_form/wrappers.rb +1 -0
  65. data/lib/simple_form.rb +79 -14
  66. data/test/action_view_extensions/builder_test.rb +28 -9
  67. data/test/action_view_extensions/form_helper_test.rb +3 -2
  68. data/test/components/custom_components_test.rb +62 -0
  69. data/test/components/label_test.rb +33 -4
  70. data/test/form_builder/association_test.rb +33 -2
  71. data/test/form_builder/button_test.rb +1 -0
  72. data/test/form_builder/error_notification_test.rb +1 -0
  73. data/test/form_builder/error_test.rb +44 -9
  74. data/test/form_builder/general_test.rb +92 -20
  75. data/test/form_builder/hint_test.rb +6 -0
  76. data/test/form_builder/input_field_test.rb +76 -70
  77. data/test/form_builder/label_test.rb +27 -4
  78. data/test/form_builder/wrapper_test.rb +66 -14
  79. data/test/generators/simple_form_generator_test.rb +4 -3
  80. data/test/inputs/boolean_input_test.rb +35 -0
  81. data/test/inputs/collection_check_boxes_input_test.rb +38 -14
  82. data/test/inputs/collection_radio_buttons_input_test.rb +48 -24
  83. data/test/inputs/collection_select_input_test.rb +40 -39
  84. data/test/inputs/color_input_test.rb +10 -0
  85. data/test/inputs/datetime_input_test.rb +12 -8
  86. data/test/inputs/disabled_test.rb +14 -0
  87. data/test/inputs/discovery_test.rb +23 -0
  88. data/test/inputs/file_input_test.rb +1 -0
  89. data/test/inputs/general_test.rb +3 -2
  90. data/test/inputs/grouped_collection_select_input_test.rb +11 -10
  91. data/test/inputs/hidden_input_test.rb +1 -0
  92. data/test/inputs/numeric_input_test.rb +5 -1
  93. data/test/inputs/priority_input_test.rb +7 -6
  94. data/test/inputs/readonly_test.rb +1 -0
  95. data/test/inputs/required_test.rb +45 -0
  96. data/test/inputs/string_input_test.rb +18 -16
  97. data/test/inputs/text_input_test.rb +13 -0
  98. data/test/simple_form_test.rb +1 -0
  99. data/test/support/discovery_inputs.rb +8 -0
  100. data/test/support/misc_helpers.rb +44 -2
  101. data/test/support/mock_controller.rb +7 -1
  102. data/test/support/models.rb +105 -22
  103. data/test/test_helper.rb +14 -3
  104. metadata +42 -36
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -7,6 +8,11 @@ class StringInputTest < ActionView::TestCase
7
8
  assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
8
9
  end
9
10
 
11
+ test 'input maps text field to citext attribute' do
12
+ with_input_for @user, :name, :citext
13
+ assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']"
14
+ end
15
+
10
16
  test 'input generates a password field for password attributes' do
11
17
  with_input_for @user, :password, :password
12
18
  assert_select "input#user_password.password[type=password][name='user[password]']"
@@ -32,9 +38,9 @@ class StringInputTest < ActionView::TestCase
32
38
  assert_select 'input.string[maxlength="25"]'
33
39
  end
34
40
 
35
- test 'input does not get maxlength from validation when tokenizer present' do
36
- with_input_for @validating_user, :action, :string
37
- assert_no_select 'input.string[maxlength]'
41
+ test 'input infers minlength column definition from validation when present' do
42
+ with_input_for @validating_user, :name, :string
43
+ assert_select 'input.string[minlength="5"]'
38
44
  end
39
45
 
40
46
  test 'input gets maxlength from validation when :is option present' do
@@ -42,6 +48,11 @@ class StringInputTest < ActionView::TestCase
42
48
  assert_select 'input.string[maxlength="12"]'
43
49
  end
44
50
 
51
+ test 'input gets minlength from validation when :is option present' do
52
+ with_input_for @validating_user, :home_picture, :string
53
+ assert_select 'input.string[minlength="12"]'
54
+ end
55
+
45
56
  test 'input maxlength is the column limit plus one to make room for decimal point' do
46
57
  with_input_for @user, :credit_limit, :string
47
58
 
@@ -70,12 +81,12 @@ class StringInputTest < ActionView::TestCase
70
81
 
71
82
  test 'input infers pattern from attributes' do
72
83
  with_input_for @other_validating_user, :country, :string, pattern: true
73
- assert_select 'input[pattern="\w+"]'
84
+ assert_select "input:match('pattern', ?)", /\w+/
74
85
  end
75
86
 
76
87
  test 'input infers pattern from attributes using proc' do
77
88
  with_input_for @other_validating_user, :name, :string, pattern: true
78
- assert_select 'input[pattern="\w+"]'
89
+ assert_select "input:match('pattern', ?)", /\w+/
79
90
  end
80
91
 
81
92
  test 'input does not infer pattern from attributes if root default is false' do
@@ -87,7 +98,7 @@ class StringInputTest < ActionView::TestCase
87
98
 
88
99
  test 'input uses given pattern from attributes' do
89
100
  with_input_for @other_validating_user, :country, :string, input_html: { pattern: "\\d+" }
90
- assert_select 'input[pattern="\d+"]'
101
+ assert_select "input:match('pattern', ?)", /\\d+/
91
102
  end
92
103
 
93
104
  test 'input does not use pattern if model has :without validation option' do
@@ -115,16 +126,7 @@ class StringInputTest < ActionView::TestCase
115
126
  end
116
127
  end
117
128
 
118
- test 'input translates a key prefixed with _html and return the html markup' do
119
- store_translations(:en, simple_form: { labels: { user: {
120
- name_html: '<b>Name</b>'
121
- } } }) do
122
- with_input_for @user, :name, :string
123
- assert_select 'label b', 'Name'
124
- end
125
- end
126
-
127
- [:email, :url, :search, :tel].each do |type|
129
+ %i[email url search tel].each do |type|
128
130
  test "input allows type #{type}" do
129
131
  with_input_for @user, :name, type
130
132
  assert_select "input.string.#{type}"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # encoding: UTF-8
2
3
  require 'test_helper'
3
4
 
@@ -12,6 +13,13 @@ class TextInputTest < ActionView::TestCase
12
13
  assert_select 'textarea.text[placeholder="Put in some text"]'
13
14
  end
14
15
 
16
+ test 'input generates a placeholder from the translations' do
17
+ store_translations(:en, simple_form: { placeholders: { user: { name: "placeholder from i18n en.simple_form.placeholders.user.name" } } }) do
18
+ with_input_for @user, :name, :text
19
+ assert_select 'textarea.text[placeholder="placeholder from i18n en.simple_form.placeholders.user.name"]'
20
+ end
21
+ end
22
+
15
23
  test 'input gets maxlength from column definition for text attributes' do
16
24
  with_input_for @user, :description, :text
17
25
  assert_select 'textarea.text[maxlength="200"]'
@@ -21,4 +29,9 @@ class TextInputTest < ActionView::TestCase
21
29
  with_input_for @validating_user, :description, :text
22
30
  assert_select 'textarea.text[maxlength="50"]'
23
31
  end
32
+
33
+ test 'input infers minlength column definition from validation when present for text attributes' do
34
+ with_input_for @validating_user, :description, :text
35
+ assert_select 'textarea.text[minlength="15"]'
36
+ end
24
37
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  class SimpleFormTest < ActiveSupport::TestCase
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class StringInput < SimpleForm::Inputs::StringInput
2
3
  def input(wrapper_options = nil)
3
4
  "<section>#{super}</section>".html_safe
@@ -36,6 +37,13 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
36
37
  end
37
38
  end
38
39
 
40
+ class FileInput < SimpleForm::Inputs::FileInput
41
+ def input_html_classes
42
+ super.delete_if { |html_class| html_class == :file }
43
+ super.push('file-upload')
44
+ end
45
+ end
46
+
39
47
  module CustomInputs
40
48
  class CustomizedInput < SimpleForm::Inputs::StringInput
41
49
  def input_html_classes
@@ -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
@@ -46,7 +47,7 @@ module MiscHelpers
46
47
  end
47
48
  end
48
49
 
49
- def swap_wrapper(name = :default, wrapper = self.custom_wrapper)
50
+ def swap_wrapper(name = :default, wrapper = custom_wrapper)
50
51
  old = SimpleForm.wrappers[name.to_s]
51
52
  SimpleForm.wrappers[name.to_s] = wrapper
52
53
  yield
@@ -91,6 +92,20 @@ module MiscHelpers
91
92
  end
92
93
  end
93
94
 
95
+ def custom_wrapper_with_input_data_modal
96
+ SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
97
+ b.use :label
98
+ b.use :input, data: { modal: 'data-modal', wrapper: 'data-wrapper' }
99
+ end
100
+ end
101
+
102
+ def custom_wrapper_with_input_aria_modal
103
+ SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
104
+ b.use :label
105
+ b.use :input, aria: { modal: 'aria-modal', wrapper: 'aria-wrapper' }
106
+ end
107
+ end
108
+
94
109
  def custom_wrapper_with_label_class
95
110
  SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
96
111
  b.use :label, class: 'inline-class'
@@ -167,7 +182,7 @@ module MiscHelpers
167
182
  end
168
183
 
169
184
  def custom_wrapper_with_label_text
170
- SimpleForm.build :label_text => proc { |label, required| "**#{label}**" } do |b|
185
+ SimpleForm.build label_text: proc { |label, required| "**#{label}**" } do |b|
171
186
  b.use :label_input
172
187
  end
173
188
  end
@@ -184,6 +199,27 @@ module MiscHelpers
184
199
  end
185
200
  end
186
201
 
202
+ def custom_wrapper_with_required_input
203
+ SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
204
+ b.use :html5
205
+ b.use :input, required: true
206
+ end
207
+ end
208
+
209
+ def custom_wrapper_with_input_error_class
210
+ SimpleForm.build tag: :div, class: "custom_wrapper", error_class: :field_with_errors do |b|
211
+ b.use :label
212
+ b.use :input, class: 'inline-class', error_class: 'is-invalid'
213
+ end
214
+ end
215
+
216
+ def custom_wrapper_with_input_valid_class
217
+ SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: :field_without_errors do |b|
218
+ b.use :label
219
+ b.use :input, class: 'inline-class', valid_class: 'is-valid'
220
+ end
221
+ end
222
+
187
223
  def custom_form_for(object, *args, &block)
188
224
  simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
189
225
  end
@@ -219,6 +255,12 @@ module MiscHelpers
219
255
  f.input(attribute_name, options.merge(as: type))
220
256
  end
221
257
  end
258
+
259
+ def with_input_field_for(object, *args)
260
+ with_concat_form_for(object) do |f|
261
+ f.input_field(*args)
262
+ end
263
+ end
222
264
  end
223
265
 
224
266
  class CustomFormBuilder < SimpleForm::FormBuilder
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class MockController
2
3
  attr_writer :action_name
3
4
 
@@ -9,7 +10,7 @@ class MockController
9
10
  defined?(@action_name) ? @action_name : "edit"
10
11
  end
11
12
 
12
- def url_for(*args)
13
+ def url_for(*)
13
14
  "http://example.com"
14
15
  end
15
16
 
@@ -17,8 +18,13 @@ class MockController
17
18
  {}
18
19
  end
19
20
 
21
+ def polymorphic_mappings(*); {}; end
22
+
20
23
  def hash_for_user_path(*); end
24
+
21
25
  def hash_for_validating_user_path(*); end
26
+
22
27
  def hash_for_other_validating_user_path(*); end
28
+
23
29
  def hash_for_users_path(*); end
24
30
  end
@@ -1,17 +1,14 @@
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
4
- # Returns +true+ if the column is either of type integer, float or decimal.
5
- def number?
6
- type == :integer || type == :float || type == :decimal
7
- end
8
5
  end
9
6
 
10
7
  Relation = Struct.new(:records) do
11
8
  delegate :each, to: :records
12
9
 
13
10
  def where(conditions = nil)
14
- self.class.new conditions ? records.first : records
11
+ self.class.new conditions ? [records.first] : records
15
12
  end
16
13
 
17
14
  def order(conditions = nil)
@@ -22,6 +19,12 @@ Relation = Struct.new(:records) do
22
19
  alias_method :to_ary, :records
23
20
  end
24
21
 
22
+ Decorator = Struct.new(:object) do
23
+ def to_model
24
+ object
25
+ end
26
+ end
27
+
25
28
  Picture = Struct.new(:id, :name) do
26
29
  extend ActiveModel::Naming
27
30
  include ActiveModel::Conversion
@@ -60,7 +63,24 @@ Company = Struct.new(:id, :name) do
60
63
  end
61
64
  end
62
65
 
63
- class Tag < Company; end
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
64
84
 
65
85
  TagGroup = Struct.new(:id, :name, :tags)
66
86
 
@@ -74,7 +94,8 @@ class User
74
94
  :avatar, :home_picture, :email, :status, :residence_country, :phone_number,
75
95
  :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
76
96
  :extra_special_company_id, :pictures, :picture_ids, :special_pictures,
77
- :special_picture_ids, :uuid
97
+ :special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
98
+ :citext, :hstore, :json, :jsonb, :hourly, :favorite_color
78
99
 
79
100
  def self.build(extra_attributes = {})
80
101
  attributes = {
@@ -125,24 +146,65 @@ class User
125
146
  when :attempts then :integer
126
147
  when :action then :string
127
148
  when :credit_card then :string
128
- when :uuid then :uuid
149
+ else attribute.to_sym
129
150
  end
130
151
  Column.new(attribute, column_type, limit)
131
152
  end
132
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
+
133
194
  def has_attribute?(attribute)
134
195
  case attribute.to_sym
135
196
  when :name, :status, :password, :description, :age,
136
197
  :credit_limit, :active, :born_at, :delivery_time,
137
198
  :created_at, :updated_at, :lock_version, :home_picture,
138
- :amount, :attempts, :action, :credit_card, :uuid then true
199
+ :amount, :attempts, :action, :credit_card, :uuid,
200
+ :citext, :hstore, :json, :jsonb then true
139
201
  else false
140
202
  end
141
203
  end
142
204
 
143
205
  def self.human_attribute_name(attribute, options = {})
144
206
  case attribute
145
- when 'name'
207
+ when 'name', :name
146
208
  'Super User Name!'
147
209
  when 'description'
148
210
  'User Description!'
@@ -159,16 +221,20 @@ class User
159
221
  Association.new(Company, association, :belongs_to, nil, {})
160
222
  when :tags
161
223
  Association.new(Tag, association, :has_many, nil, {})
224
+ when :special_tags
225
+ Association.new(Tag, association, :has_many, ->(user) { where(id: user.id) }, {})
162
226
  when :first_company
163
227
  Association.new(Company, association, :has_one, nil, {})
164
228
  when :special_company
165
- Association.new(Company, association, :belongs_to, nil, { conditions: { id: 1 } })
229
+ Association.new(Company, association, :belongs_to, nil, conditions: { id: 1 })
166
230
  when :extra_special_company
167
- Association.new(Company, association, :belongs_to, nil, { conditions: proc { { id: self.id } } })
231
+ Association.new(Company, association, :belongs_to, nil, conditions: proc { { id: self.id } })
168
232
  when :pictures
169
233
  Association.new(Picture, association, :has_many, nil, {})
170
234
  when :special_pictures
171
235
  Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
236
+ when :friends
237
+ Association.new(Friend, association, :has_many, nil, {})
172
238
  end
173
239
  end
174
240
 
@@ -194,8 +260,8 @@ class ValidatingUser < User
194
260
  include ActiveModel::Validations
195
261
  validates :name, presence: true
196
262
  validates :company, presence: true
197
- validates :age, presence: true, if: Proc.new { |user| user.name }
198
- validates :amount, presence: true, unless: Proc.new { |user| user.age }
263
+ validates :age, presence: true, if: proc { |user| user.name }
264
+ validates :amount, presence: true, unless: proc { |user| user.age }
199
265
 
200
266
  validates :action, presence: true, on: :create
201
267
  validates :credit_limit, presence: true, on: :save
@@ -213,9 +279,8 @@ class ValidatingUser < User
213
279
  greater_than_or_equal_to: :min_attempts,
214
280
  less_than_or_equal_to: :max_attempts,
215
281
  only_integer: true
216
- validates_length_of :name, maximum: 25
217
- validates_length_of :description, maximum: 50
218
- validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
282
+ validates_length_of :name, maximum: 25, minimum: 5
283
+ validates_length_of :description, in: 15..50
219
284
  validates_length_of :home_picture, is: 12
220
285
 
221
286
  def min_amount
@@ -242,16 +307,16 @@ class OtherValidatingUser < User
242
307
  less_than: 100,
243
308
  only_integer: true
244
309
  validates_numericality_of :amount,
245
- greater_than: Proc.new { |user| user.age },
246
- less_than: Proc.new { |user| user.age + 100 },
310
+ greater_than: proc { |user| user.age },
311
+ less_than: proc { |user| user.age + 100 },
247
312
  only_integer: true
248
313
  validates_numericality_of :attempts,
249
- greater_than_or_equal_to: Proc.new { |user| user.age },
250
- less_than_or_equal_to: Proc.new { |user| user.age + 100 },
314
+ greater_than_or_equal_to: proc { |user| user.age },
315
+ less_than_or_equal_to: proc { |user| user.age + 100 },
251
316
  only_integer: true
252
317
 
253
318
  validates_format_of :country, with: /\w+/
254
- validates_format_of :name, with: Proc.new { /\w+/ }
319
+ validates_format_of :name, with: proc { /\w+/ }
255
320
  validates_format_of :description, without: /\d+/
256
321
  end
257
322
 
@@ -268,3 +333,21 @@ end
268
333
 
269
334
  class UserNumber1And2 < User
270
335
  end
336
+
337
+ class UserWithAttachment < User
338
+ def avatar_attachment
339
+ OpenStruct.new
340
+ end
341
+
342
+ def cover_url
343
+ "/uploads/cover.png"
344
+ end
345
+
346
+ def profile_image_attacher
347
+ OpenStruct.new
348
+ end
349
+
350
+ def portrait_file_name
351
+ "portrait.png"
352
+ end
353
+ end
data/test/test_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
- require 'bundler/setup'
2
-
1
+ # frozen_string_literal: true
3
2
  require 'minitest/autorun'
4
3
 
5
4
  require 'active_model'
6
5
  require 'action_controller'
7
6
  require 'action_view'
7
+
8
8
  ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
9
9
 
10
10
  require 'action_view/template'
11
-
12
11
  require 'action_view/test_case'
13
12
 
14
13
  module Rails
@@ -36,10 +35,18 @@ else
36
35
  ActionDispatch::Assertions::NO_STRIP << "label"
37
36
  end
38
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
+
39
44
  class ActionView::TestCase
40
45
  include MiscHelpers
41
46
  include SimpleForm::ActionViewExtensions::FormHelper
42
47
 
48
+ extend Rails::LineFiltering
49
+
43
50
  setup :set_controller
44
51
  setup :setup_users
45
52
 
@@ -49,8 +56,11 @@ class ActionView::TestCase
49
56
 
50
57
  def setup_users(extra_attributes = {})
51
58
  @user = User.build(extra_attributes)
59
+ @decorated_user = Decorator.new(@user)
52
60
 
53
61
  @validating_user = ValidatingUser.build({
62
+ name: 'Tester McTesterson',
63
+ description: 'A test user of the most distinguised caliber',
54
64
  home_picture: 'Home picture',
55
65
  age: 19,
56
66
  amount: 15,
@@ -81,4 +91,5 @@ class ActionView::TestCase
81
91
  alias :validating_user_path :user_path
82
92
  alias :validating_users_path :user_path
83
93
  alias :other_validating_user_path :user_path
94
+ alias :user_with_attachment_path :user_path
84
95
  end
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.1.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Valim
@@ -10,36 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-11-25 00:00:00.000000000 Z
13
+ date: 2019-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '4.0'
21
+ version: '5.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '4.0'
28
+ version: '5.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: actionpack
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '4.0'
35
+ version: '5.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '4.0'
42
+ version: '5.0'
43
43
  description: Forms made easy!
44
44
  email: opensource@plataformatec.com.br
45
45
  executables: []
@@ -70,6 +70,7 @@ files:
70
70
  - lib/simple_form/components/labels.rb
71
71
  - lib/simple_form/components/maxlength.rb
72
72
  - lib/simple_form/components/min_max.rb
73
+ - lib/simple_form/components/minlength.rb
73
74
  - lib/simple_form/components/pattern.rb
74
75
  - lib/simple_form/components/placeholders.rb
75
76
  - lib/simple_form/components/readonly.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/simple_form/inputs/collection_input.rb
91
92
  - lib/simple_form/inputs/collection_radio_buttons_input.rb
92
93
  - lib/simple_form/inputs/collection_select_input.rb
94
+ - lib/simple_form/inputs/color_input.rb
93
95
  - lib/simple_form/inputs/date_time_input.rb
94
96
  - lib/simple_form/inputs/file_input.rb
95
97
  - lib/simple_form/inputs/grouped_collection_select_input.rb
@@ -112,6 +114,7 @@ files:
112
114
  - lib/simple_form/wrappers/single.rb
113
115
  - test/action_view_extensions/builder_test.rb
114
116
  - test/action_view_extensions/form_helper_test.rb
117
+ - test/components/custom_components_test.rb
115
118
  - test/components/label_test.rb
116
119
  - test/form_builder/association_test.rb
117
120
  - test/form_builder/button_test.rb
@@ -127,6 +130,7 @@ files:
127
130
  - test/inputs/collection_check_boxes_input_test.rb
128
131
  - test/inputs/collection_radio_buttons_input_test.rb
129
132
  - test/inputs/collection_select_input_test.rb
133
+ - test/inputs/color_input_test.rb
130
134
  - test/inputs/datetime_input_test.rb
131
135
  - test/inputs/disabled_test.rb
132
136
  - test/inputs/discovery_test.rb
@@ -165,45 +169,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
169
  - !ruby/object:Gem::Version
166
170
  version: '0'
167
171
  requirements: []
168
- rubyforge_project: simple_form
169
- rubygems_version: 2.2.2
172
+ rubyforge_project:
173
+ rubygems_version: 2.7.3
170
174
  signing_key:
171
175
  specification_version: 4
172
176
  summary: Forms made easy!
173
177
  test_files:
174
- - test/action_view_extensions/builder_test.rb
175
- - test/action_view_extensions/form_helper_test.rb
176
178
  - test/components/label_test.rb
177
- - test/form_builder/association_test.rb
178
- - test/form_builder/button_test.rb
179
- - test/form_builder/error_notification_test.rb
179
+ - test/components/custom_components_test.rb
180
+ - test/support/discovery_inputs.rb
181
+ - test/support/misc_helpers.rb
182
+ - test/support/mock_controller.rb
183
+ - test/support/models.rb
184
+ - test/test_helper.rb
180
185
  - test/form_builder/error_test.rb
181
- - test/form_builder/general_test.rb
182
186
  - test/form_builder/hint_test.rb
187
+ - test/form_builder/error_notification_test.rb
188
+ - test/form_builder/general_test.rb
189
+ - test/form_builder/button_test.rb
183
190
  - test/form_builder/input_field_test.rb
184
191
  - test/form_builder/label_test.rb
185
192
  - test/form_builder/wrapper_test.rb
193
+ - test/form_builder/association_test.rb
186
194
  - test/generators/simple_form_generator_test.rb
187
- - test/inputs/boolean_input_test.rb
195
+ - test/action_view_extensions/builder_test.rb
196
+ - test/action_view_extensions/form_helper_test.rb
197
+ - test/simple_form_test.rb
198
+ - test/inputs/string_input_test.rb
199
+ - test/inputs/numeric_input_test.rb
200
+ - test/inputs/readonly_test.rb
201
+ - test/inputs/grouped_collection_select_input_test.rb
202
+ - test/inputs/text_input_test.rb
188
203
  - test/inputs/collection_check_boxes_input_test.rb
189
- - test/inputs/collection_radio_buttons_input_test.rb
190
- - test/inputs/collection_select_input_test.rb
191
- - test/inputs/datetime_input_test.rb
204
+ - test/inputs/boolean_input_test.rb
192
205
  - test/inputs/disabled_test.rb
193
206
  - test/inputs/discovery_test.rb
194
- - test/inputs/file_input_test.rb
207
+ - test/inputs/collection_select_input_test.rb
195
208
  - test/inputs/general_test.rb
196
- - test/inputs/grouped_collection_select_input_test.rb
197
- - test/inputs/hidden_input_test.rb
198
- - test/inputs/numeric_input_test.rb
199
- - test/inputs/priority_input_test.rb
200
- - test/inputs/readonly_test.rb
209
+ - test/inputs/color_input_test.rb
201
210
  - test/inputs/required_test.rb
202
- - test/inputs/string_input_test.rb
203
- - test/inputs/text_input_test.rb
204
- - test/simple_form_test.rb
205
- - test/support/discovery_inputs.rb
206
- - test/support/misc_helpers.rb
207
- - test/support/mock_controller.rb
208
- - test/support/models.rb
209
- - test/test_helper.rb
211
+ - test/inputs/collection_radio_buttons_input_test.rb
212
+ - test/inputs/priority_input_test.rb
213
+ - test/inputs/hidden_input_test.rb
214
+ - test/inputs/file_input_test.rb
215
+ - test/inputs/datetime_input_test.rb