simple_form 3.3.1 → 3.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d026bcdacbcb386673f3785a25ef90cfd238ad9
4
- data.tar.gz: d1172ebf284c52c339aa055de433138c49b65f55
3
+ metadata.gz: 534c9396c2be271ccbb32518e9e5026b5ff523e1
4
+ data.tar.gz: bb8085d4a664110a941f6cd7e732db16f9eef1ec
5
5
  SHA512:
6
- metadata.gz: e18ee8cf266597533f6b732a544299eb46168013c6c20cbea36805b5da7c2d419ed2403011f22b015fbf26aa1a6d02ef71f3a4ad9ead7b60e4966bfec41c3d5a
7
- data.tar.gz: 21e536b6a81a608cf18c472cccc78c3e49ca382afb398867fbf74a2f5e9614d87ebc40602051fdec005810f39b49d8cfa2302259bc4ceef3f9a6536941c641c5
6
+ metadata.gz: d8e81c8af57b65150d3b9a53433c9d9adb3c5d64fa00ae70b1263a33ce05173d2dc65775ab66e91507d1db452e0f59cb254c0b5eb1ca905ec4b95bbc4eb98282
7
+ data.tar.gz: 249e0e56f352267ab529db921125ac214d6baeb17153278cba26c61951ce31867cf9d94b4188dab9e50457d2e23d6aebabacf29e475b31c8f7c85c382ab318f2
@@ -1,5 +1,12 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 3.4.0
4
+
5
+ * Removed Ruby 2.4.0 `Integer` unification deprecation warning.
6
+ * Removed EOL Ruby 1.9.3 from the build matrix.
7
+ * Added `minlength` component.
8
+ * `boolean_label_class` can be set on a per-input basis.
9
+
3
10
  ## 3.3.1
4
11
 
5
12
  ### Bug fix
@@ -28,8 +28,12 @@ SimpleForm.setup do |config|
28
28
  # extensions by default, you can change `b.optional` to `b.use`.
29
29
 
30
30
  # Calculates maxlength from length validations for string inputs
31
+ # and/or database column lengths
31
32
  b.optional :maxlength
32
33
 
34
+ # Calculate minlength from length validations for string inputs
35
+ b.optional :minlength
36
+
33
37
  # Calculates pattern from format validations for string inputs
34
38
  b.optional :pattern
35
39
 
@@ -8,6 +8,7 @@ SimpleForm.setup do |config|
8
8
  b.use :html5
9
9
  b.use :placeholder
10
10
  b.optional :maxlength
11
+ b.optional :minlength
11
12
  b.optional :pattern
12
13
  b.optional :min_max
13
14
  b.optional :readonly
@@ -22,6 +23,7 @@ SimpleForm.setup do |config|
22
23
  b.use :html5
23
24
  b.use :placeholder
24
25
  b.optional :maxlength
26
+ b.optional :minlength
25
27
  b.optional :readonly
26
28
  b.use :label, class: 'control-label'
27
29
 
@@ -55,6 +57,7 @@ SimpleForm.setup do |config|
55
57
  b.use :html5
56
58
  b.use :placeholder
57
59
  b.optional :maxlength
60
+ b.optional :minlength
58
61
  b.optional :pattern
59
62
  b.optional :min_max
60
63
  b.optional :readonly
@@ -71,6 +74,7 @@ SimpleForm.setup do |config|
71
74
  b.use :html5
72
75
  b.use :placeholder
73
76
  b.optional :maxlength
77
+ b.optional :minlength
74
78
  b.optional :readonly
75
79
  b.use :label, class: 'col-sm-3 control-label'
76
80
 
@@ -112,6 +116,7 @@ SimpleForm.setup do |config|
112
116
  b.use :html5
113
117
  b.use :placeholder
114
118
  b.optional :maxlength
119
+ b.optional :minlength
115
120
  b.optional :pattern
116
121
  b.optional :min_max
117
122
  b.optional :readonly
@@ -11,6 +11,7 @@ SimpleForm.setup do |config|
11
11
  b.use :html5
12
12
  b.use :placeholder
13
13
  b.optional :maxlength
14
+ b.optional :minlength
14
15
  b.optional :pattern
15
16
  b.optional :min_max
16
17
  b.optional :readonly
@@ -24,6 +25,7 @@ SimpleForm.setup do |config|
24
25
  b.use :html5
25
26
  b.use :placeholder
26
27
  b.optional :maxlength
28
+ b.optional :minlength
27
29
  b.optional :pattern
28
30
  b.optional :min_max
29
31
  b.optional :readonly
@@ -65,6 +67,7 @@ SimpleForm.setup do |config|
65
67
  b.use :html5
66
68
  b.use :placeholder
67
69
  b.optional :maxlength
70
+ b.optional :minlength
68
71
  b.optional :pattern
69
72
  b.optional :min_max
70
73
  b.optional :readonly
@@ -232,6 +232,7 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
232
232
 
233
233
  b.use :min_max
234
234
  b.use :maxlength
235
+ b.use :minlength
235
236
  b.use :placeholder
236
237
  b.optional :pattern
237
238
  b.optional :readonly
@@ -15,6 +15,7 @@ module SimpleForm
15
15
  autoload :Labels
16
16
  autoload :MinMax
17
17
  autoload :Maxlength
18
+ autoload :Minlength
18
19
  autoload :Pattern
19
20
  autoload :Placeholders
20
21
  autoload :Readonly
@@ -0,0 +1,47 @@
1
+ module SimpleForm
2
+ module Components
3
+ # Needs to be enabled in order to do automatic lookups.
4
+ module Minlength
5
+ def minlength(wrapper_options = nil)
6
+ input_html_options[:minlength] ||= minimum_length_from_validation || limit
7
+ nil
8
+ end
9
+
10
+ private
11
+
12
+ def minimum_length_from_validation
13
+ minlength = options[:minlength]
14
+ if minlength.is_a?(String) || minlength.is_a?(Integer)
15
+ minlength
16
+ else
17
+ length_validator = find_length_validator
18
+ minimum_length_value_from(length_validator)
19
+ end
20
+ end
21
+
22
+ def find_length_validator
23
+ find_validator(:length)
24
+ end
25
+
26
+ def has_tokenizer?(length_validator)
27
+ length_validator.options[:tokenizer]
28
+ end
29
+
30
+ # Use validation with tokenizer if version of Rails is less than 5,
31
+ # if not validate without the tokenizer, if version is greater than Rails 4.
32
+ if ActionPack::VERSION::STRING < '5'
33
+ def minimum_length_value_from(length_validator)
34
+ if length_validator && !has_tokenizer?(length_validator)
35
+ length_validator.options[:is] || length_validator.options[:minimum]
36
+ end
37
+ end
38
+ elsif ActionPack::VERSION::STRING >= '5'
39
+ def minimum_length_value_from(length_validator)
40
+ if length_validator
41
+ length_validator.options[:is] || length_validator.options[:minimum]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -12,7 +12,7 @@ module SimpleForm
12
12
  'update' => 'edit'
13
13
  }
14
14
 
15
- ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :placeholder, :pattern, :readonly]
15
+ ATTRIBUTE_COMPONENTS = [:html5, :min_max, :maxlength, :minlength, :placeholder, :pattern, :readonly]
16
16
 
17
17
  extend MapType
18
18
  include SimpleForm::Inputs
@@ -21,6 +21,7 @@ module SimpleForm
21
21
  include SimpleForm::Components::HTML5
22
22
  include SimpleForm::Components::LabelInput
23
23
  include SimpleForm::Components::Maxlength
24
+ include SimpleForm::Components::Minlength
24
25
  include SimpleForm::Components::MinMax
25
26
  include SimpleForm::Components::Pattern
26
27
  include SimpleForm::Components::Placeholders
@@ -50,7 +51,7 @@ module SimpleForm
50
51
  enable :hint
51
52
 
52
53
  # Usually disabled, needs to be enabled explicitly passing true as option.
53
- disable :maxlength, :placeholder, :pattern, :min_max
54
+ disable :maxlength, :minlength, :placeholder, :pattern, :min_max
54
55
 
55
56
  def initialize(builder, attribute_name, column, input_type, options = {})
56
57
  super
@@ -6,7 +6,7 @@ module SimpleForm
6
6
 
7
7
  if nested_boolean_style?
8
8
  build_hidden_field_for_checkbox +
9
- template.label_tag(nil, class: SimpleForm.boolean_label_class) {
9
+ template.label_tag(nil, class: boolean_label_class) {
10
10
  build_check_box_without_hidden_field(merged_input_options) +
11
11
  inline_label
12
12
  }
@@ -21,7 +21,7 @@ module SimpleForm
21
21
  elsif nested_boolean_style?
22
22
  html_options = label_html_options.dup
23
23
  html_options[:class] ||= []
24
- html_options[:class].push(SimpleForm.boolean_label_class) if SimpleForm.boolean_label_class
24
+ html_options[:class].push(boolean_label_class) if boolean_label_class
25
25
 
26
26
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
27
27
 
@@ -36,6 +36,10 @@ module SimpleForm
36
36
 
37
37
  private
38
38
 
39
+ def boolean_label_class
40
+ options[:boolean_label_class] || SimpleForm.boolean_label_class
41
+ end
42
+
39
43
  # Build a checkbox tag using default unchecked value. This allows us to
40
44
  # reuse the method for nested boolean style, but with no unchecked value,
41
45
  # which won't generate the hidden checkbox. This is the default functionality
@@ -1,6 +1,9 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class CollectionInput < Base
4
+ BASIC_OBJECT_CLASSES = [String, Integer, Float, NilClass, Symbol, TrueClass, FalseClass]
5
+ BASIC_OBJECT_CLASSES.push(Fixnum, Bignum) unless 1.class == Integer
6
+
4
7
  # Default boolean collection for use with selects/radios when no
5
8
  # collection is given. Always fallback to this boolean collection.
6
9
  # Texts can be translated using i18n in "simple_form.yes" and
@@ -90,9 +93,7 @@ module SimpleForm
90
93
  end
91
94
 
92
95
  def collection_includes_basic_objects?(collection_classes)
93
- (collection_classes & [
94
- String, Integer, Fixnum, Bignum, Float, NilClass, Symbol, TrueClass, FalseClass
95
- ]).any?
96
+ (collection_classes & BASIC_OBJECT_CLASSES).any?
96
97
  end
97
98
 
98
99
  def translate_collection
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class PasswordInput < Base
4
- enable :placeholder, :maxlength
4
+ enable :placeholder, :maxlength, :minlength
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class StringInput < Base
4
- enable :placeholder, :maxlength, :pattern
4
+ enable :placeholder, :maxlength, :minlength, :pattern
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  unless string?
@@ -1,7 +1,7 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
3
  class TextInput < Base
4
- enable :placeholder, :maxlength
4
+ enable :placeholder, :maxlength, :minlength
5
5
 
6
6
  def input(wrapper_options = nil)
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "3.3.1".freeze
2
+ VERSION = "3.4.0".freeze
3
3
  end
@@ -87,7 +87,7 @@ class InputFieldTest < ActionView::TestCase
87
87
  assert_select 'input[pattern="\w+"]'
88
88
  end
89
89
 
90
- test 'builder input_field accepts custom patter' do
90
+ test 'builder input_field accepts custom pattern' do
91
91
  with_input_field_for @other_validating_user, :country, as: :string, pattern: '\d+'
92
92
 
93
93
  assert_select 'input[pattern="\d+"]'
@@ -105,6 +105,12 @@ class InputFieldTest < ActionView::TestCase
105
105
  assert_select 'input.string[maxlength="25"]'
106
106
  end
107
107
 
108
+ test 'builder input_field uses minlength component' do
109
+ with_input_field_for @validating_user, :name, as: :string
110
+
111
+ assert_select 'input.string[minlength="5"]'
112
+ end
113
+
108
114
  test 'builder collection input_field generates input tag with a clean HTML' do
109
115
  with_input_field_for @user, :status, collection: ['Open', 'Closed'],
110
116
  class: 'status', label_method: :to_s, value_method: :to_s
@@ -151,6 +157,14 @@ class InputFieldTest < ActionView::TestCase
151
157
  end
152
158
  end
153
159
 
160
+ test 'build input_field without minlength component use the minlength string' do
161
+ swap_wrapper :default, custom_wrapper_with_html5_components do
162
+ with_input_field_for @user, :name, minlength: 5
163
+
164
+ assert_select 'input[minlength="5"]'
165
+ end
166
+ end
167
+
154
168
  test 'build input_field without readonly component use the readonly string' do
155
169
  swap_wrapper :default, custom_wrapper_with_html5_components do
156
170
  with_input_field_for @user, :name, readonly: true
@@ -164,6 +164,16 @@ class BooleanInputTest < ActionView::TestCase
164
164
  end
165
165
  end
166
166
 
167
+ test 'input boolean allows specifying boolean_label_class on a per-input basis' do
168
+ swap_wrapper do
169
+ swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
170
+ with_input_for @user, :active, :boolean, boolean_label_class: 'baz'
171
+
172
+ assert_select 'label.boolean + input[type=hidden] + label.baz > input.boolean'
173
+ end
174
+ end
175
+ end
176
+
167
177
  test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra label wrapper with custom class' do
168
178
  swap_wrapper do
169
179
  swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
@@ -32,11 +32,21 @@ class StringInputTest < ActionView::TestCase
32
32
  assert_select 'input.string[maxlength="25"]'
33
33
  end
34
34
 
35
+ test 'input infers minlength column definition from validation when present' do
36
+ with_input_for @validating_user, :name, :string
37
+ assert_select 'input.string[minlength="5"]'
38
+ end
39
+
35
40
  if ActionPack::VERSION::STRING < '5'
36
41
  test 'input does not get maxlength from validation when tokenizer present' do
37
42
  with_input_for @validating_user, :action, :string
38
43
  assert_no_select 'input.string[maxlength]'
39
44
  end
45
+
46
+ test 'input does not get minlength from validation when tokenizer present' do
47
+ with_input_for @validating_user, :action, :string
48
+ assert_no_select 'input.string[minlength]'
49
+ end
40
50
  end
41
51
 
42
52
  test 'input gets maxlength from validation when :is option present' do
@@ -44,6 +54,11 @@ class StringInputTest < ActionView::TestCase
44
54
  assert_select 'input.string[maxlength="12"]'
45
55
  end
46
56
 
57
+ test 'input gets minlength from validation when :is option present' do
58
+ with_input_for @validating_user, :home_picture, :string
59
+ assert_select 'input.string[minlength="12"]'
60
+ end
61
+
47
62
  test 'input maxlength is the column limit plus one to make room for decimal point' do
48
63
  with_input_for @user, :credit_limit, :string
49
64
 
@@ -28,4 +28,9 @@ class TextInputTest < ActionView::TestCase
28
28
  with_input_for @validating_user, :description, :text
29
29
  assert_select 'textarea.text[maxlength="50"]'
30
30
  end
31
+
32
+ test 'input infers minlength column definition from validation when present for text attributes' do
33
+ with_input_for @validating_user, :description, :text
34
+ assert_select 'textarea.text[minlength="15"]'
35
+ end
31
36
  end
@@ -236,8 +236,8 @@ class ValidatingUser < User
236
236
  greater_than_or_equal_to: :min_attempts,
237
237
  less_than_or_equal_to: :max_attempts,
238
238
  only_integer: true
239
- validates_length_of :name, maximum: 25
240
- validates_length_of :description, maximum: 50
239
+ validates_length_of :name, maximum: 25, minimum: 5
240
+ validates_length_of :description, in: 15..50
241
241
  if ActionPack::VERSION::STRING < '5'
242
242
  validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
243
243
  end
@@ -55,6 +55,8 @@ class ActionView::TestCase
55
55
  @user = User.build(extra_attributes)
56
56
 
57
57
  @validating_user = ValidatingUser.build({
58
+ name: 'Tester McTesterson',
59
+ description: 'A test user of the most distinguised caliber',
58
60
  home_picture: 'Home picture',
59
61
  age: 19,
60
62
  amount: 15,
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.3.1
4
+ version: 3.4.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: 2016-08-26 00:00:00.000000000 Z
13
+ date: 2017-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -82,6 +82,7 @@ files:
82
82
  - lib/simple_form/components/labels.rb
83
83
  - lib/simple_form/components/maxlength.rb
84
84
  - lib/simple_form/components/min_max.rb
85
+ - lib/simple_form/components/minlength.rb
85
86
  - lib/simple_form/components/pattern.rb
86
87
  - lib/simple_form/components/placeholders.rb
87
88
  - lib/simple_form/components/readonly.rb
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
179
  version: '0'
179
180
  requirements: []
180
181
  rubyforge_project: simple_form
181
- rubygems_version: 2.5.1
182
+ rubygems_version: 2.6.8
182
183
  signing_key:
183
184
  specification_version: 4
184
185
  summary: Forms made easy!