speedo-formstrap 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/Gemfile.lock +67 -65
- data/README.md +12 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/formtastic-bootstrap.rb +1 -0
- data/lib/formtastic-bootstrap/actions.rb +4 -0
- data/lib/formtastic-bootstrap/actions/base.rb +18 -0
- data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
- data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
- data/lib/formtastic-bootstrap/form_builder.rb +7 -5
- data/lib/formtastic-bootstrap/helpers.rb +3 -1
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +13 -9
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +4 -4
- data/lib/formtastic-bootstrap/inputs/base.rb +2 -1
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +12 -23
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +16 -6
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +5 -12
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +32 -14
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +7 -11
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +10 -9
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +5 -3
- data/lib/formtastic-bootstrap/inputs/number_input.rb +2 -2
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -12
- data/lib/formtastic-bootstrap/inputs/range_input.rb +2 -2
- data/spec/actions/button_action_spec.rb +68 -0
- data/spec/actions/generic_action_spec.rb +486 -0
- data/spec/actions/input_action_spec.rb +64 -0
- data/spec/actions/link_action_spec.rb +93 -0
- data/spec/builder/semantic_fields_for_spec.rb +14 -14
- data/spec/helpers/action_helper_spec.rb +365 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/buttons_helper_spec.rb +55 -45
- data/spec/helpers/input_helper_spec.rb +188 -188
- data/spec/helpers/inputs_helper_spec.rb +116 -102
- data/spec/inputs/boolean_input_spec.rb +72 -44
- data/spec/inputs/check_boxes_input_spec.rb +108 -80
- data/spec/inputs/date_input_spec.rb +80 -14
- data/spec/inputs/datetime_input_spec.rb +12 -12
- data/spec/inputs/email_input_spec.rb +33 -5
- data/spec/inputs/file_input_spec.rb +33 -5
- data/spec/inputs/hidden_input_spec.rb +40 -12
- data/spec/inputs/number_input_spec.rb +126 -96
- data/spec/inputs/password_input_spec.rb +33 -5
- data/spec/inputs/phone_input_spec.rb +33 -5
- data/spec/inputs/radio_input_spec.rb +72 -44
- data/spec/inputs/range_input_spec.rb +93 -65
- data/spec/inputs/search_input_spec.rb +32 -5
- data/spec/inputs/select_input_spec.rb +123 -77
- data/spec/inputs/string_input_spec.rb +66 -21
- data/spec/inputs/text_input_spec.rb +40 -13
- data/spec/inputs/time_input_spec.rb +22 -22
- data/spec/inputs/time_zone_input_spec.rb +17 -17
- data/spec/inputs/url_input_spec.rb +33 -5
- data/spec/support/custom_macros.rb +59 -188
- data/spec/support/formtastic_spec_helper.rb +19 -3
- data/speedo-formstrap.gemspec +146 -0
- metadata +31 -16
@@ -12,7 +12,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'with a block (block forms syntax)' do
|
15
|
-
|
15
|
+
|
16
16
|
describe 'when no options are provided' do
|
17
17
|
before do
|
18
18
|
output_buffer.replace 'before_builder' # clear the output buffer and sets before_builder
|
@@ -22,30 +22,30 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
22
22
|
end
|
23
23
|
end)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it 'should output just the content wrapped in inputs, not the whole template' do
|
27
27
|
output_buffer.should =~ /before_builder/
|
28
28
|
@inputs_output.should_not =~ /before_builder/
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
32
32
|
output_buffer.should have_tag("form fieldset.inputs")
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it 'should not render an ol inside the fieldset' do
|
36
36
|
# output_buffer.should have_tag("form fieldset.inputs ol")
|
37
37
|
output_buffer.should_not have_tag("form fieldset.inputs ol")
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it 'should render the contents of the block inside the fieldset' do
|
41
41
|
# output_buffer.should have_tag("form fieldset.inputs ol", /hello/)
|
42
42
|
output_buffer.should have_tag("form fieldset.inputs", /hello/)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it 'should not render a legend inside the fieldset' do
|
46
46
|
output_buffer.should_not have_tag("form fieldset.inputs legend")
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it 'should render a fieldset even if no object is given' do
|
50
50
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
51
51
|
@inputs_output = builder.inputs do
|
@@ -55,17 +55,17 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
55
55
|
output_buffer.should have_tag("form fieldset.inputs", /bye/)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
describe 'when a :for option is provided' do
|
60
|
-
|
60
|
+
|
61
61
|
before do
|
62
62
|
@new_post.stub!(:respond_to?).and_return(true, true)
|
63
63
|
@new_post.stub!(:author).and_return(@bob)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it 'should render nested inputs' do
|
67
67
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
68
|
-
|
68
|
+
|
69
69
|
concat(semantic_form_for(@new_post) do |builder|
|
70
70
|
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
71
71
|
concat(bob_builder.input(:login))
|
@@ -75,23 +75,23 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
75
75
|
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
76
76
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it 'should concat rendered nested inputs to the template' do
|
80
80
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
81
|
-
|
81
|
+
|
82
82
|
concat(semantic_form_for(@new_post) do |builder|
|
83
83
|
builder.inputs :for => [:author, @bob] do |bob_builder|
|
84
84
|
concat(bob_builder.input(:login))
|
85
85
|
end
|
86
86
|
end)
|
87
|
-
|
87
|
+
|
88
88
|
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
89
89
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
90
|
-
|
90
|
+
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
describe "as a symbol representing the association name" do
|
94
|
-
|
94
|
+
|
95
95
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
96
96
|
concat(semantic_form_for(@new_post) do |post|
|
97
97
|
inputs = post.inputs :for => :author do |author|
|
@@ -101,22 +101,22 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
101
101
|
end)
|
102
102
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
describe "as a symbol representing a has_many association name" do
|
108
108
|
before do
|
109
109
|
@new_post.stub!(:authors).and_return([@bob, @fred])
|
110
110
|
@new_post.stub!(:authors_attributes=)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it 'should nest the inputs with a fieldset, legend and :name input for each item' do
|
114
114
|
concat(semantic_form_for(@new_post) do |post|
|
115
115
|
post.inputs :for => :authors, :name => '%i' do |author|
|
116
116
|
concat(author.input(:login))
|
117
117
|
end
|
118
118
|
end)
|
119
|
-
|
119
|
+
|
120
120
|
output_buffer.should have_tag("form fieldset.inputs", :count => 2)
|
121
121
|
output_buffer.should have_tag("form fieldset.inputs legend", :count => 2)
|
122
122
|
output_buffer.should have_tag("form fieldset.inputs legend", "1", :count => 1)
|
@@ -126,9 +126,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
126
126
|
output_buffer.should_not have_tag('form fieldset[@name]')
|
127
127
|
end
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
describe 'as an array containing the a symbole for the association name and the associated object' do
|
131
|
-
|
131
|
+
|
132
132
|
it 'should nest the inputs with an _attributes suffix on the association name' do
|
133
133
|
concat(semantic_form_for(@new_post) do |post|
|
134
134
|
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
@@ -138,11 +138,11 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
138
138
|
end)
|
139
139
|
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
describe 'as an associated object' do
|
145
|
-
|
145
|
+
|
146
146
|
it 'should not nest the inputs with an _attributes suffix' do
|
147
147
|
concat(semantic_form_for(@new_post) do |post|
|
148
148
|
inputs = post.inputs :for => @new_post.author do |author|
|
@@ -152,9 +152,9 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
152
152
|
end)
|
153
153
|
output_buffer.should have_tag("form input[@name='post[author][login]']")
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
it 'should raise an error if :for and block with no argument is given' do
|
159
159
|
semantic_form_for(@new_post) do |builder|
|
160
160
|
proc {
|
@@ -165,20 +165,20 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
165
165
|
'but the block does not accept any argument.')
|
166
166
|
end
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
it 'should pass options down to semantic_fields_for' do
|
170
170
|
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
171
|
-
|
171
|
+
|
172
172
|
concat(semantic_form_for(@new_post) do |builder|
|
173
173
|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
174
174
|
concat(bob_builder.input(:login))
|
175
175
|
end
|
176
176
|
concat(inputs)
|
177
177
|
end)
|
178
|
-
|
179
|
-
output_buffer.should have_tag('form fieldset div.
|
178
|
+
|
179
|
+
output_buffer.should have_tag('form fieldset div.control-group div.controls #post_author_attributes_10_login')
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
it 'should not add builder as a fieldset attribute tag' do
|
183
183
|
concat(semantic_form_for(@new_post) do |builder|
|
184
184
|
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
@@ -186,10 +186,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
186
186
|
end
|
187
187
|
concat(inputs)
|
188
188
|
end)
|
189
|
-
|
189
|
+
|
190
190
|
output_buffer.should_not have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
it 'should send parent_builder as an option to allow child index interpolation' do
|
194
194
|
concat(semantic_form_for(@new_post) do |builder|
|
195
195
|
builder.instance_variable_set('@nested_child_index', 0)
|
@@ -198,10 +198,10 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
198
198
|
end
|
199
199
|
concat(inputs)
|
200
200
|
end)
|
201
|
-
|
201
|
+
|
202
202
|
output_buffer.should have_tag('fieldset legend', 'Author #1')
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
it 'should also provide child index interpolation when nested child index is a hash' do
|
206
206
|
concat(semantic_form_for(@new_post) do |builder|
|
207
207
|
builder.instance_variable_set('@nested_child_index', :author => 10)
|
@@ -210,11 +210,11 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
210
210
|
end
|
211
211
|
concat(inputs)
|
212
212
|
end)
|
213
|
-
|
213
|
+
|
214
214
|
output_buffer.should have_tag('fieldset legend', 'Author #11')
|
215
215
|
end
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
describe 'when a :name or :title option is provided' do
|
219
219
|
describe 'and is a string' do
|
220
220
|
before do
|
@@ -237,7 +237,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
237
237
|
concat(inputs)
|
238
238
|
end)
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
it 'should render a fieldset with a legend inside the form' do
|
242
242
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text}$/)
|
243
243
|
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_name}$/)
|
@@ -245,7 +245,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
245
245
|
output_buffer.should have_tag("form fieldset legend", /^#{@nested_forms_legend_text}$/)
|
246
246
|
end
|
247
247
|
end
|
248
|
-
|
248
|
+
|
249
249
|
describe 'and is a symbol' do
|
250
250
|
before do
|
251
251
|
@localized_legend_text = "Localized advanced options"
|
@@ -277,7 +277,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
277
277
|
concat(inputs)
|
278
278
|
end)
|
279
279
|
end
|
280
|
-
|
280
|
+
|
281
281
|
it 'should render a fieldset with a localized legend inside the form' do
|
282
282
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text}$/)
|
283
283
|
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_name}$/)
|
@@ -286,138 +286,138 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
286
286
|
end
|
287
287
|
end
|
288
288
|
end
|
289
|
-
|
289
|
+
|
290
290
|
describe 'when other options are provided' do
|
291
291
|
before do
|
292
292
|
@id_option = 'advanced'
|
293
293
|
@class_option = 'wide'
|
294
|
-
|
294
|
+
|
295
295
|
concat(semantic_form_for(@new_post) do |builder|
|
296
296
|
builder.inputs :id => @id_option, :class => @class_option do
|
297
297
|
end
|
298
298
|
end)
|
299
299
|
end
|
300
|
-
|
300
|
+
|
301
301
|
it 'should pass the options into the fieldset tag as attributes' do
|
302
302
|
output_buffer.should have_tag("form fieldset##{@id_option}")
|
303
303
|
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
304
304
|
end
|
305
305
|
end
|
306
|
-
|
306
|
+
|
307
307
|
end
|
308
|
-
|
308
|
+
|
309
309
|
describe 'without a block' do
|
310
|
-
|
310
|
+
|
311
311
|
before do
|
312
312
|
::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to),
|
313
313
|
:comments => mock('reflection', :options => {}, :macro => :has_many) })
|
314
314
|
::Author.stub!(:find).and_return([@fred, @bob])
|
315
|
-
|
315
|
+
|
316
316
|
@new_post.stub!(:title)
|
317
317
|
@new_post.stub!(:body)
|
318
318
|
@new_post.stub!(:author_id)
|
319
|
-
|
319
|
+
|
320
320
|
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
|
321
321
|
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
|
322
322
|
@new_post.stub!(:column_for_attribute).with(:created_at).and_return(mock('column', :type => :datetime))
|
323
323
|
@new_post.stub!(:column_for_attribute).with(:author).and_return(nil)
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
describe 'with no args (quick forms syntax)' do
|
327
327
|
before do
|
328
328
|
concat(semantic_form_for(@new_post) do |builder|
|
329
329
|
concat(builder.inputs)
|
330
330
|
end)
|
331
331
|
end
|
332
|
-
|
332
|
+
|
333
333
|
it 'should render a form' do
|
334
334
|
output_buffer.should have_tag('form')
|
335
335
|
end
|
336
|
-
|
336
|
+
|
337
337
|
it 'should render a fieldset inside the form' do
|
338
338
|
output_buffer.should have_tag('form > fieldset.inputs')
|
339
339
|
end
|
340
|
-
|
340
|
+
|
341
341
|
it 'should not render a legend in the fieldset' do
|
342
342
|
output_buffer.should_not have_tag('form > fieldset.inputs > legend')
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
it 'should not render an ol in the fieldset' do
|
346
346
|
output_buffer.should_not have_tag('form > fieldset.inputs > ol')
|
347
347
|
end
|
348
|
-
|
348
|
+
|
349
349
|
it 'should render a div item in the ol for each column and reflection' do
|
350
350
|
# Remove the :has_many macro and :created_at column
|
351
351
|
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
352
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
352
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group', :count => count)
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
it 'should render a string list item for title' do
|
356
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
356
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.string-wrapper')
|
357
357
|
end
|
358
358
|
|
359
359
|
it 'should render a text list item for body' do
|
360
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
360
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.text-wrapper')
|
361
361
|
end
|
362
|
-
|
362
|
+
|
363
363
|
it 'should render a select list item for author_id' do
|
364
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
364
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.select-wrapper', :count => 1)
|
365
365
|
end
|
366
|
-
|
366
|
+
|
367
367
|
it 'should not render timestamps inputs by default' do
|
368
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > div.
|
368
|
+
output_buffer.should_not have_tag('form > fieldset.inputs > div.control-group.datetime-wrapper')
|
369
369
|
end
|
370
|
-
|
370
|
+
|
371
371
|
context "with a polymorphic association" do
|
372
|
-
|
373
|
-
before do
|
372
|
+
|
373
|
+
before do
|
374
374
|
@new_post.stub!(:commentable)
|
375
|
-
@new_post.class.stub!(:reflections).and_return({
|
375
|
+
@new_post.class.stub!(:reflections).and_return({
|
376
376
|
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
377
377
|
})
|
378
378
|
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
|
379
379
|
mock('column', :type => :integer)
|
380
380
|
)
|
381
381
|
end
|
382
|
-
|
382
|
+
|
383
383
|
it 'should not render an input for the polymorphic association (the collection class cannot be guessed)' do
|
384
384
|
concat(semantic_form_for(@new_post) do |builder|
|
385
385
|
concat(builder.inputs)
|
386
386
|
end)
|
387
387
|
output_buffer.should_not have_tag('li#post_commentable_input')
|
388
388
|
end
|
389
|
-
|
389
|
+
|
390
390
|
end
|
391
391
|
end
|
392
|
-
|
392
|
+
|
393
393
|
describe 'with column names as args (short hand forms syntax)' do
|
394
394
|
describe 'and an object is given' do
|
395
395
|
it 'should render a form with a fieldset containing two list items' do
|
396
396
|
concat(semantic_form_for(@new_post) do |builder|
|
397
397
|
concat(builder.inputs(:title, :body))
|
398
398
|
end)
|
399
|
-
|
400
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
401
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
402
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
399
|
+
|
400
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group', :count => 2)
|
401
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.string-wrapper')
|
402
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.text-wrapper')
|
403
403
|
end
|
404
404
|
end
|
405
|
-
|
405
|
+
|
406
406
|
describe 'and no object is given' do
|
407
407
|
it 'should render a form with a fieldset containing two list items' do
|
408
408
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
409
409
|
concat(builder.inputs(:title, :body))
|
410
410
|
end)
|
411
|
-
|
412
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
411
|
+
|
412
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group.string-wrapper', :count => 2)
|
413
413
|
end
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
context "with a polymorphic association" do
|
417
|
-
|
417
|
+
|
418
418
|
it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
|
419
419
|
@new_post.stub!(:commentable)
|
420
|
-
@new_post.class.stub!(:reflections).and_return({
|
420
|
+
@new_post.class.stub!(:reflections).and_return({
|
421
421
|
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
422
422
|
})
|
423
423
|
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
|
@@ -426,18 +426,18 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
426
426
|
@new_post.class.stub!(:reflect_on_association).with(:commentable).and_return(
|
427
427
|
mock('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
|
428
428
|
)
|
429
|
-
|
430
|
-
expect {
|
429
|
+
|
430
|
+
expect {
|
431
431
|
concat(semantic_form_for(@new_post) do |builder|
|
432
432
|
concat(builder.inputs :commentable)
|
433
433
|
end)
|
434
434
|
}.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
435
435
|
end
|
436
|
-
|
436
|
+
|
437
437
|
end
|
438
|
-
|
438
|
+
|
439
439
|
end
|
440
|
-
|
440
|
+
|
441
441
|
describe 'when a :for option is provided' do
|
442
442
|
describe 'and an object is given' do
|
443
443
|
it 'should render nested inputs' do
|
@@ -445,12 +445,12 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
445
445
|
concat(semantic_form_for(@new_post) do |builder|
|
446
446
|
concat(builder.inputs(:login, :for => @bob))
|
447
447
|
end)
|
448
|
-
|
448
|
+
|
449
449
|
output_buffer.should have_tag("form fieldset.inputs #post_author_login")
|
450
450
|
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
451
451
|
end
|
452
452
|
end
|
453
|
-
|
453
|
+
|
454
454
|
describe 'and no object is given' do
|
455
455
|
it 'should render nested inputs' do
|
456
456
|
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
@@ -461,7 +461,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
461
461
|
end
|
462
462
|
end
|
463
463
|
end
|
464
|
-
|
464
|
+
|
465
465
|
describe 'with column names and an options hash as args' do
|
466
466
|
before do
|
467
467
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -471,25 +471,25 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
471
471
|
concat(builder.inputs(@legend_text_using_arg, :title, :body, :id => "my-id-2"))
|
472
472
|
end)
|
473
473
|
end
|
474
|
-
|
474
|
+
|
475
475
|
it 'should render a form with a fieldset containing two list items' do
|
476
|
-
output_buffer.should have_tag('form > fieldset.inputs > div.
|
476
|
+
output_buffer.should have_tag('form > fieldset.inputs > div.control-group', :count => 4)
|
477
477
|
end
|
478
|
-
|
478
|
+
|
479
479
|
it 'should pass the options down to the fieldset' do
|
480
480
|
output_buffer.should have_tag('form > fieldset#my-id.inputs')
|
481
481
|
end
|
482
|
-
|
482
|
+
|
483
483
|
it 'should use the special :name option as a text for the legend tag' do
|
484
484
|
output_buffer.should have_tag('form > fieldset#my-id.inputs > legend', /^#{@legend_text_using_option}$/)
|
485
485
|
output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
|
486
486
|
end
|
487
487
|
end
|
488
|
-
|
488
|
+
|
489
489
|
end
|
490
|
-
|
490
|
+
|
491
491
|
describe 'nesting' do
|
492
|
-
|
492
|
+
|
493
493
|
context "when not nested" do
|
494
494
|
it "should not wrap the inputs in an li block" do
|
495
495
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -499,7 +499,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
499
499
|
output_buffer.should_not have_tag('form > li')
|
500
500
|
end
|
501
501
|
end
|
502
|
-
|
502
|
+
|
503
503
|
context "when nested (with block)" do
|
504
504
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
505
505
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -511,7 +511,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
511
511
|
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
512
512
|
end
|
513
513
|
end
|
514
|
-
|
514
|
+
|
515
515
|
context "when nested (with block and :for)" do
|
516
516
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
517
517
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -523,7 +523,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
523
523
|
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
524
524
|
end
|
525
525
|
end
|
526
|
-
|
526
|
+
|
527
527
|
context "when nested (without block)" do
|
528
528
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
529
529
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -534,7 +534,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
534
534
|
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
535
535
|
end
|
536
536
|
end
|
537
|
-
|
537
|
+
|
538
538
|
context "when nested (without block, with :for)" do
|
539
539
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
540
540
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -545,7 +545,7 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
545
545
|
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
546
546
|
end
|
547
547
|
end
|
548
|
-
|
548
|
+
|
549
549
|
context "when double nested" do
|
550
550
|
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
551
551
|
concat(semantic_form_for(@new_post) do |builder|
|
@@ -559,7 +559,21 @@ describe 'Formtastic::FormBuilder#inputs' do
|
|
559
559
|
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs > fieldset.inputs')
|
560
560
|
end
|
561
561
|
end
|
562
|
-
|
562
|
+
|
563
|
+
context "when several are nested" do
|
564
|
+
it "should wrap each of the nested inputs in an li block to maintain HTML validity" do
|
565
|
+
concat(semantic_form_for(@new_post) do |builder|
|
566
|
+
concat(builder.inputs do
|
567
|
+
concat(builder.inputs do
|
568
|
+
end)
|
569
|
+
concat(builder.inputs do
|
570
|
+
end)
|
571
|
+
end)
|
572
|
+
end)
|
573
|
+
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs', :count => 2)
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
563
577
|
end
|
564
578
|
|
565
579
|
describe 'when using MongoMapper associations ' do
|