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.
Files changed (89) hide show
  1. data/README.md +11 -2
  2. data/VERSION +1 -1
  3. data/vendor/assets/stylesheets/formtastic-bootstrap.css +4 -0
  4. metadata +51 -154
  5. data/.rspec +0 -1
  6. data/Gemfile +0 -14
  7. data/Gemfile.lock +0 -131
  8. data/Rakefile +0 -49
  9. data/formtastic-bootstrap.gemspec +0 -166
  10. data/lib/action_view/helpers/text_field_date_helper.rb +0 -166
  11. data/lib/formtastic-bootstrap/actions.rb +0 -10
  12. data/lib/formtastic-bootstrap/actions/base.rb +0 -22
  13. data/lib/formtastic-bootstrap/actions/button_action.rb +0 -13
  14. data/lib/formtastic-bootstrap/actions/input_action.rb +0 -13
  15. data/lib/formtastic-bootstrap/actions/link_action.rb +0 -12
  16. data/lib/formtastic-bootstrap/engine.rb +0 -4
  17. data/lib/formtastic-bootstrap/form_builder.rb +0 -40
  18. data/lib/formtastic-bootstrap/helpers.rb +0 -17
  19. data/lib/formtastic-bootstrap/helpers/action_helper.rb +0 -12
  20. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +0 -24
  21. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +0 -35
  22. data/lib/formtastic-bootstrap/helpers/input_helper.rb +0 -12
  23. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +0 -34
  24. data/lib/formtastic-bootstrap/inputs.rb +0 -36
  25. data/lib/formtastic-bootstrap/inputs/base.rb +0 -45
  26. data/lib/formtastic-bootstrap/inputs/base/choices.rb +0 -20
  27. data/lib/formtastic-bootstrap/inputs/base/collections.rb +0 -9
  28. data/lib/formtastic-bootstrap/inputs/base/errors.rb +0 -48
  29. data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +0 -9
  30. data/lib/formtastic-bootstrap/inputs/base/hints.rb +0 -27
  31. data/lib/formtastic-bootstrap/inputs/base/html.rb +0 -21
  32. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +0 -29
  33. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +0 -9
  34. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +0 -17
  35. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +0 -55
  36. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +0 -55
  37. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +0 -29
  38. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +0 -40
  39. data/lib/formtastic-bootstrap/inputs/date_input.rb +0 -10
  40. data/lib/formtastic-bootstrap/inputs/date_select_input.rb +0 -8
  41. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +0 -10
  42. data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +0 -8
  43. data/lib/formtastic-bootstrap/inputs/email_input.rb +0 -15
  44. data/lib/formtastic-bootstrap/inputs/file_input.rb +0 -14
  45. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +0 -12
  46. data/lib/formtastic-bootstrap/inputs/number_input.rb +0 -15
  47. data/lib/formtastic-bootstrap/inputs/password_input.rb +0 -15
  48. data/lib/formtastic-bootstrap/inputs/phone_input.rb +0 -15
  49. data/lib/formtastic-bootstrap/inputs/radio_input.rb +0 -46
  50. data/lib/formtastic-bootstrap/inputs/range_input.rb +0 -15
  51. data/lib/formtastic-bootstrap/inputs/search_input.rb +0 -15
  52. data/lib/formtastic-bootstrap/inputs/select_input.rb +0 -16
  53. data/lib/formtastic-bootstrap/inputs/string_input.rb +0 -8
  54. data/lib/formtastic-bootstrap/inputs/text_input.rb +0 -14
  55. data/lib/formtastic-bootstrap/inputs/time_input.rb +0 -10
  56. data/lib/formtastic-bootstrap/inputs/time_select_input.rb +0 -8
  57. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +0 -14
  58. data/lib/formtastic-bootstrap/inputs/url_input.rb +0 -14
  59. data/spec/actions/button_action_spec.rb +0 -63
  60. data/spec/actions/input_action_spec.rb +0 -59
  61. data/spec/actions/link_action_spec.rb +0 -92
  62. data/spec/builder/semantic_fields_for_spec.rb +0 -130
  63. data/spec/helpers/action_helper_spec.rb +0 -368
  64. data/spec/helpers/actions_helper_spec.rb +0 -147
  65. data/spec/helpers/input_helper_spec.rb +0 -935
  66. data/spec/helpers/inputs_helper_spec.rb +0 -636
  67. data/spec/inputs/boolean_input_spec.rb +0 -226
  68. data/spec/inputs/check_boxes_input_spec.rb +0 -454
  69. data/spec/inputs/date_select_input_spec.rb +0 -164
  70. data/spec/inputs/datetime_select_input_spec.rb +0 -112
  71. data/spec/inputs/deprecated_time_date_datetime_inputs_spec.rb +0 -48
  72. data/spec/inputs/email_input_spec.rb +0 -86
  73. data/spec/inputs/file_input_spec.rb +0 -90
  74. data/spec/inputs/hidden_input_spec.rb +0 -153
  75. data/spec/inputs/number_input_spec.rb +0 -816
  76. data/spec/inputs/password_input_spec.rb +0 -100
  77. data/spec/inputs/phone_input_spec.rb +0 -86
  78. data/spec/inputs/radio_input_spec.rb +0 -267
  79. data/spec/inputs/range_input_spec.rb +0 -506
  80. data/spec/inputs/search_input_spec.rb +0 -85
  81. data/spec/inputs/select_input_spec.rb +0 -624
  82. data/spec/inputs/string_input_spec.rb +0 -210
  83. data/spec/inputs/text_input_spec.rb +0 -188
  84. data/spec/inputs/time_select_input_spec.rb +0 -191
  85. data/spec/inputs/time_zone_input_spec.rb +0 -118
  86. data/spec/inputs/url_input_spec.rb +0 -86
  87. data/spec/spec_helper.rb +0 -30
  88. data/spec/support/custom_macros.rb +0 -537
  89. data/spec/support/fb_custom_macros.rb +0 -23
@@ -1,85 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'search input' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ''
10
- mock_everything
11
- end
12
-
13
- describe "when object is provided" do
14
- before do
15
- concat(semantic_form_for(@new_post) do |builder|
16
- concat(builder.input(:search))
17
- end)
18
- end
19
-
20
- it_should_have_bootstrap_horizontal_wrapping
21
- it_should_have_input_wrapper_with_class(:search)
22
- it_should_have_input_wrapper_with_class(:input)
23
- it_should_have_input_wrapper_with_class(:stringish)
24
- it_should_have_input_wrapper_with_id("post_search_input")
25
- it_should_have_label_with_text(/Search/)
26
- it_should_have_label_for("post_search")
27
- it_should_have_input_with_id("post_search")
28
- it_should_have_input_with_type(:search)
29
- it_should_have_input_with_name("post[search]")
30
-
31
- end
32
-
33
- describe "when namespace is provided" do
34
-
35
- before do
36
- concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
37
- concat(builder.input(:search))
38
- end)
39
- end
40
-
41
- it_should_have_input_wrapper_with_id("context2_post_search_input")
42
- it_should_have_label_and_input_with_id("context2_post_search")
43
-
44
- end
45
-
46
- describe "when index is provided" do
47
-
48
- before do
49
- @output_buffer = ''
50
- mock_everything
51
-
52
- concat(semantic_form_for(@new_post) do |builder|
53
- concat(builder.fields_for(:author, :index => 3) do |author|
54
- concat(author.input(:name, :as => :search))
55
- end)
56
- end)
57
- end
58
-
59
- it 'should index the id of the control-group' do
60
- output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
61
- end
62
-
63
- it 'should index the id of the select tag' do
64
- output_buffer.should have_tag("input#post_author_attributes_3_name")
65
- end
66
-
67
- it 'should index the name of the select tag' do
68
- output_buffer.should have_tag("input[@name='post[author_attributes][3][name]']")
69
- end
70
-
71
- end
72
-
73
- describe "when required" do
74
- it "should add the required attribute to the input's html options" do
75
- with_config :use_required_attribute, true do
76
- concat(semantic_form_for(@new_post) do |builder|
77
- concat(builder.input(:title, :as => :search, :required => true))
78
- end)
79
- output_buffer.should have_tag("input[@required]")
80
- end
81
- end
82
- end
83
-
84
- end
85
-
@@ -1,624 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe 'select input' do
5
-
6
- include FormtasticSpecHelper
7
-
8
- before do
9
- @output_buffer = ''
10
- mock_everything
11
- end
12
-
13
- describe 'explicit values' do
14
- describe 'using an array of values' do
15
- before do
16
- @array_with_values = ["Title A", "Title B", "Title C"]
17
- @array_with_keys_and_values = [["Title D", 1], ["Title E", 2], ["Title F", 3]]
18
- concat(semantic_form_for(@new_post) do |builder|
19
- concat(builder.input(:title, :as => :select, :collection => @array_with_values))
20
- concat(builder.input(:title, :as => :select, :collection => @array_with_keys_and_values))
21
- end)
22
- end
23
-
24
- it 'should have a option for each key and/or value' do
25
- @array_with_values.each do |v|
26
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
27
- end
28
- @array_with_keys_and_values.each do |v|
29
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v.second}']", /^#{v.first}$/)
30
- end
31
- end
32
- end
33
-
34
- describe "using a related model without reflection's options (Mongoid Document)" do
35
- before do
36
- @new_post.stub!(:mongoid_reviewer)
37
- concat(semantic_form_for(@new_post) do |builder|
38
- concat(builder.input(:mongoid_reviewer, :as => :select))
39
- end)
40
- end
41
-
42
- it 'should draw select options' do
43
- output_buffer.should have_tag('form div.control-group div.controls select')
44
- output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
45
- output_buffer.should_not have_tag('form div.control-group div.controls select#post_mongoid_reviewer_id')
46
- end
47
- end
48
-
49
- describe 'using a range' do
50
- before do
51
- @range_with_values = 1..5
52
- concat(semantic_form_for(@new_post) do |builder|
53
- concat(builder.input(:title, :as => :select, :collection => @range_with_values))
54
- end)
55
- end
56
-
57
- it 'should have an option for each value' do
58
- @range_with_values.each do |v|
59
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
60
- end
61
- end
62
- end
63
-
64
- describe 'using a string' do
65
- before do
66
- @string ="<option value='0'>0</option><option value='1'>1</option>".html_safe
67
- concat(semantic_form_for(@new_post) do |builder|
68
- concat(builder.input(:title, :as => :select, :collection => @string))
69
- end)
70
- end
71
-
72
- it 'should render select options using provided HTML string' do
73
- 2.times do |v|
74
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{v}']", /^#{v}$/)
75
- end
76
- end
77
- end
78
-
79
- describe 'using a nil name' do
80
- before do
81
- concat(semantic_form_for(@new_post) do |builder|
82
- concat(builder.input(:title, :as => :select, :collection => [], :input_html => {:name => nil}))
83
- end)
84
- end
85
-
86
- it_should_have_select_with_name("post[title]")
87
- end
88
- end
89
-
90
- describe 'for boolean columns' do
91
- pending
92
- # describe 'default formtastic locale' do
93
- # before do
94
- # # Note: Works, but something like Formtastic.root.join(...) would probably be "safer".
95
- # # ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
96
- # # ::I18n.backend.send(:init_translations)
97
- #
98
- # concat(semantic_form_for(@new_post) do |builder|
99
- # concat(builder.input(:published, :as => :select))
100
- # end)
101
- # end
102
- #
103
- # after do
104
- # # ::I18n.load_path = []
105
- # # ::I18n.backend.store_translations :en, {}
106
- # end
107
- #
108
- #
109
- # it 'should render a select with at least options: true/false' do
110
- # # I don't wanna deal with this right now.
111
- # pending
112
- # # output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /^Yes$/)
113
- # # output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /^No$/)
114
- # end
115
- # end
116
- #
117
- # describe 'custom locale' do
118
- # before do
119
- # @boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
120
- # ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
121
- #
122
- # concat(semantic_form_for(@new_post) do |builder|
123
- # concat(builder.input(:published, :as => :select))
124
- # end)
125
- # end
126
- #
127
- # after do
128
- # ::I18n.backend.store_translations :en, {}
129
- # end
130
- #
131
- # it 'should render a select with at least options: true/false' do
132
- # output_buffer.should have_tag("form div.control-group div.controls select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
133
- # output_buffer.should have_tag("form div.control-group div.controls select option[@value='false']", /#{@boolean_select_labels[:no]}/)
134
- # end
135
- # end
136
- end
137
-
138
- describe 'for a belongs_to association' do
139
- before do
140
- concat(semantic_form_for(@new_post) do |builder|
141
- concat(builder.input(:author, :as => :select))
142
- concat(builder.input(:reviewer, :as => :select))
143
- end)
144
- end
145
-
146
- it_should_have_bootstrap_horizontal_wrapping
147
- it_should_have_input_wrapper_with_class("select")
148
- it_should_have_input_wrapper_with_class(:input)
149
- it_should_have_input_wrapper_with_id("post_author_input")
150
- it_should_have_label_with_text(/Author/)
151
- it_should_have_label_for('post_author_id')
152
- it_should_apply_error_logic_for_input_type(:select)
153
- it_should_call_find_on_association_class_when_no_collection_is_provided(:select)
154
- it_should_use_the_collection_when_provided(:select, 'option')
155
-
156
- it 'should have a select inside the wrapper' do
157
- output_buffer.should have_tag('form div.control-group div.controls select')
158
- output_buffer.should have_tag('form div.control-group div.controls select#post_author_id')
159
- output_buffer.should have_tag('form div.control-group div.controls select#post_reviewer_id')
160
- end
161
-
162
- it 'should have a valid name' do
163
- output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]']")
164
- output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[author_id][]']")
165
- output_buffer.should_not have_tag("form div.control-group div.controls select[@name='post[reviewer_id][]']")
166
- end
167
-
168
- it 'should not create a multi-select' do
169
- output_buffer.should_not have_tag('form div.control-group div.controls select[@multiple]')
170
- end
171
-
172
- it 'should not add a hidden input' do
173
- output_buffer.should_not have_tag('form li input[@type="hidden"]')
174
- end
175
-
176
- it 'should create a select without size' do
177
- output_buffer.should_not have_tag('form div.control-group div.controls select[@size]')
178
- end
179
-
180
- it 'should have a blank option' do
181
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
182
- end
183
-
184
- it 'should have a select option for each Author' do
185
- output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option", :count => ::Author.all.size + 1)
186
- ::Author.all.each do |author|
187
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
188
- end
189
- end
190
-
191
- it 'should have one option with a "selected" attribute (bob)' do
192
- output_buffer.should have_tag("form div.control-group div.controls select[@name='post[author_id]'] option[@selected]", :count => 1)
193
- end
194
-
195
- it 'should not singularize the association name' do
196
- @new_post.stub!(:author_status).and_return(@bob)
197
- @new_post.stub!(:author_status_id).and_return(@bob.id)
198
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :integer, :limit => 255))
199
-
200
- concat(semantic_form_for(@new_post) do |builder|
201
- concat(builder.input(:author_status, :as => :select))
202
- end)
203
-
204
- output_buffer.should have_tag('form div.control-group div.controls select#post_author_status_id')
205
- end
206
- end
207
-
208
- describe "for a belongs_to association with :group_by => :author" do
209
- it "should call author.posts" do
210
- ::Author.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Post, :name => :posts)] : []}
211
-
212
- [@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
213
- @fred.should_receive(:posts)
214
-
215
- with_deprecation_silenced do
216
- concat(semantic_form_for(@new_post) do |builder|
217
- concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
218
- end)
219
- end
220
- end
221
- end
222
-
223
- describe "for a belongs_to association with :conditions" do
224
- before do
225
- ::Post.stub!(:reflect_on_association).with(:author).and_return do
226
- mock = mock('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
227
- mock.stub!(:[]).with(:class_name).and_return("Author")
228
- mock
229
- end
230
- end
231
-
232
- it "should call author.find with association conditions" do
233
- ::Author.should_receive(:scoped).with(:conditions => {:active => true})
234
-
235
- semantic_form_for(@new_post) do |builder|
236
- concat(builder.input(:author, :as => :select))
237
- end
238
- end
239
-
240
- it "should call author.find with association conditions and find_options conditions" do
241
- ::Author.should_receive(:scoped).with(:conditions => {:active => true})
242
- ::Author.should_receive(:where).with({:publisher => true})
243
-
244
- with_deprecation_silenced do
245
- semantic_form_for(@new_post) do |builder|
246
- concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
247
- end
248
- end
249
- end
250
- end
251
-
252
- describe 'for a belongs_to association with :group_by => :continent' do
253
- before do
254
- @authors = [@bob, @fred, @fred, @fred]
255
- ::Author.stub!(:find).and_return(@authors)
256
- @continent_names = %w(Europe Africa)
257
- @continents = (0..1).map { |i| c = ::Continent.new; c.stub!(:id).and_return(100 - i);c }
258
- @authors[0..1].each_with_index { |author, i| author.stub!(:continent).and_return(@continents[i]) }
259
-
260
- ::Continent.stub!(:reflect_on_all_associations).and_return { |macro| macro == :has_many ? [mock('reflection', :klass => Author, :name => :authors)] : [] }
261
- ::Continent.stub!(:reflect_on_association).and_return {|column_name| mock('reflection', :klass => Author) if column_name == :authors}
262
- ::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Continent, :macro => :belongs_to) if column_name == :continent }
263
-
264
-
265
- @continents.each_with_index do |continent, i|
266
- continent.stub!(:to_label).and_return(@continent_names[i])
267
- continent.stub!(:authors).and_return([@authors[i]])
268
- end
269
-
270
- with_deprecation_silenced do
271
- concat(semantic_form_for(@new_post) do |builder|
272
- concat(builder.input(:author, :as => :select, :group_by => :continent ) )
273
- concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label => :id ) )
274
- concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login ) )
275
- concat(builder.input(:author, :as => :select, :group_by => :continent, :member_label => :login, :group_label => :id ) )
276
- end)
277
- end
278
- end
279
-
280
- it_should_have_input_wrapper_with_class("select")
281
- it_should_have_input_wrapper_with_id("post_author_input")
282
- it_should_have_label_with_text(/Author/)
283
- it_should_have_label_for('post_author_id')
284
-
285
- # TODO, need to find a way to repeat some of the specs and logic from the belongs_to specs without grouping
286
-
287
- 0.upto(1) do |i|
288
- it 'should have all option groups and the right values' do
289
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
290
- end
291
-
292
- it 'should have custom group labels' do
293
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
294
- end
295
-
296
- it 'should have custom author labels' do
297
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continent_names[i]}']", @authors[i].login)
298
- end
299
-
300
- it 'should have custom author and group labels' do
301
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{@continents[i].id}']", @authors[i].login)
302
- end
303
- end
304
-
305
- it 'should have no duplicate groups' do
306
- output_buffer.should have_tag('form div.control-group div.controls select optgroup', :count => 8)
307
- end
308
-
309
- it 'should sort the groups on the label method' do
310
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='Africa']")
311
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='99']")
312
- end
313
-
314
- it 'should call find with :include for more optimized queries' do
315
- Author.should_receive(:where).with(:include => :continent)
316
-
317
- with_deprecation_silenced do
318
- semantic_form_for(@new_post) do |builder|
319
- concat(builder.input(:author, :as => :select, :group_by => :continent ) )
320
- end
321
- end
322
- end
323
- end
324
-
325
- describe 'for a has_many association' do
326
- before do
327
- concat(semantic_form_for(@fred) do |builder|
328
- concat(builder.input(:posts, :as => :select))
329
- end)
330
- end
331
-
332
- it_should_have_input_wrapper_with_class("select")
333
- it_should_have_input_wrapper_with_id("author_posts_input")
334
- it_should_have_label_with_text(/Post/)
335
- it_should_have_label_for('author_post_ids')
336
- it_should_apply_error_logic_for_input_type(:select)
337
- it_should_call_find_on_association_class_when_no_collection_is_provided(:select)
338
- it_should_use_the_collection_when_provided(:select, 'option')
339
-
340
- it 'should have a select inside the wrapper' do
341
- output_buffer.should have_tag('form div.control-group div.controls select')
342
- output_buffer.should have_tag('form div.control-group div.controls select#author_post_ids')
343
- end
344
-
345
- it 'should have a multi-select select' do
346
- output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
347
- end
348
-
349
- it 'should append [] to the name attribute for multiple select' do
350
- output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"][@name="author[post_ids][]"]')
351
- end
352
-
353
- it 'should have a hidden field' do
354
- output_buffer.should have_tag('form div.control-group input[@type="hidden"][@name="author[post_ids][]"]')
355
- end
356
-
357
- it 'should have a select option for each Post' do
358
- output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Post.all.size)
359
- ::Post.all.each do |post|
360
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{post.id}']", /#{post.to_label}/)
361
- end
362
- end
363
-
364
- it 'should not have a blank option by default' do
365
- output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
366
- end
367
-
368
- it 'should respect the :include_blank option for single selects' do
369
- concat(semantic_form_for(@fred) do |builder|
370
- concat(builder.input(:posts, :as => :select, :multiple => false, :include_blank => true))
371
- end)
372
-
373
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
374
- end
375
-
376
- it 'should respect the :include_blank option for multiple selects' do
377
- concat(semantic_form_for(@fred) do |builder|
378
- concat(builder.input(:posts, :as => :select, :multiple => true, :include_blank => true))
379
- end)
380
-
381
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
382
- end
383
-
384
- it 'should have one option with a "selected" attribute' do
385
- output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
386
- end
387
- end
388
-
389
- describe 'for a has_and_belongs_to_many association' do
390
- before do
391
- concat(semantic_form_for(@freds_post) do |builder|
392
- concat(builder.input(:authors, :as => :select))
393
- end)
394
- end
395
-
396
- it_should_have_input_wrapper_with_class("select")
397
- it_should_have_input_wrapper_with_id("post_authors_input")
398
- it_should_have_label_with_text(/Author/)
399
- it_should_have_label_for('post_author_ids')
400
- it_should_apply_error_logic_for_input_type(:select)
401
- it_should_call_find_on_association_class_when_no_collection_is_provided(:select)
402
- it_should_use_the_collection_when_provided(:select, 'option')
403
-
404
- it 'should have a select inside the wrapper' do
405
- output_buffer.should have_tag('form div.control-group div.controls select')
406
- output_buffer.should have_tag('form div.control-group div.controls select#post_author_ids')
407
- end
408
-
409
- it 'should have a multi-select select' do
410
- output_buffer.should have_tag('form div.control-group div.controls select[@multiple="multiple"]')
411
- end
412
-
413
- it 'should have a select option for each Author' do
414
- output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size)
415
- ::Author.all.each do |author|
416
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
417
- end
418
- end
419
-
420
- it 'should not have a blank option by default' do
421
- output_buffer.should_not have_tag("form div.control-group div.controls select option[@value='']")
422
- end
423
-
424
- it 'should respect the :include_blank option for single selects' do
425
- concat(semantic_form_for(@freds_post) do |builder|
426
- concat(builder.input(:authors, :as => :select, :multiple => false, :include_blank => true))
427
- end)
428
-
429
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
430
- end
431
-
432
- it 'should respect the :include_blank option for multiple selects' do
433
- concat(semantic_form_for(@freds_post) do |builder|
434
- concat(builder.input(:authors, :as => :select, :multiple => true, :include_blank => true))
435
- end)
436
-
437
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']")
438
- end
439
-
440
- it 'should have one option with a "selected" attribute' do
441
- output_buffer.should have_tag('form div.control-group div.controls select option[@selected]', :count => 1)
442
- end
443
- end
444
-
445
- describe 'when :prompt => "choose something" is set' do
446
- before do
447
- @new_post.stub!(:author_id).and_return(nil)
448
- concat(semantic_form_for(@new_post) do |builder|
449
- concat(builder.input(:author, :as => :select, :prompt => "choose author"))
450
- end)
451
- end
452
-
453
- it 'should have a select with prompt' do
454
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", /choose author/, :count => 1)
455
- end
456
-
457
- it 'should not have a second blank select option' do
458
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='']", :count => 1)
459
- end
460
- end
461
-
462
- describe 'when no object is given' do
463
- before(:each) do
464
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
465
- concat(builder.input(:author, :as => :select, :collection => ::Author.all))
466
- end)
467
- end
468
-
469
- it 'should generate label' do
470
- output_buffer.should have_tag('form div.control-group label.control-label', /Author/)
471
- output_buffer.should have_tag("form div.control-group label.control-label[@for='project_author']")
472
- end
473
-
474
- it 'should generate select inputs' do
475
- output_buffer.should have_tag('form div.control-group div.controls select#project_author')
476
- output_buffer.should have_tag('form div.control-group div.controls select option', :count => ::Author.all.size + 1)
477
- end
478
-
479
- it 'should generate an option to each item' do
480
- ::Author.all.each do |author|
481
- output_buffer.should have_tag("form div.control-group div.controls select option[@value='#{author.id}']", /#{author.to_label}/)
482
- end
483
- end
484
- end
485
-
486
- describe 'when no association exists' do
487
-
488
- it 'should still generate a valid name attribute' do
489
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
490
- concat(builder.input(:author_name, :as => :select, :collection => ::Author.all))
491
- end)
492
- output_buffer.should have_tag("form div.control-group div.controls select[@name='project[author_name]']")
493
- end
494
-
495
- describe 'and :multiple is set to true through :input_html' do
496
- it "should make the select a multi-select" do
497
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
498
- concat(builder.input(:author_name, :as => :select, :input_html => {:multiple => true} ))
499
- end)
500
- output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
501
- end
502
- end
503
-
504
- describe 'and :multiple is set to true' do
505
- it "should make the select a multi-select" do
506
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
507
- concat(builder.input(:author_name, :as => :select, :multiple => true, :collection => ["Fred", "Bob"]))
508
- end)
509
- output_buffer.should have_tag("form div.control-group div.controls select[@multiple]")
510
- end
511
- end
512
-
513
- end
514
-
515
- describe 'when a grouped collection collection is given' do
516
- before(:each) do
517
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
518
- @grouped_opts = [['one', ['pencil', 'crayon', 'pen']],
519
- ['two', ['eyes', 'hands', 'feet']],
520
- ['three', ['wickets', 'witches', 'blind mice']]]
521
- concat(builder.input(:author, :as => :select, :collection => grouped_options_for_select(@grouped_opts, "hands")))
522
- end)
523
- end
524
-
525
- it 'should generate an option to each item' do
526
- @grouped_opts.each do |opt_pair|
527
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}']")
528
- opt_pair[1].each do |v|
529
- output_buffer.should have_tag("form div.control-group div.controls select optgroup[@label='#{opt_pair[0]}'] option[@value='#{v}']")
530
- end
531
- end
532
- output_buffer.should have_tag("form div.control-group div.controls select optgroup option[@selected]","hands")
533
- end
534
- end
535
-
536
- describe "enum" do
537
- before do
538
- @output_buffer = ''
539
- @some_meta_descriptions = ["One", "Two", "Three"]
540
- @new_post.stub!(:meta_description).any_number_of_times
541
- end
542
-
543
- describe ":as is not set" do
544
- before do
545
- concat(semantic_form_for(@new_post) do |builder|
546
- concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
547
- end)
548
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
549
- concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
550
- end)
551
- end
552
-
553
- it "should render a select field" do
554
- output_buffer.should have_tag("form div.control-group div.controls select", :count => 2)
555
- end
556
- end
557
-
558
- describe ":as is set" do
559
- before do
560
- # Should not be a case, but just checking :as got highest priority in setting input type.
561
- concat(semantic_form_for(@new_post) do |builder|
562
- concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
563
- end)
564
- concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
565
- concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
566
- end)
567
- end
568
-
569
- it "should render a text field" do
570
- output_buffer.should have_tag("form div.control-group div.controls input[@type='text']", :count => 2)
571
- end
572
- end
573
- end
574
-
575
- describe 'when a namespace is provided' do
576
- before do
577
- concat(semantic_form_for(@freds_post, :namespace => 'context2') do |builder|
578
- concat(builder.input(:authors, :as => :select))
579
- end)
580
- end
581
- it_should_have_input_wrapper_with_id("context2_post_authors_input")
582
- it_should_have_select_with_id("context2_post_author_ids")
583
- it_should_have_label_for("context2_post_author_ids")
584
- end
585
-
586
- describe "when index is provided" do
587
-
588
- before do
589
- @output_buffer = ''
590
- mock_everything
591
-
592
- concat(semantic_form_for(@new_post) do |builder|
593
- concat(builder.fields_for(:author, :index => 3) do |author|
594
- concat(author.input(:name, :as => :select))
595
- end)
596
- end)
597
- end
598
-
599
- it 'should index the id of the control-group' do
600
- output_buffer.should have_tag("div.control-group#post_author_attributes_3_name_input")
601
- end
602
-
603
- it 'should index the id of the select tag' do
604
- output_buffer.should have_tag("select#post_author_attributes_3_name")
605
- end
606
-
607
- it 'should index the name of the select' do
608
- output_buffer.should have_tag("select[@name='post[author_attributes][3][name]']")
609
- end
610
-
611
- end
612
-
613
- context "when required" do
614
- it "should add the required attribute to the select's html options" do
615
- with_config :use_required_attribute, true do
616
- concat(semantic_form_for(@new_post) do |builder|
617
- concat(builder.input(:author, :as => :select, :required => true))
618
- end)
619
- output_buffer.should have_tag("select[@required]")
620
- end
621
- end
622
- end
623
-
624
- end