formtastic 4.0.0 → 5.0.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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +13 -13
  3. data/CHANGELOG.md +10 -1
  4. data/Gemfile.lock +99 -64
  5. data/README.md +7 -2
  6. data/formtastic.gemspec +5 -3
  7. data/gemfiles/{rails_5.2 → rails_7.0}/Gemfile +1 -1
  8. data/gemfiles/rails_7.1/Gemfile +5 -0
  9. data/gemfiles/rails_edge/Gemfile +1 -1
  10. data/lib/formtastic/action_class_finder.rb +1 -0
  11. data/lib/formtastic/actions/base.rb +1 -0
  12. data/lib/formtastic/actions/button_action.rb +1 -0
  13. data/lib/formtastic/actions/buttonish.rb +1 -0
  14. data/lib/formtastic/actions/input_action.rb +1 -0
  15. data/lib/formtastic/actions/link_action.rb +1 -0
  16. data/lib/formtastic/actions.rb +1 -0
  17. data/lib/formtastic/deprecation.rb +2 -1
  18. data/lib/formtastic/engine.rb +1 -0
  19. data/lib/formtastic/form_builder.rb +1 -0
  20. data/lib/formtastic/helpers/action_helper.rb +1 -0
  21. data/lib/formtastic/helpers/actions_helper.rb +1 -0
  22. data/lib/formtastic/helpers/enum.rb +1 -0
  23. data/lib/formtastic/helpers/errors_helper.rb +1 -0
  24. data/lib/formtastic/helpers/fieldset_wrapper.rb +1 -0
  25. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  26. data/lib/formtastic/helpers/form_helper.rb +1 -0
  27. data/lib/formtastic/helpers/input_helper.rb +2 -4
  28. data/lib/formtastic/helpers/inputs_helper.rb +2 -1
  29. data/lib/formtastic/helpers/reflection.rb +1 -0
  30. data/lib/formtastic/helpers.rb +1 -1
  31. data/lib/formtastic/html_attributes.rb +1 -0
  32. data/lib/formtastic/i18n.rb +1 -0
  33. data/lib/formtastic/input_class_finder.rb +1 -0
  34. data/lib/formtastic/inputs/base/associations.rb +1 -0
  35. data/lib/formtastic/inputs/base/choices.rb +2 -1
  36. data/lib/formtastic/inputs/base/collections.rb +4 -1
  37. data/lib/formtastic/inputs/base/database.rb +5 -7
  38. data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
  39. data/lib/formtastic/inputs/base/errors.rb +3 -2
  40. data/lib/formtastic/inputs/base/fileish.rb +1 -0
  41. data/lib/formtastic/inputs/base/hints.rb +1 -0
  42. data/lib/formtastic/inputs/base/html.rb +2 -1
  43. data/lib/formtastic/inputs/base/labelling.rb +3 -2
  44. data/lib/formtastic/inputs/base/naming.rb +1 -0
  45. data/lib/formtastic/inputs/base/numeric.rb +1 -0
  46. data/lib/formtastic/inputs/base/options.rb +1 -0
  47. data/lib/formtastic/inputs/base/placeholder.rb +1 -0
  48. data/lib/formtastic/inputs/base/stringish.rb +1 -0
  49. data/lib/formtastic/inputs/base/timeish.rb +4 -3
  50. data/lib/formtastic/inputs/base/validations.rb +2 -1
  51. data/lib/formtastic/inputs/base/wrapping.rb +1 -0
  52. data/lib/formtastic/inputs/base.rb +3 -2
  53. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  54. data/lib/formtastic/inputs/check_boxes_input.rb +2 -1
  55. data/lib/formtastic/inputs/color_input.rb +1 -0
  56. data/lib/formtastic/inputs/country_input.rb +1 -0
  57. data/lib/formtastic/inputs/datalist_input.rb +1 -0
  58. data/lib/formtastic/inputs/date_picker_input.rb +1 -0
  59. data/lib/formtastic/inputs/date_select_input.rb +1 -0
  60. data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
  61. data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
  62. data/lib/formtastic/inputs/email_input.rb +1 -0
  63. data/lib/formtastic/inputs/file_input.rb +1 -0
  64. data/lib/formtastic/inputs/hidden_input.rb +3 -2
  65. data/lib/formtastic/inputs/number_input.rb +1 -0
  66. data/lib/formtastic/inputs/password_input.rb +1 -0
  67. data/lib/formtastic/inputs/phone_input.rb +1 -0
  68. data/lib/formtastic/inputs/radio_input.rb +1 -0
  69. data/lib/formtastic/inputs/range_input.rb +1 -0
  70. data/lib/formtastic/inputs/search_input.rb +1 -0
  71. data/lib/formtastic/inputs/select_input.rb +1 -0
  72. data/lib/formtastic/inputs/string_input.rb +1 -0
  73. data/lib/formtastic/inputs/text_input.rb +1 -0
  74. data/lib/formtastic/inputs/time_picker_input.rb +1 -0
  75. data/lib/formtastic/inputs/time_select_input.rb +1 -0
  76. data/lib/formtastic/inputs/time_zone_input.rb +1 -0
  77. data/lib/formtastic/inputs/url_input.rb +1 -0
  78. data/lib/formtastic/inputs.rb +1 -0
  79. data/lib/formtastic/localized_string.rb +1 -0
  80. data/lib/formtastic/localizer.rb +1 -0
  81. data/lib/formtastic/namespaced_class_finder.rb +7 -8
  82. data/lib/formtastic/version.rb +2 -1
  83. data/lib/formtastic.rb +1 -0
  84. data/lib/generators/formtastic/form/form_generator.rb +1 -0
  85. data/lib/generators/formtastic/input/input_generator.rb +1 -0
  86. data/lib/generators/formtastic/install/install_generator.rb +1 -0
  87. data/lib/generators/templates/formtastic.rb +1 -0
  88. data/script/integration-template.rb +2 -3
  89. data/spec/action_class_finder_spec.rb +1 -0
  90. data/spec/actions/button_action_spec.rb +17 -16
  91. data/spec/actions/generic_action_spec.rb +130 -129
  92. data/spec/actions/input_action_spec.rb +16 -15
  93. data/spec/actions/link_action_spec.rb +25 -24
  94. data/spec/builder/custom_builder_spec.rb +5 -4
  95. data/spec/builder/error_proc_spec.rb +2 -1
  96. data/spec/builder/semantic_fields_for_spec.rb +26 -25
  97. data/spec/fast_spec_helper.rb +1 -0
  98. data/spec/generators/formtastic/form/form_generator_spec.rb +8 -7
  99. data/spec/generators/formtastic/input/input_generator_spec.rb +1 -0
  100. data/spec/generators/formtastic/install/install_generator_spec.rb +1 -0
  101. data/spec/helpers/action_helper_spec.rb +15 -14
  102. data/spec/helpers/actions_helper_spec.rb +42 -41
  103. data/spec/helpers/form_helper_spec.rb +26 -19
  104. data/spec/helpers/input_helper_spec.rb +70 -69
  105. data/spec/helpers/inputs_helper_spec.rb +179 -179
  106. data/spec/helpers/reflection_helper_spec.rb +4 -3
  107. data/spec/helpers/semantic_errors_helper_spec.rb +4 -3
  108. data/spec/i18n_spec.rb +13 -12
  109. data/spec/input_class_finder_spec.rb +1 -0
  110. data/spec/inputs/base/collections_spec.rb +2 -0
  111. data/spec/inputs/base/validations_spec.rb +1 -0
  112. data/spec/inputs/boolean_input_spec.rb +66 -65
  113. data/spec/inputs/check_boxes_input_spec.rb +89 -88
  114. data/spec/inputs/color_input_spec.rb +7 -6
  115. data/spec/inputs/country_input_spec.rb +10 -9
  116. data/spec/inputs/custom_input_spec.rb +1 -0
  117. data/spec/inputs/datalist_input_spec.rb +2 -1
  118. data/spec/inputs/date_picker_input_spec.rb +109 -108
  119. data/spec/inputs/date_select_input_spec.rb +63 -62
  120. data/spec/inputs/datetime_picker_input_spec.rb +118 -117
  121. data/spec/inputs/datetime_select_input_spec.rb +72 -71
  122. data/spec/inputs/email_input_spec.rb +16 -15
  123. data/spec/inputs/file_input_spec.rb +17 -16
  124. data/spec/inputs/hidden_input_spec.rb +29 -28
  125. data/spec/inputs/include_blank_spec.rb +7 -6
  126. data/spec/inputs/label_spec.rb +25 -24
  127. data/spec/inputs/number_input_spec.rb +159 -158
  128. data/spec/inputs/password_input_spec.rb +16 -15
  129. data/spec/inputs/phone_input_spec.rb +16 -15
  130. data/spec/inputs/placeholder_spec.rb +17 -16
  131. data/spec/inputs/radio_input_spec.rb +58 -57
  132. data/spec/inputs/range_input_spec.rb +108 -107
  133. data/spec/inputs/readonly_spec.rb +5 -4
  134. data/spec/inputs/search_input_spec.rb +15 -14
  135. data/spec/inputs/select_input_spec.rb +144 -93
  136. data/spec/inputs/string_input_spec.rb +36 -35
  137. data/spec/inputs/text_input_spec.rb +32 -31
  138. data/spec/inputs/time_picker_input_spec.rb +110 -109
  139. data/spec/inputs/time_select_input_spec.rb +71 -70
  140. data/spec/inputs/time_zone_input_spec.rb +21 -20
  141. data/spec/inputs/url_input_spec.rb +16 -15
  142. data/spec/inputs/with_options_spec.rb +8 -7
  143. data/spec/localizer_spec.rb +1 -0
  144. data/spec/namespaced_class_finder_spec.rb +17 -5
  145. data/spec/schema.rb +1 -0
  146. data/spec/spec_helper.rb +8 -8
  147. data/spec/support/custom_macros.rb +64 -63
  148. data/spec/support/deprecation.rb +2 -1
  149. data/spec/support/shared_examples.rb +2 -1
  150. data/spec/support/specialized_class_finder_shared_example.rb +1 -0
  151. data/spec/support/test_environment.rb +1 -0
  152. metadata +29 -14
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'Formtastic::Helpers::Reflection' do
@@ -6,7 +7,7 @@ RSpec.describe 'Formtastic::Helpers::Reflection' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  end
12
13
 
@@ -27,6 +28,6 @@ RSpec.describe 'Formtastic::Helpers::Reflection' do
27
28
  expect(@reflection_tester.reflection_for(:sub_posts)).not_to be_nil
28
29
  end
29
30
  end
30
-
31
-
31
+
32
+
32
33
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
@@ -6,7 +7,7 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  @title_errors = ['must not be blank', 'must be awesome']
12
13
  @base_errors = ['base error message', 'nasty error']
@@ -95,7 +96,7 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
95
96
  end
96
97
  end
97
98
  end
98
-
99
+
99
100
  describe 'when :base is passed in as an argument' do
100
101
  before do
101
102
  allow(@errors).to receive(:[]).with(errors_matcher(:base)).and_return(@base_error)
@@ -108,5 +109,5 @@ RSpec.describe 'Formtastic::FormBuilder#semantic_errors' do
108
109
  end
109
110
  end
110
111
  end
111
-
112
+
112
113
  end
data/spec/i18n_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'Formtastic::I18n' do
@@ -82,7 +83,7 @@ RSpec.describe 'Formtastic::I18n' do
82
83
  include FormtasticSpecHelper
83
84
 
84
85
  before do
85
- @output_buffer = ''
86
+ @output_buffer = ActionView::OutputBuffer.new ''
86
87
  mock_everything
87
88
 
88
89
  ::I18n.backend.store_translations :en, {:formtastic => {
@@ -117,7 +118,7 @@ RSpec.describe 'Formtastic::I18n' do
117
118
  concat(semantic_form_for(@new_post) do |builder|
118
119
  concat(builder.input(:title))
119
120
  end)
120
- expect(output_buffer).to have_tag("form label", :text => /Hello post!/)
121
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello post!/)
121
122
  end
122
123
  end
123
124
 
@@ -126,7 +127,7 @@ RSpec.describe 'Formtastic::I18n' do
126
127
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
127
128
  concat(builder.input(:title))
128
129
  end)
129
- expect(output_buffer).to have_tag("form label", :text => /Hello project!/)
130
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
130
131
  end
131
132
  end
132
133
 
@@ -135,7 +136,7 @@ RSpec.describe 'Formtastic::I18n' do
135
136
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
136
137
  concat(builder.input(:author))
137
138
  end)
138
- expect(output_buffer).to have_tag("form label", :text => /Author/)
139
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Author/)
139
140
  end
140
141
  end
141
142
 
@@ -146,7 +147,7 @@ RSpec.describe 'Formtastic::I18n' do
146
147
  concat(f.input(:name))
147
148
  end)
148
149
  end)
149
- expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
150
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
150
151
  end
151
152
  end
152
153
 
@@ -157,7 +158,7 @@ RSpec.describe 'Formtastic::I18n' do
157
158
  concat(f.input(:name))
158
159
  end
159
160
  end)
160
- expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
161
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
161
162
  end
162
163
  end
163
164
 
@@ -168,10 +169,10 @@ RSpec.describe 'Formtastic::I18n' do
168
169
  concat(f.input(:title))
169
170
  end
170
171
  end)
171
- expect(output_buffer).to have_tag("form label", :text => /Hello project!/)
172
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello project!/)
172
173
  end
173
174
  end
174
-
175
+
175
176
  it 'should be able to translate nested forms with top level translations' do
176
177
  with_config :i18n_lookups_by_default, true do
177
178
  concat(semantic_form_for(:post) do |builder|
@@ -179,7 +180,7 @@ RSpec.describe 'Formtastic::I18n' do
179
180
  concat(f.input(:name))
180
181
  end
181
182
  end)
182
- expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
183
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello author name!/)
183
184
  end
184
185
  end
185
186
 
@@ -188,10 +189,10 @@ RSpec.describe 'Formtastic::I18n' do
188
189
  concat(semantic_form_for(@new_post) do |builder|
189
190
  concat(builder.input(:body))
190
191
  end)
191
- expect(output_buffer).to have_tag("form label", :text => /Elaborate/)
192
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Elaborate/)
192
193
  end
193
194
  end
194
-
195
+
195
196
  it 'should be able to translate nested helper label as Rails does' do
196
197
  with_config :i18n_lookups_by_default, true do
197
198
  concat(semantic_form_for(@new_post) do |builder|
@@ -199,7 +200,7 @@ RSpec.describe 'Formtastic::I18n' do
199
200
  concat(f.input(:login))
200
201
  end)
201
202
  end)
202
- expect(output_buffer).to have_tag("form label", :text => /Hello login/)
203
+ expect(output_buffer.to_str).to have_tag("form label", :text => /Hello login/)
203
204
  end
204
205
  end
205
206
 
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
  require 'formtastic/input_class_finder'
4
5
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'fast_spec_helper'
2
3
  require 'inputs/base/collections'
3
4
 
@@ -34,6 +35,7 @@ RSpec.describe MyInput do
34
35
  statuses = ActiveSupport::HashWithIndifferentAccess.new("active"=>0, "inactive"=>1)
35
36
  allow(model_class).to receive(:statuses) { statuses }
36
37
  allow(model).to receive(:defined_enums) { {"status" => statuses } }
38
+ allow(model).to receive(:model_name).and_return(double(i18n_key: model_name))
37
39
  end
38
40
 
39
41
  context 'no translations available' do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'fast_spec_helper'
2
3
  require 'active_model'
3
4
  require 'inputs/base/validations'
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe 'boolean input' do
@@ -6,7 +7,7 @@ RSpec.describe 'boolean input' do
6
7
  include FormtasticSpecHelper
7
8
 
8
9
  before do
9
- @output_buffer = ''
10
+ @output_buffer = ActionView::OutputBuffer.new ''
10
11
  mock_everything
11
12
  end
12
13
 
@@ -16,38 +17,38 @@ RSpec.describe 'boolean input' do
16
17
  concat(builder.input(:allow_comments, :as => :boolean))
17
18
  end)
18
19
  end
19
-
20
+
20
21
  it_should_have_input_wrapper_with_class("boolean")
21
22
  it_should_have_input_wrapper_with_class(:input)
22
23
  it_should_have_input_wrapper_with_id("post_allow_comments_input")
23
24
  it_should_apply_error_logic_for_input_type(:boolean)
24
-
25
+
25
26
  it 'should generate a label containing the input' do
26
- expect(output_buffer).not_to have_tag('label.label')
27
- expect(output_buffer).to have_tag('form li label', :count => 1)
28
- expect(output_buffer).to have_tag('form li label[@for="post_allow_comments"]')
29
- expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
30
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"]', :count => 1)
31
- expect(output_buffer).to have_tag('form li input[@type="hidden"]', :count => 1)
32
- expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
27
+ expect(output_buffer.to_str).not_to have_tag('label.label')
28
+ expect(output_buffer.to_str).to have_tag('form li label', :count => 1)
29
+ expect(output_buffer.to_str).to have_tag('form li label[@for="post_allow_comments"]')
30
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
31
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]', :count => 1)
32
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"]', :count => 1)
33
+ expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
33
34
  end
34
-
35
+
35
36
  it 'should not add a "name" attribute to the label' do
36
- expect(output_buffer).not_to have_tag('form li label[@name]')
37
+ expect(output_buffer.to_str).not_to have_tag('form li label[@name]')
37
38
  end
38
-
39
+
39
40
  it 'should generate a checkbox input' do
40
- expect(output_buffer).to have_tag('form li label input')
41
- expect(output_buffer).to have_tag('form li label input#post_allow_comments')
42
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
43
- expect(output_buffer).to have_tag('form li label input[@name="post[allow_comments]"]')
44
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"]')
41
+ expect(output_buffer.to_str).to have_tag('form li label input')
42
+ expect(output_buffer.to_str).to have_tag('form li label input#post_allow_comments')
43
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
44
+ expect(output_buffer.to_str).to have_tag('form li label input[@name="post[allow_comments]"]')
45
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"]')
45
46
  end
46
-
47
+
47
48
  it 'should generate a checked input if object.method returns true' do
48
- expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
49
- expect(output_buffer).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
50
- expect(output_buffer).to have_tag('form li input#post_allow_comments', :count => 1)
49
+ expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
50
+ expect(output_buffer.to_str).to have_tag('form li input[@name="post[allow_comments]"]', :count => 2)
51
+ expect(output_buffer.to_str).to have_tag('form li input#post_allow_comments', :count => 1)
51
52
  end
52
53
  end
53
54
 
@@ -55,7 +56,7 @@ RSpec.describe 'boolean input' do
55
56
  concat(semantic_form_for(@new_post) do |builder|
56
57
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => {:checked => 'checked'}))
57
58
  end)
58
- expect(output_buffer).to have_tag('form li label input[@checked="checked"]')
59
+ expect(output_buffer.to_str).to have_tag('form li label input[@checked="checked"]')
59
60
  end
60
61
 
61
62
  it 'should name the hidden input with the :name html_option' do
@@ -63,8 +64,8 @@ RSpec.describe 'boolean input' do
63
64
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
64
65
  end)
65
66
 
66
- expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
67
- expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
67
+ expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
68
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
68
69
  end
69
70
 
70
71
  it 'should name the hidden input with the :name html_option' do
@@ -72,33 +73,33 @@ RSpec.describe 'boolean input' do
72
73
  concat(builder.input(:answer_comments, :as => :boolean, :input_html => { :name => "foo" }))
73
74
  end)
74
75
 
75
- expect(output_buffer).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
76
- expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
76
+ expect(output_buffer.to_str).to have_tag('form li input[@type="checkbox"][@name="foo"]', :count => 1)
77
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="foo"]', :count => 1)
77
78
  end
78
79
 
79
80
  it "should generate a disabled input and hidden input if :input_html is passed :disabled => 'disabled' " do
80
81
  concat(semantic_form_for(@new_post) do |builder|
81
82
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:disabled => 'disabled'}))
82
83
  end)
83
- expect(output_buffer).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
84
- expect(output_buffer).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
84
+ expect(output_buffer.to_str).to have_tag('form li label input[@disabled="disabled"]', :count => 1)
85
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@disabled="disabled"]', :count => 1)
85
86
  end
86
87
 
87
88
  it 'should generate an input[id] with matching label[for] when id passed in :input_html' do
88
89
  concat(semantic_form_for(@new_post) do |builder|
89
90
  concat(builder.input(:allow_comments, :as => :boolean, :input_html => {:id => 'custom_id'}))
90
91
  end)
91
- expect(output_buffer).to have_tag('form li label input[@id="custom_id"]')
92
- expect(output_buffer).to have_tag('form li label[@for="custom_id"]')
92
+ expect(output_buffer.to_str).to have_tag('form li label input[@id="custom_id"]')
93
+ expect(output_buffer.to_str).to have_tag('form li label[@for="custom_id"]')
93
94
  end
94
95
 
95
96
  it 'should allow checked and unchecked values to be sent' do
96
97
  concat(semantic_form_for(@new_post) do |builder|
97
98
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'checked', :unchecked_value => 'unchecked'))
98
99
  end)
99
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
100
- expect(output_buffer).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
101
- expect(output_buffer).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
100
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="checked"]:not([@unchecked_value][@checked_value])')
101
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@value="unchecked"]')
102
+ expect(output_buffer.to_str).not_to have_tag('form li label input[@type="hidden"]') # invalid HTML5
102
103
  end
103
104
 
104
105
  it 'should generate a checked input if object.method returns checked value' do
@@ -108,7 +109,7 @@ RSpec.describe 'boolean input' do
108
109
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
109
110
  end)
110
111
 
111
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
112
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
112
113
  end
113
114
 
114
115
  it 'should not generate a checked input if object.method returns unchecked value' do
@@ -118,7 +119,7 @@ RSpec.describe 'boolean input' do
118
119
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
119
120
  end)
120
121
 
121
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
122
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
122
123
  end
123
124
 
124
125
  it 'should generate a checked input if object.method returns checked value' do
@@ -128,7 +129,7 @@ RSpec.describe 'boolean input' do
128
129
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
129
130
  end)
130
131
 
131
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
132
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"][@checked="checked"]')
132
133
  end
133
134
 
134
135
  it 'should generate a checked input for boolean database values compared to string checked values' do
@@ -138,7 +139,7 @@ RSpec.describe 'boolean input' do
138
139
  concat(builder.input(:foo, :as => :boolean))
139
140
  end)
140
141
 
141
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
142
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="1"][@checked="checked"]')
142
143
  end
143
144
 
144
145
  it 'should generate a checked input if object.method returns checked value when inverted' do
@@ -148,7 +149,7 @@ RSpec.describe 'boolean input' do
148
149
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 0, :unchecked_value => 1))
149
150
  end)
150
151
 
151
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
152
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="0"][@checked="checked"]')
152
153
  end
153
154
 
154
155
  it 'should not generate a checked input if object.method returns unchecked value' do
@@ -158,7 +159,7 @@ RSpec.describe 'boolean input' do
158
159
  concat(builder.input(:allow_comments, :as => :boolean, :checked_value => 'yes', :unchecked_value => 'no'))
159
160
  end)
160
161
 
161
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
162
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"][@value="yes"]:not([@checked])')
162
163
  end
163
164
 
164
165
  it 'should generate a label and a checkbox even if no object is given' do
@@ -166,49 +167,49 @@ RSpec.describe 'boolean input' do
166
167
  concat(builder.input(:allow_comments, :as => :boolean))
167
168
  end)
168
169
 
169
- expect(output_buffer).to have_tag('form li label[@for="project_allow_comments"]')
170
- expect(output_buffer).to have_tag('form li label', :text => /Allow comments/)
171
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
170
+ expect(output_buffer.to_str).to have_tag('form li label[@for="project_allow_comments"]')
171
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Allow comments/)
172
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
172
173
 
173
- expect(output_buffer).to have_tag('form li label input#project_allow_comments')
174
- expect(output_buffer).to have_tag('form li label input[@type="checkbox"]')
175
- expect(output_buffer).to have_tag('form li label input[@name="project[allow_comments]"]')
174
+ expect(output_buffer.to_str).to have_tag('form li label input#project_allow_comments')
175
+ expect(output_buffer.to_str).to have_tag('form li label input[@type="checkbox"]')
176
+ expect(output_buffer.to_str).to have_tag('form li label input[@name="project[allow_comments]"]')
176
177
  end
177
-
178
+
178
179
  it 'should not pass input_html options down to the label html' do
179
180
  concat(semantic_form_for(@new_post) do |builder|
180
181
  builder.input(:title, :as => :boolean, :input_html => { :tabindex => 2, :x => "X" })
181
182
  end)
182
- expect(output_buffer).not_to have_tag('label[tabindex]')
183
- expect(output_buffer).not_to have_tag('label[x]')
183
+ expect(output_buffer.to_str).not_to have_tag('label[tabindex]')
184
+ expect(output_buffer.to_str).not_to have_tag('label[x]')
184
185
  end
185
186
 
186
187
  context "when required" do
187
-
188
+
188
189
  it "should add the required attribute to the input's html options" do
189
190
  with_config :use_required_attribute, true do
190
191
  concat(semantic_form_for(@new_post) do |builder|
191
192
  concat(builder.input(:title, :as => :boolean, :required => true))
192
193
  end)
193
- expect(output_buffer).to have_tag("input[@required]")
194
+ expect(output_buffer.to_str).to have_tag("input[@required]")
194
195
  end
195
196
  end
196
-
197
+
197
198
  it "should not add the required attribute to the boolean fields input's html options" do
198
199
  with_config :use_required_attribute, true do
199
200
  concat(semantic_form_for(@new_post) do |builder|
200
201
  concat(builder.input(:title, :as => :boolean))
201
202
  end)
202
- expect(output_buffer).not_to have_tag("input[@required]")
203
+ expect(output_buffer.to_str).not_to have_tag("input[@required]")
203
204
  end
204
205
  end
205
-
206
+
206
207
  end
207
208
 
208
209
  describe "when namespace is provided" do
209
210
 
210
211
  before do
211
- @output_buffer = ''
212
+ @output_buffer = ActionView::OutputBuffer.new ''
212
213
  mock_everything
213
214
 
214
215
  concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
@@ -220,11 +221,11 @@ RSpec.describe 'boolean input' do
220
221
  it_should_have_an_inline_label_for("context2_post_allow_comments")
221
222
 
222
223
  end
223
-
224
+
224
225
  describe "when index is provided" do
225
226
 
226
227
  before do
227
- @output_buffer = ''
228
+ @output_buffer = ActionView::OutputBuffer.new ''
228
229
  mock_everything
229
230
 
230
231
  concat(semantic_form_for(@new_post) do |builder|
@@ -233,22 +234,22 @@ RSpec.describe 'boolean input' do
233
234
  end)
234
235
  end)
235
236
  end
236
-
237
+
237
238
  it 'should index the id of the wrapper' do
238
- expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
239
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
239
240
  end
240
-
241
+
241
242
  it 'should index the id of the input tag' do
242
- expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
243
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
243
244
  end
244
-
245
+
245
246
  it 'should index the name of the hidden input' do
246
- expect(output_buffer).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
247
+ expect(output_buffer.to_str).to have_tag("input[@type='hidden'][@name='post[author_attributes][3][name]']")
247
248
  end
248
249
 
249
250
  it 'should index the name of the checkbox input' do
250
- expect(output_buffer).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
251
+ expect(output_buffer.to_str).to have_tag("input[@type='checkbox'][@name='post[author_attributes][3][name]']")
251
252
  end
252
-
253
+
253
254
  end
254
255
  end