formtastic-bootstrap 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -2
- data/VERSION +1 -1
- data/vendor/assets/stylesheets/formtastic-bootstrap.css +4 -0
- metadata +51 -154
- data/.rspec +0 -1
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -131
- data/Rakefile +0 -49
- data/formtastic-bootstrap.gemspec +0 -166
- data/lib/action_view/helpers/text_field_date_helper.rb +0 -166
- data/lib/formtastic-bootstrap/actions.rb +0 -10
- data/lib/formtastic-bootstrap/actions/base.rb +0 -22
- data/lib/formtastic-bootstrap/actions/button_action.rb +0 -13
- data/lib/formtastic-bootstrap/actions/input_action.rb +0 -13
- data/lib/formtastic-bootstrap/actions/link_action.rb +0 -12
- data/lib/formtastic-bootstrap/engine.rb +0 -4
- data/lib/formtastic-bootstrap/form_builder.rb +0 -40
- data/lib/formtastic-bootstrap/helpers.rb +0 -17
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +0 -12
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +0 -24
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +0 -35
- data/lib/formtastic-bootstrap/helpers/input_helper.rb +0 -12
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -34
- data/lib/formtastic-bootstrap/inputs.rb +0 -36
- data/lib/formtastic-bootstrap/inputs/base.rb +0 -45
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +0 -20
- data/lib/formtastic-bootstrap/inputs/base/collections.rb +0 -9
- data/lib/formtastic-bootstrap/inputs/base/errors.rb +0 -48
- data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +0 -9
- data/lib/formtastic-bootstrap/inputs/base/hints.rb +0 -27
- data/lib/formtastic-bootstrap/inputs/base/html.rb +0 -21
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +0 -29
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +0 -9
- data/lib/formtastic-bootstrap/inputs/base/stringish.rb +0 -17
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +0 -55
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +0 -55
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +0 -29
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +0 -40
- data/lib/formtastic-bootstrap/inputs/date_input.rb +0 -10
- data/lib/formtastic-bootstrap/inputs/date_select_input.rb +0 -8
- data/lib/formtastic-bootstrap/inputs/datetime_input.rb +0 -10
- data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +0 -8
- data/lib/formtastic-bootstrap/inputs/email_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/file_input.rb +0 -14
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +0 -12
- data/lib/formtastic-bootstrap/inputs/number_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/password_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/phone_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +0 -46
- data/lib/formtastic-bootstrap/inputs/range_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/search_input.rb +0 -15
- data/lib/formtastic-bootstrap/inputs/select_input.rb +0 -16
- data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -8
- data/lib/formtastic-bootstrap/inputs/text_input.rb +0 -14
- data/lib/formtastic-bootstrap/inputs/time_input.rb +0 -10
- data/lib/formtastic-bootstrap/inputs/time_select_input.rb +0 -8
- data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +0 -14
- data/lib/formtastic-bootstrap/inputs/url_input.rb +0 -14
- data/spec/actions/button_action_spec.rb +0 -63
- data/spec/actions/input_action_spec.rb +0 -59
- data/spec/actions/link_action_spec.rb +0 -92
- data/spec/builder/semantic_fields_for_spec.rb +0 -130
- data/spec/helpers/action_helper_spec.rb +0 -368
- data/spec/helpers/actions_helper_spec.rb +0 -147
- data/spec/helpers/input_helper_spec.rb +0 -935
- data/spec/helpers/inputs_helper_spec.rb +0 -636
- data/spec/inputs/boolean_input_spec.rb +0 -226
- data/spec/inputs/check_boxes_input_spec.rb +0 -454
- data/spec/inputs/date_select_input_spec.rb +0 -164
- data/spec/inputs/datetime_select_input_spec.rb +0 -112
- data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +0 -48
- data/spec/inputs/email_input_spec.rb +0 -86
- data/spec/inputs/file_input_spec.rb +0 -90
- data/spec/inputs/hidden_input_spec.rb +0 -153
- data/spec/inputs/number_input_spec.rb +0 -816
- data/spec/inputs/password_input_spec.rb +0 -100
- data/spec/inputs/phone_input_spec.rb +0 -86
- data/spec/inputs/radio_input_spec.rb +0 -267
- data/spec/inputs/range_input_spec.rb +0 -506
- data/spec/inputs/search_input_spec.rb +0 -85
- data/spec/inputs/select_input_spec.rb +0 -624
- data/spec/inputs/string_input_spec.rb +0 -210
- data/spec/inputs/text_input_spec.rb +0 -188
- data/spec/inputs/time_select_input_spec.rb +0 -191
- data/spec/inputs/time_zone_input_spec.rb +0 -118
- data/spec/inputs/url_input_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -30
- data/spec/support/custom_macros.rb +0 -537
- data/spec/support/fb_custom_macros.rb +0 -23
@@ -1,636 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe 'FormtasticBootstrap::FormBuilder#inputs' do
|
5
|
-
|
6
|
-
include FormtasticSpecHelper
|
7
|
-
|
8
|
-
before do
|
9
|
-
@output_buffer = ''
|
10
|
-
mock_everything
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'with a block (block forms syntax)' do
|
14
|
-
|
15
|
-
describe 'when no options are provided' do
|
16
|
-
before do
|
17
|
-
output_buffer.replace 'before_builder' # clear the output buffer and sets before_builder
|
18
|
-
concat(semantic_form_for(@new_post) do |builder|
|
19
|
-
@inputs_output = builder.inputs do
|
20
|
-
concat('hello')
|
21
|
-
end
|
22
|
-
end)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should output just the content wrapped in inputs, not the whole template' do
|
26
|
-
output_buffer.should =~ /before_builder/
|
27
|
-
@inputs_output.should_not =~ /before_builder/
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should render a fieldset inside the form, with a class of "inputs"' do
|
31
|
-
output_buffer.should have_tag("form fieldset.inputs")
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should not render an ol inside the fieldset' do
|
35
|
-
output_buffer.should_not have_tag("form fieldset.inputs ol")
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should not render the contents of the block inside the ol' do
|
39
|
-
output_buffer.should_not have_tag("form fieldset.inputs ol", /hello/)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should not render a legend inside the fieldset' do
|
43
|
-
output_buffer.should_not have_tag("form fieldset.inputs legend")
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should render a fieldset even if no object is given' do
|
47
|
-
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
48
|
-
@inputs_output = builder.inputs do
|
49
|
-
concat('bye')
|
50
|
-
end
|
51
|
-
end)
|
52
|
-
output_buffer.should have_tag("form fieldset.inputs", /bye/)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'when a :for option is provided' do
|
57
|
-
|
58
|
-
before do
|
59
|
-
@new_post.stub!(:respond_to?).and_return(true, true)
|
60
|
-
@new_post.stub!(:author).and_return(@bob)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should render nested inputs' do
|
64
|
-
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
65
|
-
|
66
|
-
concat(semantic_form_for(@new_post) do |builder|
|
67
|
-
inputs = builder.inputs :for => [:author, @bob] do |bob_builder|
|
68
|
-
concat(bob_builder.input(:login))
|
69
|
-
end
|
70
|
-
concat(inputs)
|
71
|
-
end)
|
72
|
-
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
73
|
-
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should concat rendered nested inputs to the template' do
|
77
|
-
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
78
|
-
|
79
|
-
concat(semantic_form_for(@new_post) do |builder|
|
80
|
-
builder.inputs :for => [:author, @bob] do |bob_builder|
|
81
|
-
concat(bob_builder.input(:login))
|
82
|
-
end
|
83
|
-
end)
|
84
|
-
|
85
|
-
output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
|
86
|
-
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "as a symbol representing the association name" do
|
91
|
-
|
92
|
-
it 'should nest the inputs with an _attributes suffix on the association name' do
|
93
|
-
concat(semantic_form_for(@new_post) do |post|
|
94
|
-
inputs = post.inputs :for => :author do |author|
|
95
|
-
concat(author.input(:login))
|
96
|
-
end
|
97
|
-
concat(inputs)
|
98
|
-
end)
|
99
|
-
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "as a symbol representing a has_many association name" do
|
105
|
-
before do
|
106
|
-
@new_post.stub!(:authors).and_return([@bob, @fred])
|
107
|
-
@new_post.stub!(:authors_attributes=)
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should nest the inputs with a fieldset, legend and :name input for each item' do
|
111
|
-
concat(semantic_form_for(@new_post) do |post|
|
112
|
-
post.inputs :for => :authors, :name => '%i' do |author|
|
113
|
-
concat(author.input(:login))
|
114
|
-
end
|
115
|
-
end)
|
116
|
-
|
117
|
-
output_buffer.should have_tag("form fieldset.inputs", :count => 2)
|
118
|
-
output_buffer.should have_tag("form fieldset.inputs legend", :count => 2)
|
119
|
-
output_buffer.should have_tag("form fieldset.inputs legend", "1", :count => 1)
|
120
|
-
output_buffer.should have_tag("form fieldset.inputs legend", "2")
|
121
|
-
output_buffer.should have_tag("form input[@name='post[authors_attributes][0][login]']")
|
122
|
-
output_buffer.should have_tag("form input[@name='post[authors_attributes][1][login]']")
|
123
|
-
output_buffer.should_not have_tag('form fieldset[@name]')
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'should include an indexed :label input for each item' do
|
127
|
-
concat(semantic_form_for(@new_post) do |post|
|
128
|
-
post.inputs :for => :authors do |author, index|
|
129
|
-
concat(author.input(:login, :label => "#{index}", :required => false))
|
130
|
-
end
|
131
|
-
end)
|
132
|
-
|
133
|
-
output_buffer.should have_tag("form fieldset.inputs label", "1", :count => 1)
|
134
|
-
output_buffer.should have_tag("form fieldset.inputs label", "2", :count => 1)
|
135
|
-
output_buffer.should_not have_tag('form fieldset legend')
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'as an array containing the a symbole for the association name and the associated object' do
|
140
|
-
|
141
|
-
it 'should nest the inputs with an _attributes suffix on the association name' do
|
142
|
-
concat(semantic_form_for(@new_post) do |post|
|
143
|
-
inputs = post.inputs :for => [:author, @new_post.author] do |author|
|
144
|
-
concat(author.input(:login))
|
145
|
-
end
|
146
|
-
concat(inputs)
|
147
|
-
end)
|
148
|
-
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
describe 'as an associated object' do
|
154
|
-
|
155
|
-
it 'should not nest the inputs with an _attributes suffix' do
|
156
|
-
concat(semantic_form_for(@new_post) do |post|
|
157
|
-
inputs = post.inputs :for => @new_post.author do |author|
|
158
|
-
concat(author.input(:login))
|
159
|
-
end
|
160
|
-
concat(inputs)
|
161
|
-
end)
|
162
|
-
output_buffer.should have_tag("form input[@name='post[author][login]']")
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should raise an error if :for and block with no argument is given' do
|
168
|
-
semantic_form_for(@new_post) do |builder|
|
169
|
-
proc {
|
170
|
-
builder.inputs(:for => [:author, @bob]) do
|
171
|
-
#
|
172
|
-
end
|
173
|
-
}.should raise_error(ArgumentError, 'You gave :for option with a block to inputs method, ' <<
|
174
|
-
'but the block does not accept any argument.')
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should pass options down to semantic_fields_for' do
|
179
|
-
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
180
|
-
|
181
|
-
concat(semantic_form_for(@new_post) do |builder|
|
182
|
-
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
183
|
-
concat(bob_builder.input(:login))
|
184
|
-
end
|
185
|
-
concat(inputs)
|
186
|
-
end)
|
187
|
-
|
188
|
-
output_buffer.should have_tag('form fieldset #post_author_attributes_10_login')
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'should not add builder as a fieldset attribute tag' do
|
192
|
-
concat(semantic_form_for(@new_post) do |builder|
|
193
|
-
inputs = builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
|
194
|
-
concat('input')
|
195
|
-
end
|
196
|
-
concat(inputs)
|
197
|
-
end)
|
198
|
-
|
199
|
-
output_buffer.should_not have_tag('fieldset[@builder="Formtastic::Helpers::FormHelper"]')
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'should send parent_builder as an option to allow child index interpolation for legends' do
|
203
|
-
concat(semantic_form_for(@new_post) do |builder|
|
204
|
-
builder.instance_variable_set('@nested_child_index', 0)
|
205
|
-
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
206
|
-
concat('input')
|
207
|
-
end
|
208
|
-
concat(inputs)
|
209
|
-
end)
|
210
|
-
|
211
|
-
output_buffer.should have_tag('fieldset legend', 'Author #1')
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'should also provide child index interpolation for legends when nested child index is a hash' do
|
215
|
-
concat(semantic_form_for(@new_post) do |builder|
|
216
|
-
builder.instance_variable_set('@nested_child_index', :author => 10)
|
217
|
-
inputs = builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
|
218
|
-
concat('input')
|
219
|
-
end
|
220
|
-
concat(inputs)
|
221
|
-
end)
|
222
|
-
|
223
|
-
output_buffer.should have_tag('fieldset legend', 'Author #11')
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'should send parent_builder as an option to allow child index interpolation for labels' do
|
227
|
-
concat(semantic_form_for(@new_post) do |builder|
|
228
|
-
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 0)
|
229
|
-
inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
|
230
|
-
concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
|
231
|
-
end
|
232
|
-
concat(inputs)
|
233
|
-
end)
|
234
|
-
|
235
|
-
output_buffer.should have_tag('fieldset label', 'Author #1')
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'should also provide child index interpolation for labels when nested child index is a hash' do
|
239
|
-
concat(semantic_form_for(@new_post) do |builder|
|
240
|
-
builder.instance_variable_set('@nested_child_index', 'post[author_attributes]' => 10)
|
241
|
-
inputs = builder.inputs :for => [:author, @bob] do |bob_builder, index|
|
242
|
-
concat(bob_builder.input(:name, :label => "Author ##{index}", :required => false))
|
243
|
-
end
|
244
|
-
concat(inputs)
|
245
|
-
end)
|
246
|
-
|
247
|
-
output_buffer.should have_tag('fieldset label', 'Author #11')
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
describe 'when a :name or :title option is provided' do
|
252
|
-
describe 'and is a string' do
|
253
|
-
before do
|
254
|
-
@legend_text = "Advanced options"
|
255
|
-
@legend_text_using_name = "Advanced options 2"
|
256
|
-
@legend_text_using_title = "Advanced options 3"
|
257
|
-
@nested_forms_legend_text = "This is a nested form title"
|
258
|
-
concat(semantic_form_for(@new_post) do |builder|
|
259
|
-
inputs = builder.inputs @legend_text do
|
260
|
-
end
|
261
|
-
concat(inputs)
|
262
|
-
inputs = builder.inputs :name => @legend_text_using_name do
|
263
|
-
end
|
264
|
-
concat(inputs)
|
265
|
-
inputs = builder.inputs :title => @legend_text_using_title do
|
266
|
-
end
|
267
|
-
concat(inputs)
|
268
|
-
inputs = builder.inputs @nested_forms_legend_text, :for => :authors do |nf|
|
269
|
-
end
|
270
|
-
concat(inputs)
|
271
|
-
end)
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'should render a fieldset with a legend inside the form' do
|
275
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text}$/)
|
276
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_name}$/)
|
277
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_title}$/)
|
278
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@nested_forms_legend_text}$/)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe 'and is a symbol' do
|
283
|
-
before do
|
284
|
-
@localized_legend_text = "Localized advanced options"
|
285
|
-
@localized_legend_text_using_name = "Localized advanced options 2"
|
286
|
-
@localized_legend_text_using_title = "Localized advanced options 3"
|
287
|
-
@localized_nested_forms_legend_text = "This is a localized nested form title"
|
288
|
-
::I18n.backend.store_translations :en, :formtastic => {
|
289
|
-
:titles => {
|
290
|
-
:post => {
|
291
|
-
:advanced_options => @localized_legend_text,
|
292
|
-
:advanced_options_using_name => @localized_legend_text_using_name,
|
293
|
-
:advanced_options_using_title => @localized_legend_text_using_title,
|
294
|
-
:nested_forms_title => @localized_nested_forms_legend_text
|
295
|
-
}
|
296
|
-
}
|
297
|
-
}
|
298
|
-
concat(semantic_form_for(@new_post) do |builder|
|
299
|
-
inputs = builder.inputs :advanced_options do
|
300
|
-
end
|
301
|
-
concat(inputs)
|
302
|
-
inputs =builder.inputs :name => :advanced_options_using_name do
|
303
|
-
end
|
304
|
-
concat(inputs)
|
305
|
-
inputs = builder.inputs :title => :advanced_options_using_title do
|
306
|
-
end
|
307
|
-
concat(inputs)
|
308
|
-
inputs = builder.inputs :nested_forms_title, :for => :authors do |nf|
|
309
|
-
end
|
310
|
-
concat(inputs)
|
311
|
-
end)
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'should render a fieldset with a localized legend inside the form' do
|
315
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text}$/)
|
316
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_name}$/)
|
317
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_title}$/)
|
318
|
-
output_buffer.should have_tag("form fieldset legend", /^#{@localized_nested_forms_legend_text}$/)
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
describe 'when other options are provided' do
|
324
|
-
before do
|
325
|
-
@id_option = 'advanced'
|
326
|
-
@class_option = 'wide'
|
327
|
-
|
328
|
-
concat(semantic_form_for(@new_post) do |builder|
|
329
|
-
builder.inputs :id => @id_option, :class => @class_option do
|
330
|
-
end
|
331
|
-
end)
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'should pass the options into the fieldset tag as attributes' do
|
335
|
-
output_buffer.should have_tag("form fieldset##{@id_option}")
|
336
|
-
output_buffer.should have_tag("form fieldset.#{@class_option}")
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
end
|
341
|
-
|
342
|
-
describe 'without a block' do
|
343
|
-
|
344
|
-
before do
|
345
|
-
::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to),
|
346
|
-
:comments => mock('reflection', :options => {}, :macro => :has_many) })
|
347
|
-
::Author.stub!(:find).and_return([@fred, @bob])
|
348
|
-
|
349
|
-
@new_post.stub!(:title)
|
350
|
-
@new_post.stub!(:body)
|
351
|
-
@new_post.stub!(:author_id)
|
352
|
-
|
353
|
-
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
|
354
|
-
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
|
355
|
-
@new_post.stub!(:column_for_attribute).with(:created_at).and_return(mock('column', :type => :datetime))
|
356
|
-
@new_post.stub!(:column_for_attribute).with(:author).and_return(nil)
|
357
|
-
end
|
358
|
-
|
359
|
-
describe 'with no args (quick forms syntax)' do
|
360
|
-
before do
|
361
|
-
concat(semantic_form_for(@new_post) do |builder|
|
362
|
-
concat(builder.inputs)
|
363
|
-
end)
|
364
|
-
end
|
365
|
-
|
366
|
-
it 'should render a form' do
|
367
|
-
output_buffer.should have_tag('form')
|
368
|
-
end
|
369
|
-
|
370
|
-
it 'should render a fieldset inside the form' do
|
371
|
-
output_buffer.should have_tag('form > fieldset.inputs')
|
372
|
-
end
|
373
|
-
|
374
|
-
it 'should not render a legend in the fieldset' do
|
375
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > legend')
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'should not render an ol in the fieldset' do
|
379
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol')
|
380
|
-
end
|
381
|
-
|
382
|
-
it 'should not render a list item in the ol for each column and reflection' do
|
383
|
-
# Remove the :has_many macro and :created_at column
|
384
|
-
count = ::Post.content_columns.size + ::Post.reflections.size - 2
|
385
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => count)
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'should not render a string list item for title' do
|
389
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
|
390
|
-
end
|
391
|
-
|
392
|
-
it 'should not render a text list item for body' do
|
393
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.text')
|
394
|
-
end
|
395
|
-
|
396
|
-
it 'should not render a select list item for author_id' do
|
397
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
|
398
|
-
end
|
399
|
-
|
400
|
-
it 'should not render timestamps inputs by default' do
|
401
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.datetime')
|
402
|
-
end
|
403
|
-
|
404
|
-
context "with a polymorphic association" do
|
405
|
-
|
406
|
-
before do
|
407
|
-
@new_post.stub!(:commentable)
|
408
|
-
@new_post.class.stub!(:reflections).and_return({
|
409
|
-
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
410
|
-
})
|
411
|
-
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
|
412
|
-
mock('column', :type => :integer)
|
413
|
-
)
|
414
|
-
end
|
415
|
-
|
416
|
-
it 'should not render an input for the polymorphic association (the collection class cannot be guessed)' do
|
417
|
-
concat(semantic_form_for(@new_post) do |builder|
|
418
|
-
concat(builder.inputs)
|
419
|
-
end)
|
420
|
-
output_buffer.should_not have_tag('li#post_commentable_input')
|
421
|
-
end
|
422
|
-
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
describe 'with column names as args (short hand forms syntax)' do
|
427
|
-
describe 'and an object is given' do
|
428
|
-
it 'should render a form with a fieldset containing two list items' do
|
429
|
-
concat(semantic_form_for(@new_post) do |builder|
|
430
|
-
concat(builder.inputs(:title, :body))
|
431
|
-
end)
|
432
|
-
|
433
|
-
output_buffer.should have_tag('form > fieldset.inputs input', :count => 1)
|
434
|
-
output_buffer.should have_tag('form > fieldset.inputs textarea', :count => 1)
|
435
|
-
|
436
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => 2)
|
437
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
|
438
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.text')
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe 'and no object is given' do
|
443
|
-
it 'should render a form with a fieldset containing two list items' do
|
444
|
-
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
445
|
-
concat(builder.inputs(:title, :body))
|
446
|
-
end)
|
447
|
-
|
448
|
-
output_buffer.should have_tag('form > fieldset.inputs input', :count => 2)
|
449
|
-
|
450
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.string')
|
451
|
-
end
|
452
|
-
end
|
453
|
-
|
454
|
-
context "with a polymorphic association" do
|
455
|
-
|
456
|
-
it 'should raise an error for polymorphic associations (the collection class cannot be guessed)' do
|
457
|
-
@new_post.stub!(:commentable)
|
458
|
-
@new_post.class.stub!(:reflections).and_return({
|
459
|
-
:commentable => mock('macro_reflection', :options => { :polymorphic => true }, :macro => :belongs_to)
|
460
|
-
})
|
461
|
-
@new_post.stub!(:column_for_attribute).with(:commentable).and_return(
|
462
|
-
mock('column', :type => :integer)
|
463
|
-
)
|
464
|
-
@new_post.class.stub!(:reflect_on_association).with(:commentable).and_return(
|
465
|
-
mock('reflection', :macro => :belongs_to, :options => { :polymorphic => true })
|
466
|
-
)
|
467
|
-
|
468
|
-
expect {
|
469
|
-
concat(semantic_form_for(@new_post) do |builder|
|
470
|
-
concat(builder.inputs :commentable)
|
471
|
-
end)
|
472
|
-
}.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
473
|
-
end
|
474
|
-
|
475
|
-
end
|
476
|
-
|
477
|
-
end
|
478
|
-
|
479
|
-
describe 'when a :for option is provided' do
|
480
|
-
describe 'and an object is given' do
|
481
|
-
it 'should render nested inputs' do
|
482
|
-
@bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
|
483
|
-
concat(semantic_form_for(@new_post) do |builder|
|
484
|
-
concat(builder.inputs(:login, :for => @bob))
|
485
|
-
end)
|
486
|
-
|
487
|
-
output_buffer.should have_tag("form fieldset.inputs #post_author_login")
|
488
|
-
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
describe 'and no object is given' do
|
493
|
-
it 'should render nested inputs' do
|
494
|
-
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
495
|
-
concat(builder.inputs(:login, :for => @bob))
|
496
|
-
end)
|
497
|
-
output_buffer.should have_tag("form fieldset.inputs #project_author_login")
|
498
|
-
output_buffer.should_not have_tag("form fieldset.inputs #project_login")
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
describe 'with column names and an options hash as args' do
|
504
|
-
before do
|
505
|
-
concat(semantic_form_for(@new_post) do |builder|
|
506
|
-
@legend_text_using_option = "Legendary Legend Text"
|
507
|
-
@legend_text_using_arg = "Legendary Legend Text 2"
|
508
|
-
concat(builder.inputs(:title, :body, :name => @legend_text_using_option, :id => "my-id"))
|
509
|
-
concat(builder.inputs(@legend_text_using_arg, :title, :body, :id => "my-id-2"))
|
510
|
-
end)
|
511
|
-
end
|
512
|
-
|
513
|
-
it 'should not render a form with a fieldset containing two list items' do
|
514
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li', :count => 4)
|
515
|
-
output_buffer.should_not have_tag('form > fieldset.inputs input', :count => 4)
|
516
|
-
end
|
517
|
-
|
518
|
-
it 'should pass the options down to the fieldset' do
|
519
|
-
output_buffer.should have_tag('form > fieldset#my-id.inputs')
|
520
|
-
end
|
521
|
-
|
522
|
-
it 'should use the special :name option as a text for the legend tag' do
|
523
|
-
output_buffer.should have_tag('form > fieldset#my-id.inputs > legend', /^#{@legend_text_using_option}$/)
|
524
|
-
output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
end
|
529
|
-
|
530
|
-
describe 'nesting' do
|
531
|
-
|
532
|
-
context "when not nested" do
|
533
|
-
it "should not wrap the inputs in an li block" do
|
534
|
-
concat(semantic_form_for(@new_post) do |builder|
|
535
|
-
concat(builder.inputs do
|
536
|
-
end)
|
537
|
-
end)
|
538
|
-
output_buffer.should_not have_tag('form > li')
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
context "when nested (with block)" do
|
543
|
-
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
544
|
-
concat(semantic_form_for(@new_post) do |builder|
|
545
|
-
concat(builder.inputs do
|
546
|
-
concat(builder.inputs do
|
547
|
-
end)
|
548
|
-
end)
|
549
|
-
end)
|
550
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
551
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
context "when nested (with block and :for)" do
|
556
|
-
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
557
|
-
concat(semantic_form_for(@new_post) do |builder|
|
558
|
-
concat(builder.inputs do
|
559
|
-
concat(builder.inputs(:for => :author) do |author_builder|
|
560
|
-
end)
|
561
|
-
end)
|
562
|
-
end)
|
563
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
564
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
context "when nested (without block)" do
|
569
|
-
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
570
|
-
concat(semantic_form_for(@new_post) do |builder|
|
571
|
-
concat(builder.inputs do
|
572
|
-
concat(builder.inputs(:title))
|
573
|
-
end)
|
574
|
-
end)
|
575
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
576
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
context "when nested (without block, with :for)" do
|
581
|
-
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
582
|
-
concat(semantic_form_for(@new_post) do |builder|
|
583
|
-
concat(builder.inputs do
|
584
|
-
concat(builder.inputs(:name, :for => :author))
|
585
|
-
end)
|
586
|
-
end)
|
587
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
588
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs')
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
context "when double nested" do
|
593
|
-
it "should wrap the nested inputs in an li block to maintain HTML validity" do
|
594
|
-
concat(semantic_form_for(@new_post) do |builder|
|
595
|
-
concat(builder.inputs do
|
596
|
-
concat(builder.inputs do
|
597
|
-
concat(builder.inputs do
|
598
|
-
end)
|
599
|
-
end)
|
600
|
-
end)
|
601
|
-
end)
|
602
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
603
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs > fieldset.inputs')
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
context "when several are nested" do
|
608
|
-
it "should wrap each of the nested inputs in an li block to maintain HTML validity" do
|
609
|
-
concat(semantic_form_for(@new_post) do |builder|
|
610
|
-
concat(builder.inputs do
|
611
|
-
concat(builder.inputs do
|
612
|
-
end)
|
613
|
-
concat(builder.inputs do
|
614
|
-
end)
|
615
|
-
end)
|
616
|
-
end)
|
617
|
-
output_buffer.should_not have_tag('form > fieldset.inputs > ol > li > fieldset.inputs > ol')
|
618
|
-
output_buffer.should have_tag('form > fieldset.inputs > fieldset.inputs', :count => 2)
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
end
|
623
|
-
|
624
|
-
describe 'when using MongoMapper associations ' do
|
625
|
-
def generate_form
|
626
|
-
semantic_form_for(@new_mm_post) do |builder|
|
627
|
-
builder.inputs :title, :sub_posts
|
628
|
-
end
|
629
|
-
end
|
630
|
-
it "should throw PolymorphicInputWithoutCollectionError on sub_posts" do
|
631
|
-
::MongoPost.should_receive(:associations).at_least(3).times
|
632
|
-
expect { generate_form }.to raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
633
|
-
end
|
634
|
-
end
|
635
|
-
|
636
|
-
end
|