simple_form 1.5.0 → 1.5.1

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.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.5.1
2
+
3
+ * enhancements
4
+ * `:components` options is now deprecated
5
+
6
+ * bug fix
7
+ * Fallback to default label when block is provided (github.com/pivotal-casebook)
8
+ * Do not override default selection through attribute value in collection select when label/value methods are lambdas
9
+
1
10
  == 1.5.0
2
11
 
3
12
  * enhancements
@@ -178,8 +178,11 @@ class ActionView::Helpers::FormBuilder
178
178
 
179
179
  [value, text, selected, disabled]
180
180
  end
181
- options[:disabled] = collection.map(&:pop).compact
182
- options[:selected] = collection.map(&:pop).compact
181
+
182
+ [:disabled, :selected].each do |option|
183
+ option_value = collection.map(&:pop).compact
184
+ options[option] = option_value if option_value.present?
185
+ end
183
186
  value_method, text_method = :first, :last
184
187
  end
185
188
 
@@ -266,7 +266,7 @@ module SimpleForm
266
266
  # f.label :name, :id => "cool_label"
267
267
  #
268
268
  def label(attribute_name, *args)
269
- return super if args.first.is_a?(String)
269
+ return super if args.first.is_a?(String) || block_given?
270
270
  options = args.extract_options!
271
271
  options[:label_html] = options.dup
272
272
  options[:label] = options.delete(:label)
@@ -82,7 +82,12 @@ module SimpleForm
82
82
  end
83
83
 
84
84
  def components_list
85
- options[:components] || SimpleForm.components
85
+ if components = options[:components]
86
+ ActiveSupport::Deprecation.warn "The option :components of f.input is deprecated. Please turn off each component individually instead."
87
+ components
88
+ else
89
+ SimpleForm.components
90
+ end
86
91
  end
87
92
 
88
93
  def has_autofocus?
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.5.1".freeze
3
3
  end
@@ -39,9 +39,9 @@ class FormBuilderTest < ActionView::TestCase
39
39
  end
40
40
  end
41
41
 
42
- def with_label_for(object, *args)
42
+ def with_label_for(object, *args, &block)
43
43
  with_concat_form_for(object) do |f|
44
- f.label(*args)
44
+ f.label(*args, &block)
45
45
  end
46
46
  end
47
47
 
@@ -453,50 +453,60 @@ class FormBuilderTest < ActionView::TestCase
453
453
 
454
454
  # ONLY THE INPUT TAG
455
455
  test "builder input_field should only render the input tag, nothing else" do
456
- with_concat_form_for(@user) do |f|
457
- f.input_field :name
456
+ ActiveSupport::Deprecation.silence do
457
+ with_concat_form_for(@user) do |f|
458
+ f.input_field :name
459
+ end
460
+ assert_select 'form > input.required.string'
461
+ assert_no_select 'div.string'
462
+ assert_no_select 'label'
463
+ assert_no_select '.hint'
458
464
  end
459
- assert_select 'form > input.required.string'
460
- assert_no_select 'div.string'
461
- assert_no_select 'label'
462
- assert_no_select '.hint'
463
465
  end
464
466
 
465
467
  test 'builder input_field should allow overriding default input type' do
466
- with_concat_form_for(@user) do |f|
467
- f.input_field :name, :as => :text
468
- end
468
+ ActiveSupport::Deprecation.silence do
469
+ with_concat_form_for(@user) do |f|
470
+ f.input_field :name, :as => :text
471
+ end
469
472
 
470
- assert_no_select 'input#user_name'
471
- assert_select 'textarea#user_name.text'
473
+ assert_no_select 'input#user_name'
474
+ assert_select 'textarea#user_name.text'
475
+ end
472
476
  end
473
477
 
474
478
  test 'builder input_field should allow passing options to input tag' do
475
- with_concat_form_for(@user) do |f|
476
- f.input_field :name, :id => 'name_input', :class => 'name'
477
- end
479
+ ActiveSupport::Deprecation.silence do
480
+ with_concat_form_for(@user) do |f|
481
+ f.input_field :name, :id => 'name_input', :class => 'name'
482
+ end
478
483
 
479
- assert_select 'input.string.name#name_input'
484
+ assert_select 'input.string.name#name_input'
485
+ end
480
486
  end
481
487
 
482
488
  test 'builder input_field should generate an input tag with a clean HTML' do
483
- with_concat_form_for(@user) do |f|
484
- f.input_field :name, :as => :integer, :class => 'name'
485
- end
489
+ ActiveSupport::Deprecation.silence do
490
+ with_concat_form_for(@user) do |f|
491
+ f.input_field :name, :as => :integer, :class => 'name'
492
+ end
486
493
 
487
- assert_no_select 'input.integer[input_html]'
488
- assert_no_select 'input.integer[as]'
494
+ assert_no_select 'input.integer[input_html]'
495
+ assert_no_select 'input.integer[as]'
496
+ end
489
497
  end
490
498
 
491
499
  test 'builder collection input_field should generate input tag with a clean HTML' do
492
- with_concat_form_for(@user) do |f|
493
- f.input_field :status, :collection => ['Open', 'Closed'], :class => 'status', :label_method => :to_s, :value_method => :to_s
494
- end
500
+ ActiveSupport::Deprecation.silence do
501
+ with_concat_form_for(@user) do |f|
502
+ f.input_field :status, :collection => ['Open', 'Closed'], :class => 'status', :label_method => :to_s, :value_method => :to_s
503
+ end
495
504
 
496
- assert_no_select 'select.status[input_html]'
497
- assert_no_select 'select.status[collection]'
498
- assert_no_select 'select.status[label_method]'
499
- assert_no_select 'select.status[value_method]'
505
+ assert_no_select 'select.status[input_html]'
506
+ assert_no_select 'select.status[collection]'
507
+ assert_no_select 'select.status[label_method]'
508
+ assert_no_select 'select.status[value_method]'
509
+ end
500
510
  end
501
511
 
502
512
  # WITHOUT OBJECT
@@ -627,6 +637,14 @@ class FormBuilderTest < ActionView::TestCase
627
637
  assert_no_select 'label.string'
628
638
  end
629
639
 
640
+ test 'builder should fallback to default label when block is given' do
641
+ with_label_for @user, :name do
642
+ 'Nome do usuário'
643
+ end
644
+ assert_select 'label', 'Nome do usuário'
645
+ assert_no_select 'label.string'
646
+ end
647
+
630
648
  test 'builder allows label order to be changed' do
631
649
  swap SimpleForm, :label_text => lambda { |l, r| "#{l}:" } do
632
650
  with_label_for @user, :age
data/test/inputs_test.rb CHANGED
@@ -104,30 +104,38 @@ class InputTest < ActionView::TestCase
104
104
  end
105
105
  end
106
106
 
107
+ test 'components option is deprecated' do
108
+ assert_deprecated(/The option :components of f\.input is deprecated/) do
109
+ with_input_for @user, :name, :string, :components => [:input]
110
+ end
111
+ end
112
+
107
113
  test 'input should render components according to an optional :components option' do
108
- with_input_for @user, :name, :string, :components => [:input, :label]
109
- assert_select 'input + label'
114
+ ActiveSupport::Deprecation.silence do
115
+ with_input_for @user, :name, :string, :components => [:input, :label]
116
+ assert_select 'input + label'
110
117
 
111
- with_input_for @user, :age, :integer, :components => [:input, :label]
112
- assert_select 'input + label'
118
+ with_input_for @user, :age, :integer, :components => [:input, :label]
119
+ assert_select 'input + label'
113
120
 
114
- with_input_for @user, :active, :boolean, :components => [:label, :input]
115
- assert_select 'label + input'
121
+ with_input_for @user, :active, :boolean, :components => [:label, :input]
122
+ assert_select 'label + input'
116
123
 
117
- with_input_for @user, :description, :text, :components => [:input, :label]
118
- assert_select 'textarea + label'
124
+ with_input_for @user, :description, :text, :components => [:input, :label]
125
+ assert_select 'textarea + label'
119
126
 
120
- with_input_for @user, :password, :password, :components => [:input, :label]
121
- assert_select 'input + label'
127
+ with_input_for @user, :password, :password, :components => [:input, :label]
128
+ assert_select 'input + label'
122
129
 
123
- with_input_for @user, :name, :file, :components => [:input, :label]
124
- assert_select 'input + label'
130
+ with_input_for @user, :name, :file, :components => [:input, :label]
131
+ assert_select 'input + label'
125
132
 
126
- with_input_for @user, :country, :country, :components => [:input, :label]
127
- assert_select 'select + label'
133
+ with_input_for @user, :country, :country, :components => [:input, :label]
134
+ assert_select 'select + label'
128
135
 
129
- with_input_for @user, :time_zone, :time_zone, :components => [:input, :label]
130
- assert_select 'select + label'
136
+ with_input_for @user, :time_zone, :time_zone, :components => [:input, :label]
137
+ assert_select 'select + label'
138
+ end
131
139
  end
132
140
 
133
141
  # StringInput
@@ -839,6 +847,15 @@ class InputTest < ActionView::TestCase
839
847
  assert_no_select 'select option[value=Antonio][selected]'
840
848
  end
841
849
 
850
+ test 'input should not override default selection through attribute value with label method as lambda for collection select' do
851
+ @user.name = "Carlos"
852
+ with_input_for @user, :name, :select, :collection => ["Carlos", "Antonio"],
853
+ :label_method => lambda { |x| x.upcase }
854
+ assert_select 'select option[value=Carlos][selected=selected]', 'CARLOS'
855
+ assert_select 'select option[value=Antonio]', 'ANTONIO'
856
+ assert_no_select 'select option[value=Antonio][selected]'
857
+ end
858
+
842
859
  test 'input should allow overriding collection for radio types' do
843
860
  with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos']
844
861
  assert_select 'input[type=radio][value=Jose]'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 0
10
- version: 1.5.0
9
+ - 1
10
+ version: 1.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jos\xC3\xA9 Valim"
@@ -16,13 +16,13 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-09-08 00:00:00 -03:00
19
+ date: 2011-09-15 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: activemodel
24
24
  prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ~>
@@ -33,11 +33,11 @@ dependencies:
33
33
  - 0
34
34
  version: "3.0"
35
35
  type: :runtime
36
- version_requirements: *id001
36
+ requirement: *id001
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: actionpack
39
39
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -48,7 +48,7 @@ dependencies:
48
48
  - 0
49
49
  version: "3.0"
50
50
  type: :runtime
51
- version_requirements: *id002
51
+ requirement: *id002
52
52
  description: Forms made easy!
53
53
  email: contact@plataformatec.com.br
54
54
  executables: []