formtastic 3.1.5 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/.gitignore +3 -2
- data/.travis.yml +28 -40
- data/CHANGELOG.md +49 -0
- data/DEPRECATIONS +1 -1
- data/Gemfile.lock +104 -0
- data/README.md +628 -629
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +8 -14
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +5 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +8 -24
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +7 -3
- data/lib/formtastic/helpers/input_helper.rb +18 -76
- data/lib/formtastic/helpers/inputs_helper.rb +12 -3
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/collections.rb +1 -5
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +19 -9
- data/lib/formtastic/inputs/check_boxes_input.rb +3 -3
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/select_input.rb +1 -1
- data/lib/formtastic/localizer.rb +5 -7
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/templates/formtastic.rb +4 -6
- data/script/integration-template.rb +71 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +36 -20
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +31 -31
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +33 -33
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +6 -6
- data/spec/inputs/base/validations_spec.rb +157 -19
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +96 -95
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +63 -65
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +4 -4
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +92 -96
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +19 -19
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +163 -223
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1301
- data/spec/support/test_environment.rb +23 -9
- metadata +33 -123
- data/Appraisals +0 -43
- data/CHANGELOG +0 -54
- data/gemfiles/rails_3.2.gemfile +0 -9
- data/gemfiles/rails_4.0.4.gemfile +0 -8
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/gemfiles/rails_4.2.gemfile +0 -8
- data/gemfiles/rails_4.gemfile +0 -8
- data/gemfiles/rails_5.0.gemfile +0 -8
- data/gemfiles/rails_edge.gemfile +0 -15
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/util_spec.rb +0 -66
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe 'Formtastic::FormBuilder#inputs' do
|
4
|
+
RSpec.describe 'Formtastic::FormBuilder#inputs' do
|
5
5
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
@@ -23,24 +23,24 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should output just the content wrapped in inputs, not the whole template' do
|
26
|
-
output_buffer.
|
27
|
-
@inputs_output.
|
26
|
+
expect(output_buffer).to match(/before_builder/)
|
27
|
+
expect(@inputs_output).not_to match(/before_builder/)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
31
|
-
output_buffer.
|
31
|
+
expect(output_buffer).to have_tag("form fieldset.inputs")
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should render an ol inside the fieldset' do
|
35
|
-
output_buffer.
|
35
|
+
expect(output_buffer).to have_tag("form fieldset.inputs ol")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should render the contents of the block inside the ol' do
|
39
|
-
output_buffer.
|
39
|
+
expect(output_buffer).to have_tag("form fieldset.inputs ol", :text => /hello/)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should not render a legend inside the fieldset' do
|
43
|
-
output_buffer.
|
43
|
+
expect(output_buffer).not_to have_tag("form fieldset.inputs legend")
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should render a fieldset even if no object is given' do
|
@@ -49,20 +49,20 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
49
49
|
concat('bye')
|
50
50
|
end
|
51
51
|
end)
|
52
|
-
output_buffer.
|
52
|
+
expect(output_buffer).to have_tag("form fieldset.inputs ol", :text => /bye/)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
describe 'when a :for option is provided' do
|
57
57
|
|
58
58
|
before do
|
59
|
-
@new_post.
|
60
|
-
@new_post.
|
61
|
-
@new_post.
|
59
|
+
allow(@new_post).to receive(:respond_to?).and_return(true, true)
|
60
|
+
allow(@new_post).to receive(:respond_to?).with(:empty?).and_return(false)
|
61
|
+
allow(@new_post).to receive(:author).and_return(@bob)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should render nested inputs' do
|
65
|
-
@bob.
|
65
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
66
66
|
|
67
67
|
concat(semantic_form_for(@new_post) do |builder|
|
68
68
|
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
@@ -70,12 +70,12 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
70
70
|
end
|
71
71
|
concat(inputs)
|
72
72
|
end)
|
73
|
-
output_buffer.
|
74
|
-
output_buffer.
|
73
|
+
expect(output_buffer).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
74
|
+
expect(output_buffer).not_to have_tag("form fieldset.inputs #author_login")
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should concat rendered nested inputs to the template' do
|
78
|
-
@bob.
|
78
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
79
79
|
|
80
80
|
concat(semantic_form_for(@new_post) do |builder|
|
81
81
|
builder.inputs :for => [:author, @bob] do |bob_builder|
|
@@ -83,8 +83,8 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
83
83
|
end
|
84
84
|
end)
|
85
85
|
|
86
|
-
output_buffer.
|
87
|
-
output_buffer.
|
86
|
+
expect(output_buffer).to have_tag("form fieldset.inputs #post_author_attributes_login")
|
87
|
+
expect(output_buffer).not_to have_tag("form fieldset.inputs #author_login")
|
88
88
|
|
89
89
|
end
|
90
90
|
|
@@ -97,15 +97,15 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
97
97
|
end
|
98
98
|
concat(inputs)
|
99
99
|
end)
|
100
|
-
output_buffer.
|
100
|
+
expect(output_buffer).to have_tag("form input[@name='post[author_attributes][login]']")
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
104
104
|
|
105
105
|
describe "as a symbol representing a has_many association name" do
|
106
106
|
before do
|
107
|
-
@new_post.
|
108
|
-
@new_post.
|
107
|
+
allow(@new_post).to receive(:authors).and_return([@bob, @fred])
|
108
|
+
allow(@new_post).to receive(:authors_attributes=)
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should nest the inputs with a fieldset, legend and :name input for each item' do
|
@@ -115,13 +115,13 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
115
115
|
end
|
116
116
|
end)
|
117
117
|
|
118
|
-
output_buffer.
|
119
|
-
output_buffer.
|
120
|
-
output_buffer.
|
121
|
-
output_buffer.
|
122
|
-
output_buffer.
|
123
|
-
output_buffer.
|
124
|
-
output_buffer.
|
118
|
+
expect(output_buffer).to have_tag("form fieldset.inputs", :count => 2)
|
119
|
+
expect(output_buffer).to have_tag("form fieldset.inputs legend", :count => 2)
|
120
|
+
expect(output_buffer).to have_tag("form fieldset.inputs legend", :text => "1", :count => 1)
|
121
|
+
expect(output_buffer).to have_tag("form fieldset.inputs legend", :text => "2")
|
122
|
+
expect(output_buffer).to have_tag("form input[@name='post[authors_attributes][0][login]']")
|
123
|
+
expect(output_buffer).to have_tag("form input[@name='post[authors_attributes][1][login]']")
|
124
|
+
expect(output_buffer).not_to have_tag('form fieldset[@name]')
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should include an indexed :label input for each item' do
|
@@ -131,9 +131,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
131
131
|
end
|
132
132
|
end)
|
133
133
|
|
134
|
-
output_buffer.
|
135
|
-
output_buffer.
|
136
|
-
output_buffer.
|
134
|
+
expect(output_buffer).to have_tag("form fieldset.inputs label", :text => "1", :count => 1)
|
135
|
+
expect(output_buffer).to have_tag("form fieldset.inputs label", :text => "2", :count => 1)
|
136
|
+
expect(output_buffer).not_to have_tag('form fieldset legend')
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -146,7 +146,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
146
146
|
end
|
147
147
|
concat(inputs)
|
148
148
|
end)
|
149
|
-
output_buffer.
|
149
|
+
expect(output_buffer).to have_tag("form input[@name='post[author_attributes][login]']")
|
150
150
|
end
|
151
151
|
|
152
152
|
end
|
@@ -160,24 +160,24 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
160
160
|
end
|
161
161
|
concat(inputs)
|
162
162
|
end)
|
163
|
-
output_buffer.
|
163
|
+
expect(output_buffer).to have_tag("form input[@name='post[author][login]']")
|
164
164
|
end
|
165
165
|
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'should raise an error if :for and block with no argument is given' do
|
169
169
|
semantic_form_for(@new_post) do |builder|
|
170
|
-
|
170
|
+
expect {
|
171
171
|
builder.inputs(:for => [:author, @bob]) do
|
172
172
|
#
|
173
173
|
end
|
174
|
-
}.
|
174
|
+
}.to raise_error(ArgumentError, 'You gave :for option with a block to inputs method, ' <<
|
175
175
|
'but the block does not accept any argument.')
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'should pass options down to semantic_fields_for' do
|
180
|
-
@bob.
|
180
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
181
181
|
|
182
182
|
concat(semantic_form_for(@new_post) do |builder|
|
183
183
|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
@@ -186,7 +186,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
186
186
|
concat(inputs)
|
187
187
|
end)
|
188
188
|
|
189
|
-
output_buffer.
|
189
|
+
expect(output_buffer).to have_tag('form fieldset ol li #post_author_attributes_10_login')
|
190
190
|
end
|
191
191
|
|
192
192
|
it 'should not add builder as a fieldset attribute tag' do
|
@@ -197,7 +197,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
197
197
|
concat(inputs)
|
198
198
|
end)
|
199
199
|
|
200
|
-
output_buffer.
|
200
|
+
expect(output_buffer).not_to have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'should send parent_builder as an option to allow child index interpolation for legends' do
|
@@ -209,7 +209,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
209
209
|
concat(inputs)
|
210
210
|
end)
|
211
211
|
|
212
|
-
output_buffer.
|
212
|
+
expect(output_buffer).to have_tag('fieldset legend', :text => 'Author #1')
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'should also provide child index interpolation for legends when nested child index is a hash' do
|
@@ -221,7 +221,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
221
221
|
concat(inputs)
|
222
222
|
end)
|
223
223
|
|
224
|
-
output_buffer.
|
224
|
+
expect(output_buffer).to have_tag('fieldset legend', :text => 'Author #11')
|
225
225
|
end
|
226
226
|
|
227
227
|
it 'should send parent_builder as an option to allow child index interpolation for labels' do
|
@@ -233,7 +233,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
233
233
|
concat(inputs)
|
234
234
|
end)
|
235
235
|
|
236
|
-
output_buffer.
|
236
|
+
expect(output_buffer).to have_tag('fieldset label', :text => 'Author #1')
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'should also provide child index interpolation for labels when nested child index is a hash' do
|
@@ -245,7 +245,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
245
245
|
concat(inputs)
|
246
246
|
end)
|
247
247
|
|
248
|
-
output_buffer.
|
248
|
+
expect(output_buffer).to have_tag('fieldset label', :text => 'Author #11')
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
@@ -274,10 +274,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
274
274
|
|
275
275
|
# TODO: looks like the block isn't being called for the last assertion here
|
276
276
|
it 'should render a fieldset with a legend inside the form' do
|
277
|
-
output_buffer.
|
278
|
-
output_buffer.
|
279
|
-
output_buffer.
|
280
|
-
output_buffer.
|
277
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@legend_text}$/)
|
278
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_name}$/)
|
279
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@legend_text_using_title}$/)
|
280
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@nested_forms_legend_text}$/)
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
@@ -311,10 +311,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
311
311
|
|
312
312
|
# TODO: looks like the block isn't being called for the last assertion here
|
313
313
|
it 'should render a fieldset with a localized legend inside the form' do
|
314
|
-
output_buffer.
|
315
|
-
output_buffer.
|
316
|
-
output_buffer.
|
317
|
-
output_buffer.
|
314
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text}$/)
|
315
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_name}$/)
|
316
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@localized_legend_text_using_title}$/)
|
317
|
+
expect(output_buffer).to have_tag("form fieldset legend", :text => /^#{@localized_nested_forms_legend_text}$/)
|
318
318
|
end
|
319
319
|
end
|
320
320
|
end
|
@@ -331,8 +331,8 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
331
331
|
end
|
332
332
|
|
333
333
|
it 'should pass the options into the fieldset tag as attributes' do
|
334
|
-
output_buffer.
|
335
|
-
output_buffer.
|
334
|
+
expect(output_buffer).to have_tag("form fieldset##{@id_option}")
|
335
|
+
expect(output_buffer).to have_tag("form fieldset.#{@class_option}")
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
@@ -341,17 +341,17 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
341
341
|
describe 'without a block' do
|
342
342
|
|
343
343
|
before do
|
344
|
-
::Post.
|
344
|
+
allow(::Post).to receive(:reflections).and_return({:author => double('reflection', :options => {}, :macro => :belongs_to),
|
345
345
|
:comments => double('reflection', :options => {}, :macro => :has_many) })
|
346
346
|
|
347
|
-
@new_post.
|
348
|
-
@new_post.
|
349
|
-
@new_post.
|
347
|
+
allow(@new_post).to receive(:title)
|
348
|
+
allow(@new_post).to receive(:body)
|
349
|
+
allow(@new_post).to receive(:author_id)
|
350
350
|
|
351
|
-
@new_post.
|
352
|
-
@new_post.
|
353
|
-
@new_post.
|
354
|
-
@new_post.
|
351
|
+
allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
|
352
|
+
allow(@new_post).to receive(:column_for_attribute).with(:body).and_return(double('column', :type => :text))
|
353
|
+
allow(@new_post).to receive(:column_for_attribute).with(:created_at).and_return(double('column', :type => :datetime))
|
354
|
+
allow(@new_post).to receive(:column_for_attribute).with(:author).and_return(nil)
|
355
355
|
end
|
356
356
|
|
357
357
|
describe 'with no args (quick forms syntax)' do
|
@@ -362,51 +362,66 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
362
362
|
end
|
363
363
|
|
364
364
|
it 'should render a form' do
|
365
|
-
output_buffer.
|
365
|
+
expect(output_buffer).to have_tag('form')
|
366
366
|
end
|
367
367
|
|
368
368
|
it 'should render a fieldset inside the form' do
|
369
|
-
output_buffer.
|
369
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs')
|
370
370
|
end
|
371
371
|
|
372
372
|
it 'should not render a legend in the fieldset' do
|
373
|
-
output_buffer.
|
373
|
+
expect(output_buffer).not_to have_tag('form > fieldset.inputs > legend')
|
374
374
|
end
|
375
375
|
|
376
376
|
it 'should render an ol in the fieldset' do
|
377
|
-
output_buffer.
|
377
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol')
|
378
378
|
end
|
379
379
|
|
380
380
|
it 'should render a list item in the ol for each column and reflection' do
|
381
381
|
# Remove the :has_many macro and :created_at column
|
382
382
|
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
383
|
-
output_buffer.
|
383
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li', :count => count)
|
384
384
|
end
|
385
385
|
|
386
386
|
it 'should render a string list item for title' do
|
387
|
-
output_buffer.
|
387
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.string')
|
388
388
|
end
|
389
389
|
|
390
390
|
it 'should render a text list item for body' do
|
391
|
-
output_buffer.
|
391
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.text')
|
392
392
|
end
|
393
393
|
|
394
394
|
it 'should render a select list item for author_id' do
|
395
|
-
output_buffer.
|
395
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
396
396
|
end
|
397
397
|
|
398
398
|
it 'should not render timestamps inputs by default' do
|
399
|
-
output_buffer.
|
399
|
+
expect(output_buffer).not_to have_tag('form > fieldset.inputs > ol > li.datetime')
|
400
400
|
end
|
401
|
-
|
401
|
+
|
402
|
+
context "with non-standard foregin keys" do
|
403
|
+
before do
|
404
|
+
@output_buffer = ''
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should respect foreign key while rendering select' do
|
408
|
+
concat(semantic_form_for(LegacyPost.new, {:url => '/'}) do |builder|
|
409
|
+
concat(builder.inputs)
|
410
|
+
end)
|
411
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.select select#legacy_post_post_author', :count => 1)
|
412
|
+
expect(output_buffer).not_to have_tag('input#legacy_post_post_author')
|
413
|
+
end
|
414
|
+
|
415
|
+
end
|
416
|
+
|
402
417
|
context "with a polymorphic association" do
|
403
418
|
|
404
419
|
before do
|
405
|
-
@new_post.
|
406
|
-
@new_post.class.
|
420
|
+
allow(@new_post).to receive(:commentable)
|
421
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
407
422
|
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
408
423
|
})
|
409
|
-
@new_post.
|
424
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
410
425
|
double('column', :type => :integer)
|
411
426
|
)
|
412
427
|
end
|
@@ -415,7 +430,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
415
430
|
concat(semantic_form_for(@new_post) do |builder|
|
416
431
|
concat(builder.inputs)
|
417
432
|
end)
|
418
|
-
output_buffer.
|
433
|
+
expect(output_buffer).not_to have_tag('li#post_commentable_input')
|
419
434
|
end
|
420
435
|
|
421
436
|
end
|
@@ -428,9 +443,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
428
443
|
concat(builder.inputs(:title, :body))
|
429
444
|
end)
|
430
445
|
|
431
|
-
output_buffer.
|
432
|
-
output_buffer.
|
433
|
-
output_buffer.
|
446
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
447
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.string')
|
448
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.text')
|
434
449
|
end
|
435
450
|
end
|
436
451
|
|
@@ -440,21 +455,21 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
440
455
|
concat(builder.inputs(:title, :body))
|
441
456
|
end)
|
442
457
|
|
443
|
-
output_buffer.
|
458
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
444
459
|
end
|
445
460
|
end
|
446
461
|
|
447
462
|
context "with a polymorphic association" do
|
448
463
|
|
449
464
|
it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
|
450
|
-
@new_post.
|
451
|
-
@new_post.class.
|
465
|
+
allow(@new_post).to receive(:commentable)
|
466
|
+
allow(@new_post.class).to receive(:reflections).and_return({
|
452
467
|
:commentable => double('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
453
468
|
})
|
454
|
-
@new_post.
|
469
|
+
allow(@new_post).to receive(:column_for_attribute).with(:commentable).and_return(
|
455
470
|
double('column', :type => :integer)
|
456
471
|
)
|
457
|
-
@new_post.class.
|
472
|
+
allow(@new_post.class).to receive(:reflect_on_association).with(:commentable).and_return(
|
458
473
|
double('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
|
459
474
|
)
|
460
475
|
|
@@ -472,13 +487,13 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
472
487
|
describe 'when a :for option is provided' do
|
473
488
|
describe 'and an object is given' do
|
474
489
|
it 'should render nested inputs' do
|
475
|
-
@bob.
|
490
|
+
allow(@bob).to receive(:column_for_attribute).and_return(double('column', :type => :string, :limit => 255))
|
476
491
|
concat(semantic_form_for(@new_post) do |builder|
|
477
492
|
concat(builder.inputs(:login, :for => @bob))
|
478
493
|
end)
|
479
494
|
|
480
|
-
output_buffer.
|
481
|
-
output_buffer.
|
495
|
+
expect(output_buffer).to have_tag("form fieldset.inputs #post_author_login")
|
496
|
+
expect(output_buffer).not_to have_tag("form fieldset.inputs #author_login")
|
482
497
|
end
|
483
498
|
end
|
484
499
|
|
@@ -487,8 +502,8 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
487
502
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
488
503
|
concat(builder.inputs(:login, :for => @bob))
|
489
504
|
end)
|
490
|
-
output_buffer.
|
491
|
-
output_buffer.
|
505
|
+
expect(output_buffer).to have_tag("form fieldset.inputs #project_author_login")
|
506
|
+
expect(output_buffer).not_to have_tag("form fieldset.inputs #project_login")
|
492
507
|
end
|
493
508
|
end
|
494
509
|
end
|
@@ -504,16 +519,16 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
504
519
|
end
|
505
520
|
|
506
521
|
it 'should render a form with a fieldset containing two list items' do
|
507
|
-
output_buffer.
|
522
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
508
523
|
end
|
509
524
|
|
510
525
|
it 'should pass the options down to the fieldset' do
|
511
|
-
output_buffer.
|
526
|
+
expect(output_buffer).to have_tag('form > fieldset#my-id.inputs')
|
512
527
|
end
|
513
528
|
|
514
529
|
it 'should use the special :name option as a text for the legend tag' do
|
515
|
-
output_buffer.
|
516
|
-
output_buffer.
|
530
|
+
expect(output_buffer).to have_tag('form > fieldset#my-id.inputs > legend', :text => /^#{@legend_text_using_option}$/)
|
531
|
+
expect(output_buffer).to have_tag('form > fieldset#my-id-2.inputs > legend', :text => /^#{@legend_text_using_arg}$/)
|
517
532
|
end
|
518
533
|
end
|
519
534
|
|
@@ -524,9 +539,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
524
539
|
concat(builder.inputs :except => :body)
|
525
540
|
end)
|
526
541
|
|
527
|
-
output_buffer.
|
528
|
-
output_buffer.
|
529
|
-
output_buffer.
|
542
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
543
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.string')
|
544
|
+
expect(output_buffer).not_to have_tag('form > fieldset.inputs > ol > li.text')
|
530
545
|
end
|
531
546
|
|
532
547
|
it 'should render a form with a fieldset containing only text item' do
|
@@ -534,9 +549,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
534
549
|
concat(builder.inputs :except => :title)
|
535
550
|
end)
|
536
551
|
|
537
|
-
output_buffer.
|
538
|
-
output_buffer.
|
539
|
-
output_buffer.
|
552
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
553
|
+
expect(output_buffer).not_to have_tag('form > fieldset.inputs > ol > li.string')
|
554
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.text')
|
540
555
|
end
|
541
556
|
end
|
542
557
|
|
@@ -546,7 +561,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
546
561
|
concat(builder.inputs(:title, :body))
|
547
562
|
end)
|
548
563
|
|
549
|
-
output_buffer.
|
564
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
|
550
565
|
end
|
551
566
|
end
|
552
567
|
end
|
@@ -560,7 +575,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
560
575
|
concat(builder.inputs do
|
561
576
|
end)
|
562
577
|
end)
|
563
|
-
output_buffer.
|
578
|
+
expect(output_buffer).not_to have_tag('form > li')
|
564
579
|
end
|
565
580
|
end
|
566
581
|
|
@@ -572,7 +587,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
572
587
|
end)
|
573
588
|
end)
|
574
589
|
end)
|
575
|
-
output_buffer.
|
590
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
576
591
|
end
|
577
592
|
end
|
578
593
|
|
@@ -584,7 +599,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
584
599
|
end)
|
585
600
|
end)
|
586
601
|
end)
|
587
|
-
output_buffer.
|
602
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
588
603
|
end
|
589
604
|
end
|
590
605
|
|
@@ -595,7 +610,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
595
610
|
concat(builder.inputs(:title))
|
596
611
|
end)
|
597
612
|
end)
|
598
|
-
output_buffer.
|
613
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
599
614
|
end
|
600
615
|
end
|
601
616
|
|
@@ -606,7 +621,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
606
621
|
concat(builder.inputs(:name, :for => :author))
|
607
622
|
end)
|
608
623
|
end)
|
609
|
-
output_buffer.
|
624
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
610
625
|
end
|
611
626
|
end
|
612
627
|
|
@@ -620,7 +635,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
620
635
|
end)
|
621
636
|
end)
|
622
637
|
end)
|
623
|
-
output_buffer.
|
638
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
624
639
|
end
|
625
640
|
end
|
626
641
|
|
@@ -634,7 +649,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
634
649
|
end)
|
635
650
|
end)
|
636
651
|
end)
|
637
|
-
output_buffer.
|
652
|
+
expect(output_buffer).to have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol', :count => 2)
|
638
653
|
end
|
639
654
|
end
|
640
655
|
|
@@ -647,7 +662,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
647
662
|
end
|
648
663
|
end
|
649
664
|
it "should throw PolymorphicInputWithoutCollectionError on sub_posts" do
|
650
|
-
::MongoPost.
|
665
|
+
expect(::MongoPost).to receive(:associations).at_least(3).times
|
651
666
|
expect { generate_form }.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
652
667
|
end
|
653
668
|
end
|