simple_form 2.1.3 → 3.0.0.beta1

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.

Files changed (72) hide show
  1. data/CHANGELOG.md +6 -54
  2. data/README.md +129 -111
  3. data/lib/generators/simple_form/install_generator.rb +4 -4
  4. data/lib/generators/simple_form/templates/README +2 -2
  5. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +8 -11
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +16 -16
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
  8. data/lib/simple_form.rb +31 -47
  9. data/lib/simple_form/action_view_extensions/builder.rb +0 -319
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components.rb +1 -1
  13. data/lib/simple_form/components/errors.rb +1 -7
  14. data/lib/simple_form/components/hints.rb +2 -7
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/labels.rb +4 -4
  17. data/lib/simple_form/components/maxlength.rb +1 -8
  18. data/lib/simple_form/error_notification.rb +2 -2
  19. data/lib/simple_form/form_builder.rb +144 -46
  20. data/lib/simple_form/form_builder.rb.orig +486 -0
  21. data/lib/simple_form/helpers.rb +1 -1
  22. data/lib/simple_form/inputs/base.rb +3 -10
  23. data/lib/simple_form/inputs/block_input.rb +1 -1
  24. data/lib/simple_form/inputs/boolean_input.rb +6 -6
  25. data/lib/simple_form/inputs/collection_input.rb +7 -7
  26. data/lib/simple_form/inputs/numeric_input.rb +0 -6
  27. data/lib/simple_form/inputs/password_input.rb +0 -1
  28. data/lib/simple_form/inputs/string_input.rb +0 -1
  29. data/lib/simple_form/railtie.rb +7 -0
  30. data/lib/simple_form/tags.rb +61 -0
  31. data/lib/simple_form/version.rb +1 -1
  32. data/lib/simple_form/version.rb.orig +7 -0
  33. data/lib/simple_form/wrappers.rb +1 -1
  34. data/lib/simple_form/wrappers/builder.rb +5 -29
  35. data/lib/simple_form/wrappers/many.rb +1 -1
  36. data/lib/simple_form/wrappers/root.rb +1 -1
  37. data/test/action_view_extensions/builder_test.rb +67 -87
  38. data/test/action_view_extensions/form_helper_test.rb +16 -16
  39. data/test/components/label_test.rb +46 -46
  40. data/test/form_builder/association_test.rb +23 -23
  41. data/test/form_builder/button_test.rb +4 -4
  42. data/test/form_builder/error_notification_test.rb +8 -8
  43. data/test/form_builder/error_test.rb +18 -65
  44. data/test/form_builder/general_test.rb +45 -65
  45. data/test/form_builder/hint_test.rb +23 -29
  46. data/test/form_builder/input_field_test.rb +12 -12
  47. data/test/form_builder/label_test.rb +6 -16
  48. data/test/form_builder/wrapper_test.rb +21 -21
  49. data/test/inputs/boolean_input_test.rb +23 -35
  50. data/test/inputs/collection_check_boxes_input_test.rb +55 -55
  51. data/test/inputs/collection_radio_buttons_input_test.rb +70 -79
  52. data/test/inputs/collection_select_input_test.rb +45 -51
  53. data/test/inputs/datetime_input_test.rb +11 -11
  54. data/test/inputs/disabled_test.rb +10 -10
  55. data/test/inputs/discovery_test.rb +4 -4
  56. data/test/inputs/file_input_test.rb +1 -1
  57. data/test/inputs/general_test.rb +12 -12
  58. data/test/inputs/grouped_collection_select_input_test.rb +20 -20
  59. data/test/inputs/hidden_input_test.rb +1 -1
  60. data/test/inputs/numeric_input_test.rb +3 -3
  61. data/test/inputs/priority_input_test.rb +3 -3
  62. data/test/inputs/readonly_test.rb +12 -12
  63. data/test/inputs/required_test.rb +5 -5
  64. data/test/inputs/string_input_test.rb +10 -25
  65. data/test/inputs/text_input_test.rb +1 -1
  66. data/test/support/misc_helpers.rb +24 -24
  67. data/test/support/mock_controller.rb +6 -6
  68. data/test/support/models.rb +37 -46
  69. data/test/test_helper.rb +20 -20
  70. metadata +49 -24
  71. checksums.yaml +0 -7
  72. data/lib/simple_form/core_ext/hash.rb +0 -16
@@ -14,43 +14,37 @@ class HintTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'hint should be generated with optional text' do
17
- with_hint_for @user, :name, :hint => 'Use with care...'
17
+ with_hint_for @user, :name, hint: 'Use with care...'
18
18
  assert_select 'span.hint', 'Use with care...'
19
19
  end
20
20
 
21
21
  test 'hint should not modify the options hash' do
22
- options = { :hint => 'Use with care...' }
22
+ options = { hint: 'Use with care...' }
23
23
  with_hint_for @user, :name, options
24
24
  assert_select 'span.hint', 'Use with care...'
25
- assert_equal({ :hint => 'Use with care...' }, options)
25
+ assert_equal({ hint: 'Use with care...' }, options)
26
26
  end
27
27
 
28
28
  test 'hint should be generated cleanly with optional text' do
29
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :span
29
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :span
30
30
  assert_no_select 'span.hint[hint]'
31
31
  assert_no_select 'span.hint[hint_tag]'
32
32
  assert_no_select 'span.hint[hint_html]'
33
33
  end
34
34
 
35
35
  test 'hint uses the current component tag set' do
36
- with_hint_for @user, :name, :hint => 'Use with care...', :hint_tag => :p
36
+ with_hint_for @user, :name, hint: 'Use with care...', hint_tag: :p
37
37
  assert_select 'p.hint', 'Use with care...'
38
38
  end
39
39
 
40
40
  test 'hint should be able to pass html options' do
41
- with_hint_for @user, :name, :hint => 'Yay!', :id => 'hint', :class => 'yay'
41
+ with_hint_for @user, :name, hint: 'Yay!', id: 'hint', class: 'yay'
42
42
  assert_select 'span#hint.hint.yay'
43
43
  end
44
44
 
45
45
  test 'hint should be output as html_safe' do
46
- with_hint_for @user, :name, :hint => '<b>Bold</b> and not...'.html_safe
46
+ with_hint_for @user, :name, hint: '<b>Bold</b> and not...'
47
47
  assert_select 'span.hint', 'Bold and not...'
48
- assert_select 'span.hint b', 'Bold'
49
- end
50
-
51
- test 'builder should escape hint text' do
52
- with_hint_for @user, :name, :hint => '<script>alert(1337)</script>'
53
- assert_select 'span.hint', "&lt;script&gt;alert(1337)&lt;/script&gt;"
54
48
  end
55
49
 
56
50
  # Without attribute name
@@ -67,22 +61,22 @@ class HintTest < ActionView::TestCase
67
61
  end
68
62
 
69
63
  test 'hint without attribute name uses the current component tag set' do
70
- with_hint_for @user, 'Hello World!', :hint_tag => :p
64
+ with_hint_for @user, 'Hello World!', hint_tag: :p
71
65
  assert_no_select 'p.hint[hint]'
72
66
  assert_no_select 'p.hint[hint_html]'
73
67
  assert_no_select 'p.hint[hint_tag]'
74
68
  end
75
69
 
76
70
  test 'hint without attribute name should be able to pass html options' do
77
- with_hint_for @user, 'Yay', :id => 'hint', :class => 'yay'
71
+ with_hint_for @user, 'Yay', id: 'hint', class: 'yay'
78
72
  assert_select 'span#hint.hint.yay', 'Yay'
79
73
  end
80
74
 
81
75
  # I18n
82
76
 
83
77
  test 'hint should use i18n based on model, action, and attribute to lookup translation' do
84
- store_translations(:en, :simple_form => { :hints => { :user => {
85
- :edit => { :name => 'Content of this input will be truncated...' }
78
+ store_translations(:en, simple_form: { hints: { user: {
79
+ edit: { name: 'Content of this input will be truncated...' }
86
80
  } } }) do
87
81
  with_hint_for @user, :name
88
82
  assert_select 'span.hint', 'Content of this input will be truncated...'
@@ -90,8 +84,8 @@ class HintTest < ActionView::TestCase
90
84
  end
91
85
 
92
86
  test 'hint should use i18n with model and attribute to lookup translation' do
93
- store_translations(:en, :simple_form => { :hints => { :user => {
94
- :name => 'Content of this input will be capitalized...'
87
+ store_translations(:en, simple_form: { hints: { user: {
88
+ name: 'Content of this input will be capitalized...'
95
89
  } } }) do
96
90
  with_hint_for @user, :name
97
91
  assert_select 'span.hint', 'Content of this input will be capitalized...'
@@ -99,8 +93,8 @@ class HintTest < ActionView::TestCase
99
93
  end
100
94
 
101
95
  test 'hint should use i18n under defaults namespace to lookup translation' do
102
- store_translations(:en, :simple_form => {
103
- :hints => {:defaults => {:name => 'Content of this input will be downcased...' } }
96
+ store_translations(:en, simple_form: {
97
+ hints: {defaults: {name: 'Content of this input will be downcased...' } }
104
98
  }) do
105
99
  with_hint_for @user, :name
106
100
  assert_select 'span.hint', 'Content of this input will be downcased...'
@@ -108,17 +102,17 @@ class HintTest < ActionView::TestCase
108
102
  end
109
103
 
110
104
  test 'hint should use i18n with lookup for association name' do
111
- store_translations(:en, :simple_form => { :hints => {
112
- :user => { :company => 'My company!' }
105
+ store_translations(:en, simple_form: { hints: {
106
+ user: { company: 'My company!' }
113
107
  } } ) do
114
- with_hint_for @user, :company_id, :as => :string, :reflection => Association.new(Company, :company, {})
108
+ with_hint_for @user, :company_id, as: :string, reflection: Association.new(Company, :company, {})
115
109
  assert_select 'span.hint', /My company!/
116
110
  end
117
111
  end
118
112
 
119
113
  test 'hint should output translations as html_safe' do
120
- store_translations(:en, :simple_form => { :hints => { :user => {
121
- :edit => { :name => '<b>This is bold</b> and this is not...' }
114
+ store_translations(:en, simple_form: { hints: { user: {
115
+ edit: { name: '<b>This is bold</b> and this is not...' }
122
116
  } } }) do
123
117
  with_hint_for @user, :name
124
118
  assert_select 'span.hint', 'This is bold and this is not...'
@@ -129,7 +123,7 @@ class HintTest < ActionView::TestCase
129
123
  # No object
130
124
 
131
125
  test 'hint should generate properly when object is not present' do
132
- with_hint_for :project, :name, :hint => 'Test without object'
126
+ with_hint_for :project, :name, hint: 'Test without object'
133
127
  assert_select 'span.hint', 'Test without object'
134
128
  end
135
129
 
@@ -137,8 +131,8 @@ class HintTest < ActionView::TestCase
137
131
 
138
132
  test 'hint with custom wrappers works' do
139
133
  swap_wrapper do
140
- with_hint_for @user, :name, :hint => "can't be blank"
141
- assert_select 'div.omg_hint', "can&#x27;t be blank"
134
+ with_hint_for @user, :name, hint: "can't be blank"
135
+ assert_select 'div.omg_hint', "can't be blank"
142
136
  end
143
137
  end
144
138
  end
@@ -14,7 +14,7 @@ class InputFieldTest < ActionView::TestCase
14
14
 
15
15
  test 'builder input_field should allow overriding default input type' do
16
16
  with_concat_form_for(@user) do |f|
17
- f.input_field :name, :as => :text
17
+ f.input_field :name, as: :text
18
18
  end
19
19
 
20
20
  assert_no_select 'input#user_name'
@@ -23,27 +23,27 @@ class InputFieldTest < ActionView::TestCase
23
23
 
24
24
  test 'builder input_field should allow passing options to input tag' do
25
25
  with_concat_form_for(@user) do |f|
26
- f.input_field :name, :id => 'name_input', :class => 'name'
26
+ f.input_field :name, id: 'name_input', class: 'name'
27
27
  end
28
28
 
29
29
  assert_select 'input.string.name#name_input'
30
30
  end
31
31
 
32
32
  test 'builder input_field should not modify the options hash' do
33
- options = { :id => 'name_input', :class => 'name' }
33
+ options = { id: 'name_input', class: 'name' }
34
34
 
35
35
  with_concat_form_for(@user) do |f|
36
36
  f.input_field :name, options
37
37
  end
38
38
 
39
39
  assert_select 'input.string.name#name_input'
40
- assert_equal({ :id => 'name_input', :class => 'name' }, options)
40
+ assert_equal({ id: 'name_input', class: 'name' }, options)
41
41
  end
42
42
 
43
43
 
44
44
  test 'builder input_field should generate an input tag with a clean HTML' do
45
45
  with_concat_form_for(@user) do |f|
46
- f.input_field :name, :as => :integer, :class => 'name'
46
+ f.input_field :name, as: :integer, class: 'name'
47
47
  end
48
48
 
49
49
  assert_no_select 'input.integer[input_html]'
@@ -51,8 +51,8 @@ class InputFieldTest < ActionView::TestCase
51
51
  end
52
52
 
53
53
  test 'builder input_field should use i18n to translate placeholder text' do
54
- store_translations(:en, :simple_form => { :placeholders => { :user => {
55
- :name => 'Name goes here'
54
+ store_translations(:en, simple_form: { placeholders: { user: {
55
+ name: 'Name goes here'
56
56
  } } }) do
57
57
 
58
58
  with_concat_form_for(@user) do |f|
@@ -65,7 +65,7 @@ class InputFieldTest < ActionView::TestCase
65
65
 
66
66
  test 'builder input_field should use min_max component' do
67
67
  with_concat_form_for(@other_validating_user) do |f|
68
- f.input_field :age, :as => :integer
68
+ f.input_field :age, as: :integer
69
69
  end
70
70
 
71
71
  assert_select 'input[min=18]'
@@ -73,7 +73,7 @@ class InputFieldTest < ActionView::TestCase
73
73
 
74
74
  test 'builder input_field should use pattern component' do
75
75
  with_concat_form_for(@other_validating_user) do |f|
76
- f.input_field :country, :as => :string
76
+ f.input_field :country, as: :string
77
77
  end
78
78
 
79
79
  assert_select 'input[pattern="\w+"]'
@@ -81,7 +81,7 @@ class InputFieldTest < ActionView::TestCase
81
81
 
82
82
  test 'builder input_field should use readonly component' do
83
83
  with_concat_form_for(@other_validating_user) do |f|
84
- f.input_field :age, :as => :integer, :readonly => true
84
+ f.input_field :age, as: :integer, readonly: true
85
85
  end
86
86
 
87
87
  assert_select 'input.integer.readonly[readonly]'
@@ -89,7 +89,7 @@ class InputFieldTest < ActionView::TestCase
89
89
 
90
90
  test 'builder input_field should use maxlength component' do
91
91
  with_concat_form_for(@validating_user) do |f|
92
- f.input_field :name, :as => :string
92
+ f.input_field :name, as: :string
93
93
  end
94
94
 
95
95
  assert_select 'input.string[maxlength=25]'
@@ -97,7 +97,7 @@ class InputFieldTest < ActionView::TestCase
97
97
 
98
98
  test 'builder collection input_field should generate input tag with a clean HTML' do
99
99
  with_concat_form_for(@user) do |f|
100
- f.input_field :status, :collection => ['Open', 'Closed'], :class => 'status', :label_method => :to_s, :value_method => :to_s
100
+ f.input_field :status, collection: ['Open', 'Closed'], class: 'status', label_method: :to_s, value_method: :to_s
101
101
  end
102
102
 
103
103
  assert_no_select 'select.status[input_html]'
@@ -14,7 +14,7 @@ class LabelTest < ActionView::TestCase
14
14
  end
15
15
 
16
16
  test 'builder should generate a label for the boolean attrbiute' do
17
- with_label_for @user, :name, :as => :boolean
17
+ with_label_for @user, :name, as: :boolean
18
18
  assert_select 'label.boolean[for=user_name]', /Name/
19
19
  assert_no_select 'label[as=boolean]'
20
20
  end
@@ -29,33 +29,23 @@ class LabelTest < ActionView::TestCase
29
29
  assert_select 'label.string.required[for=validating_user_name]', /Name/
30
30
  end
31
31
 
32
- test 'builder should escape label text' do
33
- with_label_for @user, :name, :label => '<script>alert(1337)</script>', :required => false
34
- assert_select 'label.string', "&lt;script&gt;alert(1337)&lt;/script&gt;"
35
- end
36
-
37
- test 'builder should not escape label text if it is safe' do
38
- with_label_for @user, :name, :label => '<script>alert(1337)</script>'.html_safe, :required => false
39
- assert_select 'label.string script', "alert(1337)"
40
- end
41
-
42
32
  test 'builder should allow passing options to label tag' do
43
- with_label_for @user, :name, :label => 'My label', :id => 'name_label'
33
+ with_label_for @user, :name, label: 'My label', id: 'name_label'
44
34
  assert_select 'label.string#name_label', /My label/
45
35
  end
46
36
 
47
37
  test 'builder label should generate label tag with clean HTML' do
48
- with_label_for @user, :name, :label => 'My label', :required => true, :id => 'name_label'
38
+ with_label_for @user, :name, label: 'My label', required: true, id: 'name_label'
49
39
  assert_select 'label.string#name_label', /My label/
50
40
  assert_no_select 'label[label]'
51
41
  assert_no_select 'label[required]'
52
42
  end
53
43
 
54
44
  test 'builder should not modify the options hash' do
55
- options = { :label => 'My label', :id => 'name_label' }
45
+ options = { label: 'My label', id: 'name_label' }
56
46
  with_label_for @user, :name, options
57
47
  assert_select 'label.string#name_label', /My label/
58
- assert_equal({ :label => 'My label', :id => 'name_label' }, options)
48
+ assert_equal({ label: 'My label', id: 'name_label' }, options)
59
49
  end
60
50
 
61
51
  test 'builder should fallback to default label when string is given' do
@@ -73,7 +63,7 @@ class LabelTest < ActionView::TestCase
73
63
  end
74
64
 
75
65
  test 'builder allows label order to be changed' do
76
- swap SimpleForm, :label_text => lambda { |l, r| "#{l}:" } do
66
+ swap SimpleForm, label_text: lambda { |l, r| "#{l}:" } do
77
67
  with_label_for @user, :age
78
68
  assert_select 'label.integer[for=user_age]', "Age:"
79
69
  end
@@ -38,7 +38,7 @@ class WrapperTest < ActionView::TestCase
38
38
  end
39
39
 
40
40
  test 'wrapper should add hint class for attribute with a hint' do
41
- with_form_for @user, :name, :hint => 'hint'
41
+ with_form_for @user, :name, hint: 'hint'
42
42
  assert_select 'div.field_with_hint'
43
43
  end
44
44
 
@@ -48,18 +48,18 @@ class WrapperTest < ActionView::TestCase
48
48
  end
49
49
 
50
50
  test 'wrapper should have disabled class when input is disabled' do
51
- with_form_for @user, :active, :disabled => true
51
+ with_form_for @user, :active, disabled: true
52
52
  assert_select 'div.disabled'
53
53
  end
54
54
 
55
55
  test 'wrapper should support no wrapping when wrapper is false' do
56
- with_form_for @user, :name, :wrapper => false
56
+ with_form_for @user, :name, wrapper: false
57
57
  assert_select 'form > label[for=user_name]'
58
58
  assert_select 'form > input#user_name.string'
59
59
  end
60
60
 
61
61
  test 'wrapper should support no wrapping when wrapper tag is false' do
62
- with_form_for @user, :name, :wrapper => custom_wrapper_without_top_level
62
+ with_form_for @user, :name, wrapper: custom_wrapper_without_top_level
63
63
  assert_select 'form > label[for=user_name]'
64
64
  assert_select 'form > input#user_name.string'
65
65
  end
@@ -68,28 +68,28 @@ class WrapperTest < ActionView::TestCase
68
68
  with_form_for @user, :name
69
69
  assert_select 'form div.input.required.string'
70
70
 
71
- with_form_for @user, :age, :required => false
71
+ with_form_for @user, :age, required: false
72
72
  assert_select 'form div.input.optional.integer'
73
73
  end
74
74
 
75
75
  test 'wrapper should allow custom options to be given' do
76
- with_form_for @user, :name, :wrapper_html => { :id => "super_cool", :class => 'yay' }
76
+ with_form_for @user, :name, wrapper_html: { id: "super_cool", class: 'yay' }
77
77
  assert_select 'form #super_cool.required.string.yay'
78
78
  end
79
79
 
80
80
  test 'wrapper should allow tag to be given on demand' do
81
- with_form_for @user, :name, :wrapper_tag => :b
81
+ with_form_for @user, :name, wrapper_tag: :b
82
82
  assert_select 'form b.required.string'
83
83
  end
84
84
 
85
85
  test 'wrapper should allow wrapper class to be given on demand' do
86
- with_form_for @user, :name, :wrapper_class => :wrapper
86
+ with_form_for @user, :name, wrapper_class: :wrapper
87
87
  assert_select 'form div.wrapper.required.string'
88
88
  end
89
89
 
90
90
  test 'wrapper should skip additional classes when configured' do
91
- swap SimpleForm, :generate_additional_classes_for => [:input, :label] do
92
- with_form_for @user, :name, :wrapper_class => :wrapper
91
+ swap SimpleForm, generate_additional_classes_for: [:input, :label] do
92
+ with_form_for @user, :name, wrapper_class: :wrapper
93
93
  assert_select 'form div.wrapper'
94
94
  assert_no_select 'div.required'
95
95
  assert_no_select 'div.string'
@@ -98,7 +98,7 @@ class WrapperTest < ActionView::TestCase
98
98
  end
99
99
 
100
100
  test 'wrapper should not generate empty css class' do
101
- swap SimpleForm, :generate_additional_classes_for => [:input, :label] do
101
+ swap SimpleForm, generate_additional_classes_for: [:input, :label] do
102
102
  swap_wrapper :default, custom_wrapper_without_class do
103
103
  with_form_for @user, :name
104
104
  assert_no_select 'div#custom_wrapper_without_class[class]'
@@ -110,7 +110,7 @@ class WrapperTest < ActionView::TestCase
110
110
 
111
111
  test 'custom wrappers works' do
112
112
  swap_wrapper do
113
- with_form_for @user, :name, :hint => "cool"
113
+ with_form_for @user, :name, hint: "cool"
114
114
  assert_select "section.custom_wrapper div.another_wrapper label"
115
115
  assert_select "section.custom_wrapper div.another_wrapper input.string"
116
116
  assert_no_select "section.custom_wrapper div.another_wrapper span.omg_error"
@@ -121,7 +121,7 @@ class WrapperTest < ActionView::TestCase
121
121
 
122
122
  test 'custom wrappers can be turned off' do
123
123
  swap_wrapper do
124
- with_form_for @user, :name, :another => false
124
+ with_form_for @user, :name, another: false
125
125
  assert_no_select "section.custom_wrapper div.another_wrapper label"
126
126
  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
127
127
  assert_select "section.custom_wrapper div.error_wrapper span.omg_error"
@@ -137,7 +137,7 @@ class WrapperTest < ActionView::TestCase
137
137
  assert_no_select "section.custom_wrapper div.another_wrapper label"
138
138
  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
139
139
 
140
- with_concat_form_for(@user, :wrapper => :another) do |f|
140
+ with_concat_form_for(@user, wrapper: :another) do |f|
141
141
  f.input :name
142
142
  end
143
143
 
@@ -153,20 +153,20 @@ class WrapperTest < ActionView::TestCase
153
153
  assert_no_select "section.custom_wrapper div.another_wrapper input.string"
154
154
  output_buffer.replace ""
155
155
 
156
- with_form_for @user, :name, :wrapper => :another
156
+ with_form_for @user, :name, wrapper: :another
157
157
  assert_select "section.custom_wrapper div.another_wrapper label"
158
158
  assert_select "section.custom_wrapper div.another_wrapper input.string"
159
159
  output_buffer.replace ""
160
160
  end
161
161
 
162
- with_form_for @user, :name, :wrapper => custom_wrapper
162
+ with_form_for @user, :name, wrapper: custom_wrapper
163
163
  assert_select "section.custom_wrapper div.another_wrapper label"
164
164
  assert_select "section.custom_wrapper div.another_wrapper input.string"
165
165
  end
166
166
 
167
167
  test 'access wrappers with indifferent access' do
168
168
  swap_wrapper :another do
169
- with_form_for @user, :name, :wrapper => "another"
169
+ with_form_for @user, :name, wrapper: "another"
170
170
  assert_select "section.custom_wrapper div.another_wrapper label"
171
171
  assert_select "section.custom_wrapper div.another_wrapper input.string"
172
172
  end
@@ -175,8 +175,8 @@ class WrapperTest < ActionView::TestCase
175
175
  test 'do not duplicate label classes for different inputs' do
176
176
  swap_wrapper :default, self.custom_wrapper_with_label_html_option do
177
177
  with_concat_form_for(@user) do |f|
178
- concat f.input :name, :required => false
179
- concat f.input :email, :as => :email, :required => true
178
+ concat f.input :name, required: false
179
+ concat f.input :email, as: :email, required: true
180
180
  end
181
181
 
182
182
  assert_select "label.string.optional.extra-label-class[for='user_name']"
@@ -187,13 +187,13 @@ class WrapperTest < ActionView::TestCase
187
187
 
188
188
  test 'raise error when wrapper not found' do
189
189
  assert_raise SimpleForm::WrapperNotFound do
190
- with_form_for @user, :name, :wrapper => :not_found
190
+ with_form_for @user, :name, wrapper: :not_found
191
191
  end
192
192
  end
193
193
 
194
194
  test 'use wrapper for specified in config mapping' do
195
195
  swap_wrapper :another do
196
- swap SimpleForm, :wrapper_mappings => { :string => :another } do
196
+ swap SimpleForm, wrapper_mappings: { string: :another } do
197
197
  with_form_for @user, :name
198
198
  assert_select "section.custom_wrapper div.another_wrapper label"
199
199
  assert_select "section.custom_wrapper div.another_wrapper input.string"
@@ -9,26 +9,26 @@ class BooleanInputTest < ActionView::TestCase
9
9
  end
10
10
 
11
11
  test 'input does not generate the label with the checkbox when label option is false' do
12
- with_input_for @user, :active, :boolean, :label => false
12
+ with_input_for @user, :active, :boolean, label: false
13
13
  assert_select 'input[type=checkbox].boolean#user_active'
14
14
  assert_no_select 'label'
15
15
  end
16
16
 
17
17
  test 'input uses custom checked value' do
18
18
  @user.action = 'on'
19
- with_input_for @user, :action, :boolean, :checked_value => 'on', :unchecked_value => 'off'
19
+ with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
20
20
  assert_select 'input[type=checkbox][value=on][checked=checked]'
21
21
  end
22
22
 
23
23
  test 'input uses custom unchecked value' do
24
24
  @user.action = 'off'
25
- with_input_for @user, :action, :boolean, :checked_value => 'on', :unchecked_value => 'off'
25
+ with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
26
26
  assert_select 'input[type=checkbox][value=on]'
27
27
  assert_no_select 'input[checked=checked][value=on]'
28
28
  end
29
29
 
30
30
  test 'input generates hidden input with custom unchecked value' do
31
- with_input_for @user, :action, :boolean, :checked_value => 'on', :unchecked_value => 'off'
31
+ with_input_for @user, :action, :boolean, checked_value: 'on', unchecked_value: 'off'
32
32
  assert_select 'input[type=hidden][value=off]'
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ class BooleanInputTest < ActionView::TestCase
39
39
  end
40
40
 
41
41
  test 'input allows changing default boolean style config to nested, generating a default label and a manual hidden field for checkbox' do
42
- swap SimpleForm, :boolean_style => :nested do
42
+ swap SimpleForm, boolean_style: :nested do
43
43
  with_input_for @user, :active, :boolean
44
44
  assert_select 'label[for=user_active]', 'Active'
45
45
  assert_select 'label.boolean > input.boolean'
@@ -48,21 +48,21 @@ class BooleanInputTest < ActionView::TestCase
48
48
  end
49
49
 
50
50
  test 'input boolean with nested allows :inline_label' do
51
- swap SimpleForm, :boolean_style => :nested do
52
- with_input_for @user, :active, :boolean, :label => false, :inline_label => 'I am so inline.'
53
- assert_select 'label.checkbox', :text => 'I am so inline.'
51
+ swap SimpleForm, boolean_style: :nested do
52
+ with_input_for @user, :active, :boolean, label: false, inline_label: 'I am so inline.'
53
+ assert_select 'label.checkbox', text: 'I am so inline.'
54
54
  end
55
55
  end
56
56
 
57
57
  test 'input boolean with nested style creates an inline label using the default label text when inline_label option set to true' do
58
- swap SimpleForm, :boolean_style => :nested do
59
- with_input_for @user, :active, :boolean, :label => false, :inline_label => true
60
- assert_select 'label.checkbox', :text => 'Active'
58
+ swap SimpleForm, boolean_style: :nested do
59
+ with_input_for @user, :active, :boolean, label: false, inline_label: true
60
+ assert_select 'label.checkbox', text: 'Active'
61
61
  end
62
62
  end
63
63
 
64
64
  test 'input boolean with nested generates a manual hidden field for checkbox outside the label, to recreate Rails functionality with valid html5' do
65
- swap SimpleForm, :boolean_style => :nested do
65
+ swap SimpleForm, boolean_style: :nested do
66
66
  with_input_for @user, :active, :boolean
67
67
 
68
68
  assert_select "input[type=hidden][name='user[active]'] + label.boolean > input.boolean"
@@ -71,23 +71,23 @@ class BooleanInputTest < ActionView::TestCase
71
71
  end
72
72
 
73
73
  test 'input boolean with nested generates a disabled hidden field for checkbox outside the label, if the field is disabled' do
74
- swap SimpleForm, :boolean_style => :nested do
75
- with_input_for @user, :active, :boolean, :disabled => true
74
+ swap SimpleForm, boolean_style: :nested do
75
+ with_input_for @user, :active, :boolean, disabled: true
76
76
 
77
77
  assert_select "input[type=hidden][name='user[active]'][disabled] + label.boolean > input.boolean[disabled]"
78
78
  end
79
79
  end
80
80
 
81
81
  test 'input accepts changing boolean style to nested through given options' do
82
- with_input_for @user, :active, :boolean, :boolean_style => :nested
82
+ with_input_for @user, :active, :boolean, boolean_style: :nested
83
83
  assert_select 'label[for=user_active]', 'Active'
84
84
  assert_select 'label.boolean > input.boolean'
85
85
  assert_no_select 'input[type=checkbox] + label'
86
86
  end
87
87
 
88
88
  test 'input accepts changing boolean style to inline through given options, when default is nested' do
89
- swap SimpleForm, :boolean_style => :nested do
90
- with_input_for @user, :active, :boolean, :boolean_style => :inline
89
+ swap SimpleForm, boolean_style: :nested do
90
+ with_input_for @user, :active, :boolean, boolean_style: :inline
91
91
  assert_select 'label[for=user_active]', 'Active'
92
92
  assert_select 'input.boolean + label.boolean'
93
93
  assert_no_select 'label > input'
@@ -95,16 +95,16 @@ class BooleanInputTest < ActionView::TestCase
95
95
  end
96
96
 
97
97
  test 'input with nested style allows disabling label' do
98
- swap SimpleForm, :boolean_style => :nested do
99
- with_input_for @user, :active, :boolean, :label => false
98
+ swap SimpleForm, boolean_style: :nested do
99
+ with_input_for @user, :active, :boolean, label: false
100
100
  assert_select 'input.boolean'
101
101
  assert_no_select 'label.boolean'
102
102
  end
103
103
  end
104
104
 
105
105
  test 'input with nested style allows customizing input_html' do
106
- swap SimpleForm, :boolean_style => :nested do
107
- with_input_for @user, :active, :boolean, :input_html => { :name => 'active_user' }
106
+ swap SimpleForm, boolean_style: :nested do
107
+ with_input_for @user, :active, :boolean, input_html: { name: 'active_user' }
108
108
  assert_select "input[type=hidden][name=active_user] + label.boolean > input.boolean[name=active_user]"
109
109
  end
110
110
  end
@@ -120,7 +120,7 @@ class BooleanInputTest < ActionView::TestCase
120
120
 
121
121
  test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra "checkbox" label wrapper' do
122
122
  swap_wrapper do
123
- swap SimpleForm, :boolean_style => :nested do
123
+ swap SimpleForm, boolean_style: :nested do
124
124
  with_input_for @user, :active, :boolean
125
125
 
126
126
  assert_select 'label.boolean + input[type=hidden] + label.checkbox > input.boolean'
@@ -130,23 +130,11 @@ class BooleanInputTest < ActionView::TestCase
130
130
 
131
131
  test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
132
132
  swap_wrapper :default, self.custom_wrapper_without_top_level do
133
- swap SimpleForm, :boolean_style => :nested do
133
+ swap SimpleForm, boolean_style: :nested do
134
134
  with_input_for @user, :active, :boolean
135
135
 
136
136
  assert_select 'input[type=hidden] + label.boolean.checkbox > input.boolean'
137
137
  end
138
138
  end
139
139
  end
140
-
141
- test 'input boolean without additional classes should add "checkbox" class to label' do
142
- swap_wrapper :default, self.custom_wrapper_without_top_level do
143
- swap SimpleForm, :boolean_style => :nested, :generate_additional_classes_for => [:input] do
144
- with_input_for @user, :active, :boolean
145
-
146
- assert_select 'label'
147
- assert_select 'label.checkbox'
148
- assert_no_select 'label.boolean'
149
- end
150
- end
151
- end
152
140
  end