formtastic 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 'select input' do
@@ -6,7 +7,7 @@ RSpec.describe 'select 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
 
@@ -23,14 +24,14 @@ RSpec.describe 'select input' do
23
24
 
24
25
  it 'should have a option for each key and/or value' do
25
26
  @array_with_values.each do |v|
26
- expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
27
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
27
28
  end
28
29
  @array_with_keys_and_values.each do |v|
29
- expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
30
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
30
31
  end
31
32
  end
32
33
  end
33
-
34
+
34
35
  describe 'using a set of values' do
35
36
  before do
36
37
  @set_with_values = Set.new(["Title A", "Title B", "Title C"])
@@ -43,10 +44,10 @@ RSpec.describe 'select input' do
43
44
 
44
45
  it 'should have a option for each key and/or value' do
45
46
  @set_with_values.each do |v|
46
- expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
47
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
47
48
  end
48
49
  @set_with_keys_and_values.each do |v|
49
- expect(output_buffer).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
50
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v.second}']", :text => /^#{v.first}$/)
50
51
  end
51
52
  end
52
53
  end
@@ -60,9 +61,9 @@ RSpec.describe 'select input' do
60
61
  end
61
62
 
62
63
  it 'should draw select options' do
63
- expect(output_buffer).to have_tag('form li select')
64
- expect(output_buffer).to have_tag('form li select#post_reviewer_id')
65
- expect(output_buffer).not_to have_tag('form li select#post_mongoid_reviewer_id')
64
+ expect(output_buffer.to_str).to have_tag('form li select')
65
+ expect(output_buffer.to_str).to have_tag('form li select#post_reviewer_id')
66
+ expect(output_buffer.to_str).not_to have_tag('form li select#post_mongoid_reviewer_id')
66
67
  end
67
68
  end
68
69
 
@@ -76,7 +77,7 @@ RSpec.describe 'select input' do
76
77
 
77
78
  it 'should have an option for each value' do
78
79
  @range_with_values.each do |v|
79
- expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
80
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
80
81
  end
81
82
  end
82
83
  end
@@ -91,7 +92,7 @@ RSpec.describe 'select input' do
91
92
 
92
93
  it 'should render select options using provided HTML string' do
93
94
  2.times do |v|
94
- expect(output_buffer).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
95
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{v}']", :text => /^#{v}$/)
95
96
  end
96
97
  end
97
98
  end
@@ -125,8 +126,8 @@ RSpec.describe 'select input' do
125
126
  end
126
127
 
127
128
  it 'should render a select with at least options: true/false' do
128
- expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /^Yes$/)
129
- expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /^No$/)
129
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='true']", :text => /^Yes$/)
130
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='false']", :text => /^No$/)
130
131
  end
131
132
  end
132
133
 
@@ -145,8 +146,8 @@ RSpec.describe 'select input' do
145
146
  end
146
147
 
147
148
  it 'should render a select with at least options: true/false' do
148
- expect(output_buffer).to have_tag("form li select option[@value='true']", :text => /#{@boolean_select_labels[:yes]}/)
149
- expect(output_buffer).to have_tag("form li select option[@value='false']", :text => /#{@boolean_select_labels[:no]}/)
149
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='true']", :text => /#{@boolean_select_labels[:yes]}/)
150
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='false']", :text => /#{@boolean_select_labels[:no]}/)
150
151
  end
151
152
  end
152
153
  end
@@ -159,6 +160,37 @@ RSpec.describe 'select input' do
159
160
  allow(@new_post).to receive(:defined_enums) { { "status" => statuses } }
160
161
  end
161
162
 
163
+ context 'with translations in a nested association input' do
164
+ before do
165
+ ::I18n.backend.store_translations :en, activerecord: {
166
+ attributes: {
167
+ post: {
168
+ statuses: {
169
+ active: 'I am active',
170
+ inactive: 'I am inactive'
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+ allow(@fred).to receive(:posts).and_return([@new_post])
177
+ concat(semantic_form_for(@fred) do |builder|
178
+ concat(builder.inputs(for: @fred.posts.first) do |nested_builder|
179
+ nested_builder.input(:status, as: :select)
180
+ end)
181
+ end)
182
+ end
183
+
184
+ after do
185
+ ::I18n.backend.reload!
186
+ end
187
+
188
+ it 'should use localized enum values' do
189
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='active']", text: 'I am active')
190
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='inactive']", text: 'I am inactive')
191
+ end
192
+ end
193
+
162
194
  context 'single choice' do
163
195
  before do
164
196
  concat(semantic_form_for(@new_post) do |builder|
@@ -174,40 +206,40 @@ RSpec.describe 'select input' do
174
206
  it_should_apply_error_logic_for_input_type(:select)
175
207
 
176
208
  it 'should have a select inside the wrapper' do
177
- expect(output_buffer).to have_tag('form li select')
178
- expect(output_buffer).to have_tag('form li select#post_status')
209
+ expect(output_buffer.to_str).to have_tag('form li select')
210
+ expect(output_buffer.to_str).to have_tag('form li select#post_status')
179
211
  end
180
212
 
181
213
  it 'should have a valid name' do
182
- expect(output_buffer).to have_tag("form li select[@name='post[status]']")
183
- expect(output_buffer).not_to have_tag("form li select[@name='post[status][]']")
214
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[status]']")
215
+ expect(output_buffer.to_str).not_to have_tag("form li select[@name='post[status][]']")
184
216
  end
185
217
 
186
218
  it 'should not create a multi-select' do
187
- expect(output_buffer).not_to have_tag('form li select[@multiple]')
219
+ expect(output_buffer.to_str).not_to have_tag('form li select[@multiple]')
188
220
  end
189
-
221
+
190
222
  it 'should not add a hidden input' do
191
- expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
223
+ expect(output_buffer.to_str).not_to have_tag('form li input[@type="hidden"]')
192
224
  end
193
225
 
194
226
  it 'should create a select without size' do
195
- expect(output_buffer).not_to have_tag('form li select[@size]')
227
+ expect(output_buffer.to_str).not_to have_tag('form li select[@size]')
196
228
  end
197
229
 
198
230
  it 'should have a blank option' do
199
- expect(output_buffer).to have_tag("form li select option[@value='']")
231
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
200
232
  end
201
233
 
202
234
  it 'should have a select option for each defined enum status' do
203
- expect(output_buffer).to have_tag("form li select[@name='post[status]'] option", :count => @new_post.class.statuses.count + 1)
235
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[status]'] option", :count => @new_post.class.statuses.count + 1)
204
236
  @new_post.class.statuses.each do |label, value|
205
- expect(output_buffer).to have_tag("form li select option[@value='#{label}']", :text => /#{label.humanize}/)
237
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{label}']", :text => /#{label.humanize}/)
206
238
  end
207
239
  end
208
240
 
209
241
  it 'should have one option with a "selected" attribute (TODO)' do
210
- expect(output_buffer).to have_tag("form li select[@name='post[status]'] option[@selected]", :count => 1)
242
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[status]'] option[@selected]", :count => 1)
211
243
  end
212
244
  end
213
245
 
@@ -240,42 +272,42 @@ RSpec.describe 'select input' do
240
272
  it_should_use_the_collection_when_provided(:select, 'option')
241
273
 
242
274
  it 'should have a select inside the wrapper' do
243
- expect(output_buffer).to have_tag('form li select')
244
- expect(output_buffer).to have_tag('form li select#post_author_id')
245
- expect(output_buffer).to have_tag('form li select#post_reviewer_id')
275
+ expect(output_buffer.to_str).to have_tag('form li select')
276
+ expect(output_buffer.to_str).to have_tag('form li select#post_author_id')
277
+ expect(output_buffer.to_str).to have_tag('form li select#post_reviewer_id')
246
278
  end
247
279
 
248
280
  it 'should have a valid name' do
249
- expect(output_buffer).to have_tag("form li select[@name='post[author_id]']")
250
- expect(output_buffer).not_to have_tag("form li select[@name='post[author_id][]']")
251
- expect(output_buffer).not_to have_tag("form li select[@name='post[reviewer_id][]']")
281
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[author_id]']")
282
+ expect(output_buffer.to_str).not_to have_tag("form li select[@name='post[author_id][]']")
283
+ expect(output_buffer.to_str).not_to have_tag("form li select[@name='post[reviewer_id][]']")
252
284
  end
253
285
 
254
286
  it 'should not create a multi-select' do
255
- expect(output_buffer).not_to have_tag('form li select[@multiple]')
287
+ expect(output_buffer.to_str).not_to have_tag('form li select[@multiple]')
256
288
  end
257
-
289
+
258
290
  it 'should not add a hidden input' do
259
- expect(output_buffer).not_to have_tag('form li input[@type="hidden"]')
291
+ expect(output_buffer.to_str).not_to have_tag('form li input[@type="hidden"]')
260
292
  end
261
293
 
262
294
  it 'should create a select without size' do
263
- expect(output_buffer).not_to have_tag('form li select[@size]')
295
+ expect(output_buffer.to_str).not_to have_tag('form li select[@size]')
264
296
  end
265
297
 
266
298
  it 'should have a blank option' do
267
- expect(output_buffer).to have_tag("form li select option[@value='']")
299
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
268
300
  end
269
301
 
270
302
  it 'should have a select option for each Author' do
271
- expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
303
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
272
304
  ::Author.all.each do |author|
273
- expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
305
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
274
306
  end
275
307
  end
276
308
 
277
309
  it 'should have one option with a "selected" attribute (bob)' do
278
- expect(output_buffer).to have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
310
+ expect(output_buffer.to_str).to have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
279
311
  end
280
312
 
281
313
  it 'should not singularize the association name' do
@@ -287,20 +319,20 @@ RSpec.describe 'select input' do
287
319
  concat(builder.input(:author_status, :as => :select))
288
320
  end)
289
321
 
290
- expect(output_buffer).to have_tag('form li select#post_author_status_id')
322
+ expect(output_buffer.to_str).to have_tag('form li select#post_author_status_id')
291
323
  end
292
324
  end
293
325
 
294
326
  describe "for a belongs_to association with :conditions" do
295
327
  before do
296
328
  allow(::Post).to receive(:reflect_on_association).with(:author) do
297
- mock = double('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
329
+ mock = double('reflection', :scope => nil, :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
298
330
  allow(mock).to receive(:[]).with(:class_name).and_return("Author")
299
331
  mock
300
332
  end
301
333
  end
302
334
 
303
- it "should call author.(scoped|where) with association conditions" do
335
+ it "should call author.where with association conditions" do
304
336
  expect(::Author).to receive(:where).with({:active => true})
305
337
 
306
338
  semantic_form_for(@new_post) do |builder|
@@ -309,6 +341,25 @@ RSpec.describe 'select input' do
309
341
  end
310
342
  end
311
343
 
344
+ describe "for a belongs_to association with scope" do
345
+ before do
346
+ @active_scope = -> { active }
347
+ allow(::Post).to receive(:reflect_on_association).with(:author) do
348
+ mock = double('reflection', :scope => @active_scope, options: {}, :klass => ::Author, :macro => :belongs_to)
349
+ allow(mock).to receive(:[]).with(:class_name).and_return("Author")
350
+ mock
351
+ end
352
+ end
353
+
354
+ it "should call author.merge with association scope" do
355
+ expect(::Author).to receive(:merge).with(@active_scope)
356
+
357
+ semantic_form_for(@new_post) do |builder|
358
+ concat(builder.input(:author, :as => :select))
359
+ end
360
+ end
361
+ end
362
+
312
363
  describe 'for a has_many association' do
313
364
  before do
314
365
  concat(semantic_form_for(@fred) do |builder|
@@ -325,31 +376,31 @@ RSpec.describe 'select input' do
325
376
  it_should_use_the_collection_when_provided(:select, 'option')
326
377
 
327
378
  it 'should have a select inside the wrapper' do
328
- expect(output_buffer).to have_tag('form li select')
329
- expect(output_buffer).to have_tag('form li select#author_post_ids')
379
+ expect(output_buffer.to_str).to have_tag('form li select')
380
+ expect(output_buffer.to_str).to have_tag('form li select#author_post_ids')
330
381
  end
331
382
 
332
383
  it 'should have a multi-select select' do
333
- expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
384
+ expect(output_buffer.to_str).to have_tag('form li select[@multiple="multiple"]')
334
385
  end
335
-
386
+
336
387
  it 'should append [] to the name attribute for multiple select' do
337
- expect(output_buffer).to have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
388
+ expect(output_buffer.to_str).to have_tag('form li select[@multiple="multiple"][@name="author[post_ids][]"]')
338
389
  end
339
390
 
340
391
  it 'should have a hidden field' do
341
- expect(output_buffer).to have_tag('form li input[@type="hidden"][@name="author[post_ids][]"]', :count => 1)
392
+ expect(output_buffer.to_str).to have_tag('form li input[@type="hidden"][@name="author[post_ids][]"]', :count => 1)
342
393
  end
343
394
 
344
395
  it 'should have a select option for each Post' do
345
- expect(output_buffer).to have_tag('form li select option', :count => ::Post.all.size)
396
+ expect(output_buffer.to_str).to have_tag('form li select option', :count => ::Post.all.size)
346
397
  ::Post.all.each do |post|
347
- expect(output_buffer).to have_tag("form li select option[@value='#{post.id}']", :text => /#{post.to_label}/)
398
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{post.id}']", :text => /#{post.to_label}/)
348
399
  end
349
400
  end
350
401
 
351
402
  it 'should not have a blank option by default' do
352
- expect(output_buffer).not_to have_tag("form li select option[@value='']")
403
+ expect(output_buffer.to_str).not_to have_tag("form li select option[@value='']")
353
404
  end
354
405
 
355
406
  it 'should respect the :include_blank option for single selects' do
@@ -357,7 +408,7 @@ RSpec.describe 'select input' do
357
408
  concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
358
409
  end)
359
410
 
360
- expect(output_buffer).to have_tag("form li select option[@value='']")
411
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
361
412
  end
362
413
 
363
414
  it 'should respect the :include_blank option for multiple selects' do
@@ -365,11 +416,11 @@ RSpec.describe 'select input' do
365
416
  concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
366
417
  end)
367
418
 
368
- expect(output_buffer).to have_tag("form li select option[@value='']")
419
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
369
420
  end
370
421
 
371
422
  it 'should have one option with a "selected" attribute' do
372
- expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
423
+ expect(output_buffer.to_str).to have_tag('form li select option[@selected]', :count => 1)
373
424
  end
374
425
  end
375
426
 
@@ -389,23 +440,23 @@ RSpec.describe 'select input' do
389
440
  it_should_use_the_collection_when_provided(:select, 'option')
390
441
 
391
442
  it 'should have a select inside the wrapper' do
392
- expect(output_buffer).to have_tag('form li select')
393
- expect(output_buffer).to have_tag('form li select#post_author_ids')
443
+ expect(output_buffer.to_str).to have_tag('form li select')
444
+ expect(output_buffer.to_str).to have_tag('form li select#post_author_ids')
394
445
  end
395
446
 
396
447
  it 'should have a multi-select select' do
397
- expect(output_buffer).to have_tag('form li select[@multiple="multiple"]')
448
+ expect(output_buffer.to_str).to have_tag('form li select[@multiple="multiple"]')
398
449
  end
399
450
 
400
451
  it 'should have a select option for each Author' do
401
- expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size)
452
+ expect(output_buffer.to_str).to have_tag('form li select option', :count => ::Author.all.size)
402
453
  ::Author.all.each do |author|
403
- expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
454
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
404
455
  end
405
456
  end
406
457
 
407
458
  it 'should not have a blank option by default' do
408
- expect(output_buffer).not_to have_tag("form li select option[@value='']")
459
+ expect(output_buffer.to_str).not_to have_tag("form li select option[@value='']")
409
460
  end
410
461
 
411
462
  it 'should respect the :include_blank option for single selects' do
@@ -413,7 +464,7 @@ RSpec.describe 'select input' do
413
464
  concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
414
465
  end)
415
466
 
416
- expect(output_buffer).to have_tag("form li select option[@value='']")
467
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
417
468
  end
418
469
 
419
470
  it 'should respect the :include_blank option for multiple selects' do
@@ -421,11 +472,11 @@ RSpec.describe 'select input' do
421
472
  concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
422
473
  end)
423
474
 
424
- expect(output_buffer).to have_tag("form li select option[@value='']")
475
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']")
425
476
  end
426
477
 
427
478
  it 'should have one option with a "selected" attribute' do
428
- expect(output_buffer).to have_tag('form li select option[@selected]', :count => 1)
479
+ expect(output_buffer.to_str).to have_tag('form li select option[@selected]', :count => 1)
429
480
  end
430
481
  end
431
482
 
@@ -438,11 +489,11 @@ RSpec.describe 'select input' do
438
489
  end
439
490
 
440
491
  it 'should have a select with prompt' do
441
- expect(output_buffer).to have_tag("form li select option[@value='']", :text => /choose author/, :count => 1)
492
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']", :text => /choose author/, :count => 1)
442
493
  end
443
494
 
444
495
  it 'should not have a second blank select option' do
445
- expect(output_buffer).to have_tag("form li select option[@value='']", :count => 1)
496
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='']", :count => 1)
446
497
  end
447
498
  end
448
499
 
@@ -454,18 +505,18 @@ RSpec.describe 'select input' do
454
505
  end
455
506
 
456
507
  it 'should generate label' do
457
- expect(output_buffer).to have_tag('form li label', :text => /Author/)
458
- expect(output_buffer).to have_tag("form li label[@for='project_author']")
508
+ expect(output_buffer.to_str).to have_tag('form li label', :text => /Author/)
509
+ expect(output_buffer.to_str).to have_tag("form li label[@for='project_author']")
459
510
  end
460
511
 
461
512
  it 'should generate select inputs' do
462
- expect(output_buffer).to have_tag('form li select#project_author')
463
- expect(output_buffer).to have_tag('form li select option', :count => ::Author.all.size + 1)
513
+ expect(output_buffer.to_str).to have_tag('form li select#project_author')
514
+ expect(output_buffer.to_str).to have_tag('form li select option', :count => ::Author.all.size + 1)
464
515
  end
465
516
 
466
517
  it 'should generate an option to each item' do
467
518
  ::Author.all.each do |author|
468
- expect(output_buffer).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
519
+ expect(output_buffer.to_str).to have_tag("form li select option[@value='#{author.id}']", :text => /#{author.to_label}/)
469
520
  end
470
521
  end
471
522
  end
@@ -476,7 +527,7 @@ RSpec.describe 'select input' do
476
527
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
477
528
  concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
478
529
  end)
479
- expect(output_buffer).to have_tag("form li select[@name='project[author_name]']")
530
+ expect(output_buffer.to_str).to have_tag("form li select[@name='project[author_name]']")
480
531
  end
481
532
 
482
533
  describe 'and :multiple is set to true through :input_html' do
@@ -484,7 +535,7 @@ RSpec.describe 'select input' do
484
535
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
485
536
  concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
486
537
  end)
487
- expect(output_buffer).to have_tag("form li select[@multiple]")
538
+ expect(output_buffer.to_str).to have_tag("form li select[@multiple]")
488
539
  end
489
540
  end
490
541
 
@@ -493,7 +544,7 @@ RSpec.describe 'select input' do
493
544
  concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
494
545
  concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
495
546
  end)
496
- expect(output_buffer).to have_tag("form li select[@multiple]")
547
+ expect(output_buffer.to_str).to have_tag("form li select[@multiple]")
497
548
  end
498
549
  end
499
550
 
@@ -511,18 +562,18 @@ RSpec.describe 'select input' do
511
562
 
512
563
  it 'should generate an option to each item' do
513
564
  @grouped_opts.each do |opt_pair|
514
- expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}']")
565
+ expect(output_buffer.to_str).to have_tag("form li select optgroup[@label='#{opt_pair[0]}']")
515
566
  opt_pair[1].each do |v|
516
- expect(output_buffer).to have_tag("form li select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
567
+ expect(output_buffer.to_str).to have_tag("form li select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
517
568
  end
518
569
  end
519
- expect(output_buffer).to have_tag("form li select optgroup option[@selected]","hands")
570
+ expect(output_buffer.to_str).to have_tag("form li select optgroup option[@selected]","hands")
520
571
  end
521
572
  end
522
573
 
523
574
  describe "enum" do
524
575
  before do
525
- @output_buffer = ''
576
+ @output_buffer = ActionView::OutputBuffer.new ''
526
577
  @some_meta_descriptions = ["One", "Two", "Three"]
527
578
  allow(@new_post).to receive(:meta_description).at_least(:once)
528
579
  end
@@ -538,7 +589,7 @@ RSpec.describe 'select input' do
538
589
  end
539
590
 
540
591
  it "should render a select field" do
541
- expect(output_buffer).to have_tag("form li select", :count => 2)
592
+ expect(output_buffer.to_str).to have_tag("form li select", :count => 2)
542
593
  end
543
594
  end
544
595
 
@@ -554,7 +605,7 @@ RSpec.describe 'select input' do
554
605
  end
555
606
 
556
607
  it "should render a text field" do
557
- expect(output_buffer).to have_tag("form li input[@type='text']", :count => 2)
608
+ expect(output_buffer.to_str).to have_tag("form li input[@type='text']", :count => 2)
558
609
  end
559
610
  end
560
611
  end
@@ -569,32 +620,32 @@ RSpec.describe 'select input' do
569
620
  it_should_have_select_with_id("context2_post_author_ids")
570
621
  it_should_have_label_for("context2_post_author_ids")
571
622
  end
572
-
623
+
573
624
  describe "when index is provided" do
574
-
625
+
575
626
  before do
576
- @output_buffer = ''
627
+ @output_buffer = ActionView::OutputBuffer.new ''
577
628
  mock_everything
578
-
629
+
579
630
  concat(semantic_form_for(@new_post) do |builder|
580
631
  concat(builder.fields_for(:author, :index => 3) do |author|
581
632
  concat(author.input(:name, :as => :select))
582
633
  end)
583
634
  end)
584
635
  end
585
-
636
+
586
637
  it 'should index the id of the wrapper' do
587
- expect(output_buffer).to have_tag("li#post_author_attributes_3_name_input")
638
+ expect(output_buffer.to_str).to have_tag("li#post_author_attributes_3_name_input")
588
639
  end
589
-
640
+
590
641
  it 'should index the id of the select tag' do
591
- expect(output_buffer).to have_tag("select#post_author_attributes_3_name")
642
+ expect(output_buffer.to_str).to have_tag("select#post_author_attributes_3_name")
592
643
  end
593
-
644
+
594
645
  it 'should index the name of the select' do
595
- expect(output_buffer).to have_tag("select[@name='post[author_attributes][3][name]']")
646
+ expect(output_buffer.to_str).to have_tag("select[@name='post[author_attributes][3][name]']")
596
647
  end
597
-
648
+
598
649
  end
599
650
 
600
651
  context "when required" do
@@ -603,7 +654,7 @@ RSpec.describe 'select input' do
603
654
  concat(semantic_form_for(@new_post) do |builder|
604
655
  concat(builder.input(:author, :as => :select, :required => true))
605
656
  end)
606
- expect(output_buffer).to have_tag("select[@required]")
657
+ expect(output_buffer.to_str).to have_tag("select[@required]")
607
658
  end
608
659
  end
609
660
  end