speedo-formstrap 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +4 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/speedo-formstrap/form_builder.rb +7 -5
- data/lib/speedo-formstrap/helpers.rb +3 -1
- data/lib/speedo-formstrap/helpers/buttons_helper.rb +13 -9
- data/lib/speedo-formstrap/helpers/fieldset_wrapper.rb +11 -6
- data/lib/speedo-formstrap/helpers/inputs_helper.rb +4 -4
- data/lib/speedo-formstrap/inputs/base.rb +2 -1
- data/lib/speedo-formstrap/inputs/base/choices.rb +12 -23
- data/lib/speedo-formstrap/inputs/base/labelling.rb +16 -6
- data/lib/speedo-formstrap/inputs/base/timeish.rb +5 -12
- data/lib/speedo-formstrap/inputs/base/wrapping.rb +32 -14
- data/lib/speedo-formstrap/inputs/number_input.rb +2 -2
- data/lib/speedo-formstrap/inputs/radio_input.rb +13 -12
- data/lib/speedo-formstrap/inputs/range_input.rb +2 -2
- data/spec/builder/semantic_fields_for_spec.rb +16 -16
- data/spec/helpers/buttons_helper_spec.rb +56 -46
- data/spec/helpers/input_helper_spec.rb +209 -209
- data/spec/helpers/inputs_helper_spec.rb +117 -103
- data/spec/inputs/boolean_input_spec.rb +74 -46
- data/spec/inputs/check_boxes_input_spec.rb +110 -82
- data/spec/inputs/date_input_spec.rb +81 -15
- data/spec/inputs/datetime_input_spec.rb +13 -13
- data/spec/inputs/email_input_spec.rb +34 -6
- data/spec/inputs/file_input_spec.rb +34 -6
- data/spec/inputs/hidden_input_spec.rb +41 -13
- data/spec/inputs/number_input_spec.rb +127 -97
- data/spec/inputs/password_input_spec.rb +34 -6
- data/spec/inputs/phone_input_spec.rb +34 -6
- data/spec/inputs/radio_input_spec.rb +73 -45
- data/spec/inputs/range_input_spec.rb +94 -66
- data/spec/inputs/search_input_spec.rb +33 -6
- data/spec/inputs/select_input_spec.rb +124 -78
- data/spec/inputs/string_input_spec.rb +67 -22
- data/spec/inputs/text_input_spec.rb +42 -15
- data/spec/inputs/time_input_spec.rb +23 -23
- data/spec/inputs/time_zone_input_spec.rb +20 -20
- data/spec/inputs/url_input_spec.rb +34 -6
- data/spec/support/custom_macros.rb +67 -196
- data/spec/support/formtastic_spec_helper.rb +22 -6
- data/speedo-formstrap.gemspec +2 -2
- metadata +17 -17
@@ -8,7 +8,7 @@ describe 'search input' do
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
Formtastic::Helpers::FormHelper.builder =
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "when object is provided" do
|
@@ -18,8 +18,8 @@ describe 'search input' do
|
|
18
18
|
end)
|
19
19
|
end
|
20
20
|
|
21
|
-
it_should_have_input_wrapper_with_class(
|
22
|
-
it_should_have_input_wrapper_with_class(
|
21
|
+
it_should_have_input_wrapper_with_class('search-wrapper')
|
22
|
+
it_should_have_input_wrapper_with_class("control-group")
|
23
23
|
it_should_have_input_wrapper_with_class(:stringish)
|
24
24
|
it_should_have_input_class_in_the_right_place
|
25
25
|
it_should_have_input_wrapper_with_id("post_search_input")
|
@@ -43,10 +43,37 @@ describe 'search input' do
|
|
43
43
|
it_should_have_label_and_input_with_id("context2_post_search")
|
44
44
|
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
describe "when index is provided" do
|
48
|
+
|
49
|
+
before do
|
50
|
+
@output_buffer = ''
|
51
|
+
mock_everything
|
52
|
+
|
53
|
+
concat(semantic_form_for(@new_post) do |builder|
|
54
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
55
|
+
concat(author.input(:name, :as => :search))
|
56
|
+
end)
|
57
|
+
end)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should index the id of the wrapper' do
|
61
|
+
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should index the id of the select tag' do
|
65
|
+
output_buffer.should have_tag("input#post_author_attributes_3_name")
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should index the name of the select tag' do
|
69
|
+
output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
47
74
|
describe "when required" do
|
48
75
|
it "should add the required attribute to the input's html options" do
|
49
|
-
with_config :use_required_attribute, true do
|
76
|
+
with_config :use_required_attribute, true do
|
50
77
|
concat(semantic_form_for(@new_post) do |builder|
|
51
78
|
concat(builder.input(:title, :as => :search, :required => true))
|
52
79
|
end)
|
@@ -54,6 +81,6 @@ describe 'search input' do
|
|
54
81
|
end
|
55
82
|
end
|
56
83
|
end
|
57
|
-
|
84
|
+
|
58
85
|
end
|
59
86
|
|
@@ -8,7 +8,7 @@ describe 'select input' do
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
Formtastic::Helpers::FormHelper.builder =
|
11
|
+
Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'explicit values' do
|
@@ -24,10 +24,10 @@ describe 'select input' do
|
|
24
24
|
|
25
25
|
it 'should have a option for each key and/or value' do
|
26
26
|
@array_with_values.each do |v|
|
27
|
-
output_buffer.should have_tag("form div.
|
27
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
|
28
28
|
end
|
29
29
|
@array_with_keys_and_values.each do |v|
|
30
|
-
output_buffer.should have_tag("form div.
|
30
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v.second}']", /^#{v.first}$/)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -41,9 +41,9 @@ describe 'select input' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should draw select options' do
|
44
|
-
output_buffer.should have_tag('form div.
|
45
|
-
output_buffer.should have_tag('form div.
|
46
|
-
output_buffer.should_not have_tag('form div.
|
44
|
+
output_buffer.should have_tag('form div.control-group div.controls select')
|
45
|
+
output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
|
46
|
+
output_buffer.should_not have_tag('form div.control-group div.controls select#post_mongoid_reviewer_id')
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -57,7 +57,7 @@ describe 'select input' do
|
|
57
57
|
|
58
58
|
it 'should have an option for each value' do
|
59
59
|
@range_with_values.each do |v|
|
60
|
-
output_buffer.should have_tag("form div.
|
60
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -72,10 +72,20 @@ describe 'select input' do
|
|
72
72
|
|
73
73
|
it 'should render select options using provided HTML string' do
|
74
74
|
2.times do |v|
|
75
|
-
output_buffer.should have_tag("form div.
|
75
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
describe 'using a nil name' do
|
81
|
+
before do
|
82
|
+
concat(semantic_form_for(@new_post) do |builder|
|
83
|
+
concat(builder.input(:title, :as => :select, :collection => [], :input_html => {:name => nil}))
|
84
|
+
end)
|
85
|
+
end
|
86
|
+
|
87
|
+
it_should_have_select_with_name("post[title]")
|
88
|
+
end
|
79
89
|
end
|
80
90
|
|
81
91
|
describe 'for boolean columns' do
|
@@ -84,19 +94,20 @@ describe 'select input' do
|
|
84
94
|
# # Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
|
85
95
|
# ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
|
86
96
|
# ::I18n.backend.send(:init_translations)
|
87
|
-
#
|
97
|
+
#
|
88
98
|
# concat(semantic_form_for(@new_post) do |builder|
|
89
99
|
# concat(builder.input(:published, :as => :select))
|
90
100
|
# end)
|
91
101
|
# end
|
92
|
-
#
|
102
|
+
#
|
93
103
|
# after do
|
104
|
+
# ::I18n.load_path = []
|
94
105
|
# ::I18n.backend.store_translations :en, {}
|
95
106
|
# end
|
96
|
-
#
|
107
|
+
#
|
97
108
|
# it 'should render a select with at least options: true/false' do
|
98
|
-
# output_buffer.should have_tag("form div.
|
99
|
-
# output_buffer.should have_tag("form div.
|
109
|
+
# output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /^Yes$/)
|
110
|
+
# output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /^No$/)
|
100
111
|
# end
|
101
112
|
# end
|
102
113
|
|
@@ -115,8 +126,8 @@ describe 'select input' do
|
|
115
126
|
end
|
116
127
|
|
117
128
|
it 'should render a select with at least options: true/false' do
|
118
|
-
output_buffer.should have_tag("form div.
|
119
|
-
output_buffer.should have_tag("form div.
|
129
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
|
130
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /#{@boolean_select_labels[:no]}/)
|
120
131
|
end
|
121
132
|
end
|
122
133
|
end
|
@@ -129,8 +140,8 @@ describe 'select input' do
|
|
129
140
|
end)
|
130
141
|
end
|
131
142
|
|
132
|
-
it_should_have_input_wrapper_with_class("select")
|
133
|
-
it_should_have_input_wrapper_with_class(
|
143
|
+
it_should_have_input_wrapper_with_class("select-wrapper")
|
144
|
+
it_should_have_input_wrapper_with_class("control-group")
|
134
145
|
it_should_have_input_class_in_the_right_place
|
135
146
|
it_should_have_input_wrapper_with_id("post_author_input")
|
136
147
|
it_should_have_label_with_text(/Author/)
|
@@ -140,38 +151,42 @@ describe 'select input' do
|
|
140
151
|
it_should_use_the_collection_when_provided(:select, 'option')
|
141
152
|
|
142
153
|
it 'should have a select inside the wrapper' do
|
143
|
-
output_buffer.should have_tag('form div.
|
144
|
-
output_buffer.should have_tag('form div.
|
145
|
-
output_buffer.should have_tag('form div.
|
154
|
+
output_buffer.should have_tag('form div.control-group div.controls select')
|
155
|
+
output_buffer.should have_tag('form div.control-group div.controls select#post_author_id')
|
156
|
+
output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
|
146
157
|
end
|
147
158
|
|
148
159
|
it 'should have a valid name' do
|
149
|
-
output_buffer.should have_tag("form div.
|
150
|
-
output_buffer.should_not have_tag("form div.
|
151
|
-
output_buffer.should_not have_tag("form div.
|
160
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]']")
|
161
|
+
output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[author_id][]']")
|
162
|
+
output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[reviewer_id][]']")
|
152
163
|
end
|
153
164
|
|
154
165
|
it 'should not create a multi-select' do
|
155
|
-
output_buffer.should_not have_tag('form div.
|
166
|
+
output_buffer.should_not have_tag('form div.control-group div.controls select[@multiple]')
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should not add a hidden input' do
|
170
|
+
output_buffer.should_not have_tag("form div.control-group div.controls input[@type='hidden']")
|
156
171
|
end
|
157
172
|
|
158
173
|
it 'should create a select without size' do
|
159
|
-
output_buffer.should_not have_tag('form div.
|
174
|
+
output_buffer.should_not have_tag('form div.control-group div.controls select[@size]')
|
160
175
|
end
|
161
176
|
|
162
177
|
it 'should have a blank option' do
|
163
|
-
output_buffer.should have_tag("form div.
|
178
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
|
164
179
|
end
|
165
180
|
|
166
181
|
it 'should have a select option for each Author' do
|
167
|
-
output_buffer.should have_tag("form div.
|
182
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
|
168
183
|
::Author.all.each do |author|
|
169
|
-
output_buffer.should have_tag("form div.
|
184
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
|
170
185
|
end
|
171
186
|
end
|
172
187
|
|
173
188
|
it 'should have one option with a "selected" attribute (bob)' do
|
174
|
-
output_buffer.should have_tag("form div.
|
189
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option[@selected]", :count => 1)
|
175
190
|
end
|
176
191
|
|
177
192
|
it 'should not singularize the association name' do
|
@@ -183,7 +198,7 @@ describe 'select input' do
|
|
183
198
|
concat(builder.input(:author_status, :as => :select))
|
184
199
|
end)
|
185
200
|
|
186
|
-
output_buffer.should have_tag('form div.
|
201
|
+
output_buffer.should have_tag('form div.control-group div.controls select#post_author_status_id')
|
187
202
|
end
|
188
203
|
end
|
189
204
|
|
@@ -253,7 +268,7 @@ describe 'select input' do
|
|
253
268
|
end)
|
254
269
|
end
|
255
270
|
|
256
|
-
it_should_have_input_wrapper_with_class("select")
|
271
|
+
it_should_have_input_wrapper_with_class("select-wrapper")
|
257
272
|
it_should_have_input_wrapper_with_id("post_author_input")
|
258
273
|
it_should_have_label_with_text(/Author/)
|
259
274
|
it_should_have_label_for('post_author_id')
|
@@ -262,29 +277,29 @@ describe 'select input' do
|
|
262
277
|
|
263
278
|
0.upto(1) do |i|
|
264
279
|
it 'should have all option groups and the right values' do
|
265
|
-
output_buffer.should have_tag("form div.
|
280
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
|
266
281
|
end
|
267
282
|
|
268
283
|
it 'should have custom group labels' do
|
269
|
-
output_buffer.should have_tag("form div.
|
284
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
|
270
285
|
end
|
271
286
|
|
272
287
|
it 'should have custom author labels' do
|
273
|
-
output_buffer.should have_tag("form div.
|
288
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
|
274
289
|
end
|
275
290
|
|
276
291
|
it 'should have custom author and group labels' do
|
277
|
-
output_buffer.should have_tag("form div.
|
292
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
|
278
293
|
end
|
279
294
|
end
|
280
295
|
|
281
296
|
it 'should have no duplicate groups' do
|
282
|
-
output_buffer.should have_tag('form div.
|
297
|
+
output_buffer.should have_tag('form div.control-group div.controls select optgroup', :count => 8)
|
283
298
|
end
|
284
299
|
|
285
300
|
it 'should sort the groups on the label method' do
|
286
|
-
output_buffer.should have_tag("form div.
|
287
|
-
output_buffer.should have_tag("form div.
|
301
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='Africa']")
|
302
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='99']")
|
288
303
|
end
|
289
304
|
|
290
305
|
it 'should call find with :include for more optimized queries' do
|
@@ -303,7 +318,7 @@ describe 'select input' do
|
|
303
318
|
end)
|
304
319
|
end
|
305
320
|
|
306
|
-
it_should_have_input_wrapper_with_class("select")
|
321
|
+
it_should_have_input_wrapper_with_class("select-wrapper")
|
307
322
|
it_should_have_input_wrapper_with_id("author_posts_input")
|
308
323
|
it_should_have_label_with_text(/Post/)
|
309
324
|
it_should_have_label_for('author_post_ids')
|
@@ -312,27 +327,31 @@ describe 'select input' do
|
|
312
327
|
it_should_use_the_collection_when_provided(:select, 'option')
|
313
328
|
|
314
329
|
it 'should have a select inside the wrapper' do
|
315
|
-
output_buffer.should have_tag('form div.
|
316
|
-
output_buffer.should have_tag('form div.
|
330
|
+
output_buffer.should have_tag('form div.control-group div.controls select')
|
331
|
+
output_buffer.should have_tag('form div.control-group div.controls select#author_post_ids')
|
317
332
|
end
|
318
333
|
|
319
334
|
it 'should have a multi-select select' do
|
320
|
-
output_buffer.should have_tag('form div.
|
335
|
+
output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
|
321
336
|
end
|
322
337
|
|
323
338
|
it 'should append [] to the name attribute for multiple select' do
|
324
|
-
output_buffer.should have_tag('form div.
|
339
|
+
output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"][@name="author[post_ids][]"]')
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'should have a hidden field' do
|
343
|
+
output_buffer.should have_tag('form div.control-group div.controls input[@type="hidden"][@name="author[post_ids][]"]')
|
325
344
|
end
|
326
345
|
|
327
346
|
it 'should have a select option for each Post' do
|
328
|
-
output_buffer.should have_tag('form div.
|
347
|
+
output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Post.all.size)
|
329
348
|
::Post.all.each do |post|
|
330
|
-
output_buffer.should have_tag("form div.
|
349
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{post.id}']", /#{post.to_label}/)
|
331
350
|
end
|
332
351
|
end
|
333
352
|
|
334
353
|
it 'should not have a blank option by default' do
|
335
|
-
output_buffer.should_not have_tag("form div.
|
354
|
+
output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
|
336
355
|
end
|
337
356
|
|
338
357
|
it 'should respect the :include_blank option for single selects' do
|
@@ -340,7 +359,7 @@ describe 'select input' do
|
|
340
359
|
concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
|
341
360
|
end)
|
342
361
|
|
343
|
-
output_buffer.should have_tag("form div.
|
362
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
|
344
363
|
end
|
345
364
|
|
346
365
|
it 'should respect the :include_blank option for multiple selects' do
|
@@ -348,11 +367,11 @@ describe 'select input' do
|
|
348
367
|
concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
|
349
368
|
end)
|
350
369
|
|
351
|
-
output_buffer.should have_tag("form div.
|
370
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
|
352
371
|
end
|
353
372
|
|
354
373
|
it 'should have one option with a "selected" attribute' do
|
355
|
-
output_buffer.should have_tag('form div.
|
374
|
+
output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
|
356
375
|
end
|
357
376
|
end
|
358
377
|
|
@@ -363,7 +382,7 @@ describe 'select input' do
|
|
363
382
|
end)
|
364
383
|
end
|
365
384
|
|
366
|
-
it_should_have_input_wrapper_with_class("select")
|
385
|
+
it_should_have_input_wrapper_with_class("select-wrapper")
|
367
386
|
it_should_have_input_wrapper_with_id("post_authors_input")
|
368
387
|
it_should_have_label_with_text(/Author/)
|
369
388
|
it_should_have_label_for('post_author_ids')
|
@@ -372,23 +391,23 @@ describe 'select input' do
|
|
372
391
|
it_should_use_the_collection_when_provided(:select, 'option')
|
373
392
|
|
374
393
|
it 'should have a select inside the wrapper' do
|
375
|
-
output_buffer.should have_tag('form div.
|
376
|
-
output_buffer.should have_tag('form div.
|
394
|
+
output_buffer.should have_tag('form div.control-group div.controls select')
|
395
|
+
output_buffer.should have_tag('form div.control-group div.controls select#post_author_ids')
|
377
396
|
end
|
378
397
|
|
379
398
|
it 'should have a multi-select select' do
|
380
|
-
output_buffer.should have_tag('form div.
|
399
|
+
output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
|
381
400
|
end
|
382
401
|
|
383
402
|
it 'should have a select option for each Author' do
|
384
|
-
output_buffer.should have_tag('form div.
|
403
|
+
output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size)
|
385
404
|
::Author.all.each do |author|
|
386
|
-
output_buffer.should have_tag("form div.
|
405
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
|
387
406
|
end
|
388
407
|
end
|
389
408
|
|
390
409
|
it 'should not have a blank option by default' do
|
391
|
-
output_buffer.should_not have_tag("form div.
|
410
|
+
output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
|
392
411
|
end
|
393
412
|
|
394
413
|
it 'should respect the :include_blank option for single selects' do
|
@@ -396,7 +415,7 @@ describe 'select input' do
|
|
396
415
|
concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
|
397
416
|
end)
|
398
417
|
|
399
|
-
output_buffer.should have_tag("form div.
|
418
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
|
400
419
|
end
|
401
420
|
|
402
421
|
it 'should respect the :include_blank option for multiple selects' do
|
@@ -404,11 +423,11 @@ describe 'select input' do
|
|
404
423
|
concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
|
405
424
|
end)
|
406
425
|
|
407
|
-
output_buffer.should have_tag("form div.
|
426
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
|
408
427
|
end
|
409
428
|
|
410
429
|
it 'should have one option with a "selected" attribute' do
|
411
|
-
output_buffer.should have_tag('form div.
|
430
|
+
output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
|
412
431
|
end
|
413
432
|
end
|
414
433
|
|
@@ -421,11 +440,11 @@ describe 'select input' do
|
|
421
440
|
end
|
422
441
|
|
423
442
|
it 'should have a select with prompt' do
|
424
|
-
output_buffer.should have_tag("form div.
|
443
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", /choose author/, :count => 1)
|
425
444
|
end
|
426
445
|
|
427
|
-
it 'should not have a blank select option' do
|
428
|
-
output_buffer.
|
446
|
+
it 'should not have a second blank select option' do
|
447
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", :count => 1)
|
429
448
|
end
|
430
449
|
end
|
431
450
|
|
@@ -437,18 +456,18 @@ describe 'select input' do
|
|
437
456
|
end
|
438
457
|
|
439
458
|
it 'should generate label' do
|
440
|
-
output_buffer.should have_tag('form div.
|
441
|
-
output_buffer.should have_tag("form div.
|
459
|
+
output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
|
460
|
+
output_buffer.should have_tag("form div.control-group label.control-label[@for='project_author']")
|
442
461
|
end
|
443
462
|
|
444
463
|
it 'should generate select inputs' do
|
445
|
-
output_buffer.should have_tag('form div.
|
446
|
-
output_buffer.should have_tag('form div.
|
464
|
+
output_buffer.should have_tag('form div.control-group div.controls select#project_author')
|
465
|
+
output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size + 1)
|
447
466
|
end
|
448
467
|
|
449
468
|
it 'should generate an option to each item' do
|
450
469
|
::Author.all.each do |author|
|
451
|
-
output_buffer.should have_tag("form div.
|
470
|
+
output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
|
452
471
|
end
|
453
472
|
end
|
454
473
|
end
|
@@ -459,27 +478,27 @@ describe 'select input' do
|
|
459
478
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
460
479
|
concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
|
461
480
|
end)
|
462
|
-
output_buffer.should have_tag("form div.
|
481
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@name='project[author_name]']")
|
463
482
|
end
|
464
|
-
|
483
|
+
|
465
484
|
describe 'and :multiple is set to true through :input_html' do
|
466
485
|
it "should make the select a multi-select" do
|
467
486
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
468
487
|
concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
|
469
488
|
end)
|
470
|
-
output_buffer.should have_tag("form div.
|
489
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
|
471
490
|
end
|
472
491
|
end
|
473
|
-
|
492
|
+
|
474
493
|
describe 'and :multiple is set to true' do
|
475
494
|
it "should make the select a multi-select" do
|
476
495
|
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
477
496
|
concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
|
478
497
|
end)
|
479
|
-
output_buffer.should have_tag("form div.
|
498
|
+
output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
|
480
499
|
end
|
481
500
|
end
|
482
|
-
|
501
|
+
|
483
502
|
end
|
484
503
|
|
485
504
|
describe 'when a grouped collection collection is given' do
|
@@ -494,12 +513,12 @@ describe 'select input' do
|
|
494
513
|
|
495
514
|
it 'should generate an option to each item' do
|
496
515
|
@grouped_opts.each do |opt_pair|
|
497
|
-
output_buffer.should have_tag("form div.
|
516
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}']")
|
498
517
|
opt_pair[1].each do |v|
|
499
|
-
output_buffer.should have_tag("form div.
|
518
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
|
500
519
|
end
|
501
520
|
end
|
502
|
-
output_buffer.should have_tag("form div.
|
521
|
+
output_buffer.should have_tag("form div.control-group div.controls select optgroup option[@selected]","hands")
|
503
522
|
end
|
504
523
|
end
|
505
524
|
|
@@ -521,7 +540,7 @@ describe 'select input' do
|
|
521
540
|
end
|
522
541
|
|
523
542
|
it "should render a select field" do
|
524
|
-
output_buffer.should have_tag("form div.
|
543
|
+
output_buffer.should have_tag("form div.control-group div.controls select", :count => 2)
|
525
544
|
end
|
526
545
|
end
|
527
546
|
|
@@ -537,7 +556,7 @@ describe 'select input' do
|
|
537
556
|
end
|
538
557
|
|
539
558
|
it "should render a text field" do
|
540
|
-
output_buffer.should have_tag("form div.
|
559
|
+
output_buffer.should have_tag("form div.control-group div.controls input[@type='text']", :count => 2)
|
541
560
|
end
|
542
561
|
end
|
543
562
|
end
|
@@ -553,6 +572,33 @@ describe 'select input' do
|
|
553
572
|
it_should_have_label_for("context2_post_author_ids")
|
554
573
|
end
|
555
574
|
|
575
|
+
describe "when index is provided" do
|
576
|
+
|
577
|
+
before do
|
578
|
+
@output_buffer = ''
|
579
|
+
mock_everything
|
580
|
+
|
581
|
+
concat(semantic_form_for(@new_post) do |builder|
|
582
|
+
concat(builder.fields_for(:author, :index => 3) do |author|
|
583
|
+
concat(author.input(:name, :as => :select))
|
584
|
+
end)
|
585
|
+
end)
|
586
|
+
end
|
587
|
+
|
588
|
+
it 'should index the id of the wrapper' do
|
589
|
+
output_buffer.should have_tag("div#post_author_attributes_3_name_input")
|
590
|
+
end
|
591
|
+
|
592
|
+
it 'should index the id of the select tag' do
|
593
|
+
output_buffer.should have_tag("select#post_author_attributes_3_name")
|
594
|
+
end
|
595
|
+
|
596
|
+
it 'should index the name of the select' do
|
597
|
+
output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
|
598
|
+
end
|
599
|
+
|
600
|
+
end
|
601
|
+
|
556
602
|
context "when required" do
|
557
603
|
it "should add the required attribute to the select's html options" do
|
558
604
|
with_config :use_required_attribute, true do
|