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 'range input' do
@@ -6,7 +7,7 @@ RSpec.describe 'range 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
 
@@ -42,11 +43,11 @@ RSpec.describe 'range input' do
42
43
  it_should_have_label_and_input_with_id("context2_author_age")
43
44
 
44
45
  end
45
-
46
+
46
47
  describe "when index is provided" do
47
48
 
48
49
  before do
49
- @output_buffer = ''
50
+ @output_buffer = ActionView::OutputBuffer.new ''
50
51
  mock_everything
51
52
 
52
53
  concat(semantic_form_for(@new_post) do |builder|
@@ -55,21 +56,21 @@ RSpec.describe 'range input' do
55
56
  end)
56
57
  end)
57
58
  end
58
-
59
+
59
60
  it 'should index the id of the wrapper' do
60
- expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
61
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
61
62
  end
62
-
63
+
63
64
  it 'should index the id of the select tag' do
64
- expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
65
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
65
66
  end
66
-
67
+
67
68
  it 'should index the name of the select tag' do
68
- expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
69
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
69
70
  end
70
-
71
+
71
72
  end
72
-
73
+
73
74
 
74
75
  describe "when validations require a minimum value (:greater_than)" do
75
76
  before do
@@ -77,53 +78,53 @@ RSpec.describe 'range input' do
77
78
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than=>2})
78
79
  ])
79
80
  end
80
-
81
+
81
82
  it "should allow :input_html to override :min" do
82
83
  concat(semantic_form_for(@new_post) do |builder|
83
84
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
84
85
  end)
85
- expect(output_buffer).to have_tag('input[@min="5"]')
86
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
86
87
  end
87
-
88
+
88
89
  it "should allow :input_html to override :min through :in" do
89
90
  concat(semantic_form_for(@new_post) do |builder|
90
91
  builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
91
92
  end)
92
- expect(output_buffer).to have_tag('input[@min="5"]')
93
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
93
94
  end
94
-
95
+
95
96
  it "should allow options to override :min" do
96
97
  concat(semantic_form_for(@new_post) do |builder|
97
98
  builder.input(:title, :as => :range, :min => 5)
98
99
  end)
99
- expect(output_buffer).to have_tag('input[@min="5"]')
100
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
100
101
  end
101
-
102
+
102
103
  it "should allow options to override :min through :in" do
103
104
  concat(semantic_form_for(@new_post) do |builder|
104
105
  builder.input(:title, :as => :range, :in => 5..102)
105
106
  end)
106
- expect(output_buffer).to have_tag('input[@min="5"]')
107
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
107
108
  end
108
-
109
+
109
110
  describe "and the column is an integer" do
110
111
  before do
111
112
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
112
113
  end
113
-
114
+
114
115
  it "should add a min attribute to the input one greater than the validation" do
115
116
  concat(semantic_form_for(@new_post) do |builder|
116
117
  builder.input(:title, :as => :range)
117
118
  end)
118
- expect(output_buffer).to have_tag('input[@min="3"]')
119
+ expect(output_buffer.to_str).to have_tag('input[@min="3"]')
119
120
  end
120
121
  end
121
-
122
+
122
123
  describe "and the column is a float" do
123
124
  before do
124
125
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
125
126
  end
126
-
127
+
127
128
  it "should raise an error" do
128
129
  expect {
129
130
  concat(semantic_form_for(@new_post) do |builder|
@@ -132,12 +133,12 @@ RSpec.describe 'range input' do
132
133
  }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
133
134
  end
134
135
  end
135
-
136
+
136
137
  describe "and the column is a big decimal" do
137
138
  before do
138
139
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
139
140
  end
140
-
141
+
141
142
  it "should raise an error" do
142
143
  expect {
143
144
  concat(semantic_form_for(@new_post) do |builder|
@@ -146,44 +147,44 @@ RSpec.describe 'range input' do
146
147
  }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMinimumAttributeError)
147
148
  end
148
149
  end
149
-
150
+
150
151
  end
151
-
152
+
152
153
  describe "when validations require a minimum value (:greater_than_or_equal_to)" do
153
154
  before do
154
155
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
155
156
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than_or_equal_to=>2})
156
157
  ])
157
158
  end
158
-
159
+
159
160
  it "should allow :input_html to override :min" do
160
161
  concat(semantic_form_for(@new_post) do |builder|
161
162
  builder.input(:title, :as => :range, :input_html => { :min => 5 })
162
163
  end)
163
- expect(output_buffer).to have_tag('input[@min="5"]')
164
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
164
165
  end
165
-
166
+
166
167
  it "should allow options to override :min" do
167
168
  concat(semantic_form_for(@new_post) do |builder|
168
169
  builder.input(:title, :as => :range, :min => 5)
169
170
  end)
170
- expect(output_buffer).to have_tag('input[@min="5"]')
171
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
171
172
  end
172
173
 
173
174
  it "should allow :input_html to override :min with :in" do
174
175
  concat(semantic_form_for(@new_post) do |builder|
175
176
  builder.input(:title, :as => :range, :input_html => { :in => 5..102 })
176
177
  end)
177
- expect(output_buffer).to have_tag('input[@min="5"]')
178
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
178
179
  end
179
-
180
+
180
181
  it "should allow options to override :min with :in" do
181
182
  concat(semantic_form_for(@new_post) do |builder|
182
183
  builder.input(:title, :as => :range, :in => 5..102)
183
184
  end)
184
- expect(output_buffer).to have_tag('input[@min="5"]')
185
+ expect(output_buffer.to_str).to have_tag('input[@min="5"]')
185
186
  end
186
-
187
+
187
188
 
188
189
  [:integer, :decimal, :float].each do |column_type|
189
190
  describe "and the column is a #{column_type}" do
@@ -195,7 +196,7 @@ RSpec.describe 'range input' do
195
196
  concat(semantic_form_for(@new_post) do |builder|
196
197
  builder.input(:title, :as => :range)
197
198
  end)
198
- expect(output_buffer).to have_tag('input[@min="2"]')
199
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
199
200
  end
200
201
  end
201
202
  end
@@ -204,25 +205,25 @@ RSpec.describe 'range input' do
204
205
  before do
205
206
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
206
207
  end
207
-
208
+
208
209
  it "should add a max attribute to the input equal to the validation" do
209
210
  concat(semantic_form_for(@new_post) do |builder|
210
211
  builder.input(:title, :as => :range)
211
212
  end)
212
- expect(output_buffer).to have_tag('input[@min="2"]')
213
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
213
214
  end
214
215
  end
215
216
  end
216
217
 
217
218
  describe "when validations do not require a minimum value" do
218
-
219
+
219
220
  it "should default to 1" do
220
221
  concat(semantic_form_for(@new_post) do |builder|
221
222
  builder.input(:title, :as => :range)
222
223
  end)
223
- expect(output_buffer).to have_tag('input[@min="1"]')
224
+ expect(output_buffer.to_str).to have_tag('input[@min="1"]')
224
225
  end
225
-
226
+
226
227
  end
227
228
 
228
229
  describe "when validations require a maximum value (:less_than)" do
@@ -231,53 +232,53 @@ RSpec.describe 'range input' do
231
232
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than=>20})
232
233
  ])
233
234
  end
234
-
235
+
235
236
  it "should allow :input_html to override :max" do
236
237
  concat(semantic_form_for(@new_post) do |builder|
237
238
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
238
239
  end)
239
- expect(output_buffer).to have_tag('input[@max="102"]')
240
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
240
241
  end
241
-
242
+
242
243
  it "should allow option to override :max" do
243
244
  concat(semantic_form_for(@new_post) do |builder|
244
245
  builder.input(:title, :as => :range, :max => 102)
245
246
  end)
246
- expect(output_buffer).to have_tag('input[@max="102"]')
247
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
247
248
  end
248
-
249
+
249
250
  it "should allow :input_html to override :max with :in" do
250
251
  concat(semantic_form_for(@new_post) do |builder|
251
252
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
252
253
  end)
253
- expect(output_buffer).to have_tag('input[@max="102"]')
254
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
254
255
  end
255
256
 
256
257
  it "should allow option to override :max with :in" do
257
258
  concat(semantic_form_for(@new_post) do |builder|
258
259
  builder.input(:title, :as => :range, :in => 1..102)
259
260
  end)
260
- expect(output_buffer).to have_tag('input[@max="102"]')
261
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
261
262
  end
262
-
263
+
263
264
  describe "and the column is an integer" do
264
265
  before do
265
266
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :integer))
266
267
  end
267
-
268
+
268
269
  it "should add a max attribute to the input one greater than the validation" do
269
270
  concat(semantic_form_for(@new_post) do |builder|
270
271
  builder.input(:title, :as => :range)
271
272
  end)
272
- expect(output_buffer).to have_tag('input[@max="19"]')
273
+ expect(output_buffer.to_str).to have_tag('input[@max="19"]')
273
274
  end
274
275
  end
275
-
276
+
276
277
  describe "and the column is a float" do
277
278
  before do
278
279
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :float))
279
280
  end
280
-
281
+
281
282
  it "should raise an error" do
282
283
  expect {
283
284
  concat(semantic_form_for(@new_post) do |builder|
@@ -286,12 +287,12 @@ RSpec.describe 'range input' do
286
287
  }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
287
288
  end
288
289
  end
289
-
290
+
290
291
  describe "and the column is a big decimal" do
291
292
  before do
292
293
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :decimal))
293
294
  end
294
-
295
+
295
296
  it "should raise an error" do
296
297
  expect {
297
298
  concat(semantic_form_for(@new_post) do |builder|
@@ -300,42 +301,42 @@ RSpec.describe 'range input' do
300
301
  }.to raise_error(Formtastic::Inputs::Base::Validations::IndeterminableMaximumAttributeError)
301
302
  end
302
303
  end
303
-
304
+
304
305
  end
305
-
306
+
306
307
  describe "when validations require a maximum value (:less_than_or_equal_to)" do
307
308
  before do
308
309
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
309
310
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than_or_equal_to=>20})
310
311
  ])
311
312
  end
312
-
313
+
313
314
  it "should allow :input_html to override :max" do
314
315
  concat(semantic_form_for(@new_post) do |builder|
315
316
  builder.input(:title, :as => :range, :input_html => { :max => 102 })
316
317
  end)
317
- expect(output_buffer).to have_tag('input[@max="102"]')
318
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
318
319
  end
319
-
320
+
320
321
  it "should allow options to override :max" do
321
322
  concat(semantic_form_for(@new_post) do |builder|
322
323
  builder.input(:title, :as => :range, :max => 102)
323
324
  end)
324
- expect(output_buffer).to have_tag('input[@max="102"]')
325
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
325
326
  end
326
-
327
+
327
328
  it "should allow :input_html to override :max with :in" do
328
329
  concat(semantic_form_for(@new_post) do |builder|
329
330
  builder.input(:title, :as => :range, :input_html => { :in => 1..102 })
330
331
  end)
331
- expect(output_buffer).to have_tag('input[@max="102"]')
332
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
332
333
  end
333
-
334
+
334
335
  it "should allow options to override :max with :in" do
335
336
  concat(semantic_form_for(@new_post) do |builder|
336
337
  builder.input(:title, :as => :range, :in => 1..102)
337
338
  end)
338
- expect(output_buffer).to have_tag('input[@max="102"]')
339
+ expect(output_buffer.to_str).to have_tag('input[@max="102"]')
339
340
  end
340
341
 
341
342
  [:integer, :decimal, :float].each do |column_type|
@@ -348,7 +349,7 @@ RSpec.describe 'range input' do
348
349
  concat(semantic_form_for(@new_post) do |builder|
349
350
  builder.input(:title, :as => :range)
350
351
  end)
351
- expect(output_buffer).to have_tag('input[@max="20"]')
352
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
352
353
  end
353
354
  end
354
355
  end
@@ -357,149 +358,149 @@ RSpec.describe 'range input' do
357
358
  before do
358
359
  allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(nil)
359
360
  end
360
-
361
+
361
362
  it "should add a max attribute to the input equal to the validation" do
362
363
  concat(semantic_form_for(@new_post) do |builder|
363
364
  builder.input(:title, :as => :range)
364
365
  end)
365
- expect(output_buffer).to have_tag('input[@max="20"]')
366
+ expect(output_buffer.to_str).to have_tag('input[@max="20"]')
366
367
  end
367
368
  end
368
369
  end
369
-
370
+
370
371
  describe "when validations do not require a maximum value" do
371
-
372
+
372
373
  it "should default to 1" do
373
374
  concat(semantic_form_for(@new_post) do |builder|
374
375
  builder.input(:title, :as => :range)
375
376
  end)
376
- expect(output_buffer).to have_tag('input[@max="100"]')
377
+ expect(output_buffer.to_str).to have_tag('input[@max="100"]')
377
378
  end
378
-
379
+
379
380
  end
380
-
381
+
381
382
  describe "when validations require conflicting minimum values (:greater_than, :greater_than_or_equal_to)" do
382
383
  before do
383
384
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
384
385
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :greater_than => 20, :greater_than_or_equal_to=>2})
385
386
  ])
386
387
  end
387
-
388
+
388
389
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
389
390
  concat(semantic_form_for(@new_post) do |builder|
390
391
  builder.input(:title, :as => :range)
391
392
  end)
392
- expect(output_buffer).to have_tag('input[@min="2"]')
393
+ expect(output_buffer.to_str).to have_tag('input[@min="2"]')
393
394
  end
394
395
  end
395
-
396
+
396
397
  describe "when validations require conflicting maximum values (:less_than, :less_than_or_equal_to)" do
397
398
  before do
398
399
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
399
400
  active_model_numericality_validator([:title], {:only_integer=>false, :allow_nil=>false, :less_than => 20, :less_than_or_equal_to=>2})
400
401
  ])
401
402
  end
402
-
403
+
403
404
  it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
404
405
  concat(semantic_form_for(@new_post) do |builder|
405
406
  builder.input(:title, :as => :range)
406
407
  end)
407
- expect(output_buffer).to have_tag('input[@max="2"]')
408
+ expect(output_buffer.to_str).to have_tag('input[@max="2"]')
408
409
  end
409
410
  end
410
-
411
+
411
412
  describe "when validations require only an integer (:only_integer)" do
412
-
413
+
413
414
  before do
414
415
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
415
416
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true})
416
417
  ])
417
418
  end
418
-
419
+
419
420
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
420
421
  concat(semantic_form_for(@new_post) do |builder|
421
422
  builder.input(:title, :as => :range)
422
423
  end)
423
- expect(output_buffer).to have_tag('input[@step="1"]')
424
+ expect(output_buffer.to_str).to have_tag('input[@step="1"]')
424
425
  end
425
-
426
+
426
427
  it "should let input_html override :step" do
427
428
  concat(semantic_form_for(@new_post) do |builder|
428
429
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
429
430
  end)
430
- expect(output_buffer).to have_tag('input[@step="3"]')
431
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
431
432
  end
432
-
433
+
433
434
  it "should let options override :step" do
434
435
  concat(semantic_form_for(@new_post) do |builder|
435
436
  builder.input(:title, :as => :range, :step => 3)
436
437
  end)
437
- expect(output_buffer).to have_tag('input[@step="3"]')
438
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
438
439
  end
439
-
440
+
440
441
  end
441
-
442
+
442
443
  describe "when validations require a :step (non standard)" do
443
-
444
+
444
445
  before do
445
446
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
446
447
  active_model_numericality_validator([:title], {:allow_nil=>false, :only_integer=>true, :step=>2})
447
448
  ])
448
449
  end
449
-
450
+
450
451
  it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
451
452
  concat(semantic_form_for(@new_post) do |builder|
452
453
  builder.input(:title, :as => :range)
453
454
  end)
454
- expect(output_buffer).to have_tag('input[@step="2"]')
455
+ expect(output_buffer.to_str).to have_tag('input[@step="2"]')
455
456
  end
456
-
457
+
457
458
  it "should let input_html override :step" do
458
459
  concat(semantic_form_for(@new_post) do |builder|
459
460
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
460
461
  end)
461
- expect(output_buffer).to have_tag('input[@step="3"]')
462
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
462
463
  end
463
-
464
+
464
465
  it "should let options override :step" do
465
466
  concat(semantic_form_for(@new_post) do |builder|
466
467
  builder.input(:title, :as => :range, :step => 3)
467
468
  end)
468
- expect(output_buffer).to have_tag('input[@step="3"]')
469
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
469
470
  end
470
-
471
+
471
472
  end
472
-
473
+
473
474
  describe "when validations do not specify :step (non standard) or :only_integer" do
474
-
475
+
475
476
  before do
476
477
  allow(@new_post.class).to receive(:validators_on).with(:title).and_return([
477
478
  active_model_numericality_validator([:title], {:allow_nil=>false})
478
479
  ])
479
480
  end
480
-
481
+
481
482
  it "should default step to 1" do
482
483
  concat(semantic_form_for(@new_post) do |builder|
483
484
  builder.input(:title, :as => :range)
484
485
  end)
485
- expect(output_buffer).to have_tag('input[@step="1"]')
486
+ expect(output_buffer.to_str).to have_tag('input[@step="1"]')
486
487
  end
487
-
488
+
488
489
  it "should let input_html set :step" do
489
490
  concat(semantic_form_for(@new_post) do |builder|
490
491
  builder.input(:title, :as => :range, :input_html => { :step => 3 })
491
492
  end)
492
- expect(output_buffer).to have_tag('input[@step="3"]')
493
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
493
494
  end
494
-
495
+
495
496
  it "should let options set :step" do
496
497
  concat(semantic_form_for(@new_post) do |builder|
497
498
  builder.input(:title, :as => :range, :step => 3)
498
499
  end)
499
- expect(output_buffer).to have_tag('input[@step="3"]')
500
+ expect(output_buffer.to_str).to have_tag('input[@step="3"]')
500
501
  end
501
-
502
+
502
503
  end
503
-
504
+
504
505
  end
505
506
 
@@ -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 'readonly option' do
@@ -6,7 +7,7 @@ RSpec.describe 'readonly option' 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
 
@@ -20,7 +21,7 @@ RSpec.describe 'readonly option' do
20
21
  concat(semantic_form_for(@new_post) do |builder|
21
22
  concat(builder.input(:title, :as => type, input_html: {readonly: true}))
22
23
  end)
23
- expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
24
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
24
25
  end
25
26
  end
26
27
 
@@ -30,7 +31,7 @@ RSpec.describe 'readonly option' do
30
31
  concat(semantic_form_for(@new_post) do |builder|
31
32
  concat(builder.input(:title, :as => type))
32
33
  end)
33
- expect(output_buffer).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
34
+ expect(output_buffer.to_str).not_to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
34
35
  end
35
36
  end
36
37
  describe "when column is readonly attribute" do
@@ -40,7 +41,7 @@ RSpec.describe 'readonly option' do
40
41
  concat(semantic_form_for(@new_post) do |builder|
41
42
  concat(builder.input(:title, :as => type))
42
43
  end)
43
- expect(output_buffer).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
44
+ expect(output_buffer.to_str).to have_tag((type == :text ? 'textarea' : 'input') + '[@readonly]')
44
45
  end
45
46
  end
46
47
  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 'search input' do
@@ -6,7 +7,7 @@ RSpec.describe 'search 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
 
@@ -41,11 +42,11 @@ RSpec.describe 'search input' do
41
42
  it_should_have_label_and_input_with_id("context2_post_search")
42
43
 
43
44
  end
44
-
45
+
45
46
  describe "when index is provided" do
46
47
 
47
48
  before do
48
- @output_buffer = ''
49
+ @output_buffer = ActionView::OutputBuffer.new ''
49
50
  mock_everything
50
51
 
51
52
  concat(semantic_form_for(@new_post) do |builder|
@@ -54,31 +55,31 @@ RSpec.describe 'search input' do
54
55
  end)
55
56
  end)
56
57
  end
57
-
58
+
58
59
  it 'should index the id of the wrapper' do
59
- expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
60
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
60
61
  end
61
-
62
+
62
63
  it 'should index the id of the select tag' do
63
- expect(output_buffer).to have_tag("input#post_author_attributes_3_name")
64
+ expect(output_buffer.to_str).to have_tag("input#post_author_attributes_3_name")
64
65
  end
65
-
66
+
66
67
  it 'should index the name of the select tag' do
67
- expect(output_buffer).to have_tag("input[@name='post[author_attributes][3][name]']")
68
+ expect(output_buffer.to_str).to have_tag("input[@name='post[author_attributes][3][name]']")
68
69
  end
69
-
70
+
70
71
  end
71
-
72
+
72
73
  describe "when required" do
73
74
  it "should add the required attribute to the input's html options" do
74
- with_config :use_required_attribute, true do
75
+ with_config :use_required_attribute, true do
75
76
  concat(semantic_form_for(@new_post) do |builder|
76
77
  concat(builder.input(:title, :as => :search, :required => true))
77
78
  end)
78
- expect(output_buffer).to have_tag("input[@required]")
79
+ expect(output_buffer.to_str).to have_tag("input[@required]")
79
80
  end
80
81
  end
81
82
  end
82
-
83
+
83
84
  end
84
85