ShadowBelmolve-formtastic 0.2.1 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.textile +191 -176
  2. data/Rakefile +65 -22
  3. data/generators/form/USAGE +16 -0
  4. data/generators/form/form_generator.rb +120 -0
  5. data/generators/form/templates/view__form.html.erb +5 -0
  6. data/generators/form/templates/view__form.html.haml +4 -0
  7. data/generators/formtastic/formtastic_generator.rb +24 -0
  8. data/generators/{formtastic_stylesheets → formtastic}/templates/formtastic.css +2 -0
  9. data/generators/formtastic/templates/formtastic.rb +51 -0
  10. data/generators/{formtastic_stylesheets → formtastic}/templates/formtastic_changes.css +0 -0
  11. data/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +5 -10
  12. data/lib/formtastic.rb +1234 -895
  13. data/lib/formtastic/i18n.rb +32 -0
  14. data/lib/locale/en.yml +2 -2
  15. data/rails/init.rb +1 -1
  16. data/spec/buttons_spec.rb +149 -0
  17. data/spec/commit_button_spec.rb +344 -0
  18. data/spec/custom_builder_spec.rb +62 -0
  19. data/spec/custom_macros.rb +561 -0
  20. data/spec/defaults_spec.rb +20 -0
  21. data/spec/error_proc_spec.rb +27 -0
  22. data/spec/errors_spec.rb +85 -0
  23. data/spec/form_helper_spec.rb +120 -0
  24. data/spec/i18n_spec.rb +131 -0
  25. data/spec/include_blank_spec.rb +70 -0
  26. data/spec/input_spec.rb +608 -0
  27. data/spec/inputs/boolean_input_spec.rb +93 -0
  28. data/spec/inputs/check_boxes_input_spec.rb +162 -0
  29. data/spec/inputs/country_input_spec.rb +80 -0
  30. data/spec/inputs/date_input_spec.rb +45 -0
  31. data/spec/inputs/datetime_input_spec.rb +155 -0
  32. data/spec/inputs/file_input_spec.rb +33 -0
  33. data/spec/inputs/hidden_input_spec.rb +52 -0
  34. data/spec/inputs/numeric_input_spec.rb +44 -0
  35. data/spec/inputs/password_input_spec.rb +46 -0
  36. data/spec/inputs/radio_input_spec.rb +149 -0
  37. data/spec/inputs/select_input_spec.rb +459 -0
  38. data/spec/inputs/string_input_spec.rb +47 -0
  39. data/spec/inputs/text_input_spec.rb +33 -0
  40. data/spec/inputs/time_input_spec.rb +44 -0
  41. data/spec/inputs/time_zone_input_spec.rb +102 -0
  42. data/spec/inputs_spec.rb +395 -0
  43. data/spec/label_spec.rb +48 -0
  44. data/spec/nested_forms_spec.rb +50 -0
  45. data/spec/semantic_fields_for_spec.rb +44 -0
  46. data/spec/spec.opts +2 -0
  47. data/spec/spec_helper.rb +212 -0
  48. metadata +121 -16
  49. data/lib/justin_french/formtastic.rb +0 -10
  50. data/spec/formtastic_spec.rb +0 -3072
  51. data/spec/test_helper.rb +0 -14
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'string input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:title, :as => :string))
14
+ end
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class(:string)
18
+ it_should_have_input_wrapper_with_id("post_title_input")
19
+ it_should_have_label_with_text(/Title/)
20
+ it_should_have_label_for("post_title")
21
+ it_should_have_input_with_id("post_title")
22
+ it_should_have_input_with_type(:text)
23
+ it_should_have_input_with_name("post[title]")
24
+ it_should_have_maxlength_matching_column_limit
25
+ it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
26
+ it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
27
+ it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
28
+ it_should_apply_custom_input_attributes_when_input_html_provided(:string)
29
+ it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
30
+ it_should_apply_error_logic_for_input_type(:string)
31
+
32
+ describe "when no object is provided" do
33
+ before do
34
+ semantic_form_for(:project, :url => 'http://test.host/') do |builder|
35
+ concat(builder.input(:title, :as => :string))
36
+ end
37
+ end
38
+
39
+ it_should_have_label_with_text(/Title/)
40
+ it_should_have_label_for("project_title")
41
+ it_should_have_input_with_id("project_title")
42
+ it_should_have_input_with_type(:text)
43
+ it_should_have_input_with_name("project[title]")
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'text input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:body, :as => :text))
14
+ end
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("text")
18
+ it_should_have_input_wrapper_with_id("post_body_input")
19
+ it_should_have_label_with_text(/Body/)
20
+ it_should_have_label_for("post_body")
21
+ it_should_have_textarea_with_id("post_body")
22
+ it_should_have_textarea_with_name("post[body]")
23
+ it_should_apply_error_logic_for_input_type(:numeric)
24
+
25
+ it 'should use input_html to style inputs' do
26
+ semantic_form_for(@new_post) do |builder|
27
+ concat(builder.input(:title, :as => :text, :input_html => { :class => 'myclass' }))
28
+ end
29
+ output_buffer.should have_tag("form li textarea.myclass")
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'time input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:publish_at, :as => :time))
14
+ end
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("time")
18
+ it_should_have_input_wrapper_with_id("post_publish_at_input")
19
+ it_should_have_a_nested_fieldset
20
+ it_should_apply_error_logic_for_input_type(:time)
21
+
22
+ it 'should have a legend - classified as a label - containing the label text inside the fieldset' do
23
+ output_buffer.should have_tag('form li.time fieldset legend.label', /Publish at/)
24
+ end
25
+
26
+ it 'should have an ordered list of two items inside the fieldset' do
27
+ output_buffer.should have_tag('form li.time fieldset ol')
28
+ output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
29
+ end
30
+
31
+ it 'should have five labels for hour and minute' do
32
+ output_buffer.should have_tag('form li.time fieldset ol li label', :count => 2)
33
+ output_buffer.should have_tag('form li.time fieldset ol li label', /hour/i)
34
+ output_buffer.should have_tag('form li.time fieldset ol li label', /minute/i)
35
+ end
36
+
37
+ it 'should have two selects for hour and minute' do
38
+ output_buffer.should have_tag('form li.time fieldset ol li', :count => 2)
39
+ end
40
+
41
+ it_should_select_existing_datetime_else_current(:hour, :minute, :second)
42
+ it_should_select_explicit_default_value_if_set(:hour, :minute, :second)
43
+
44
+ end
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'time_zone input' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+
12
+ semantic_form_for(@new_post) do |builder|
13
+ concat(builder.input(:time_zone))
14
+ end
15
+ end
16
+
17
+ it_should_have_input_wrapper_with_class("time_zone")
18
+ it_should_have_input_wrapper_with_id("post_time_zone_input")
19
+ it_should_apply_error_logic_for_input_type(:time_zone)
20
+
21
+ it 'should generate a label for the input' do
22
+ output_buffer.should have_tag('form li label')
23
+ output_buffer.should have_tag('form li label[@for="post_time_zone"]')
24
+ output_buffer.should have_tag('form li label', /Time zone/)
25
+ end
26
+
27
+ it "should generate a select" do
28
+ output_buffer.should have_tag("form li select")
29
+ output_buffer.should have_tag("form li select#post_time_zone")
30
+ output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
31
+ end
32
+
33
+ it 'should use input_html to style inputs' do
34
+ semantic_form_for(@new_post) do |builder|
35
+ concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
36
+ end
37
+ output_buffer.should have_tag("form li select.myclass")
38
+ end
39
+
40
+ describe 'when no object is given' do
41
+ before(:each) do
42
+ semantic_form_for(:project, :url => 'http://test.host/') do |builder|
43
+ concat(builder.input(:time_zone, :as => :time_zone))
44
+ end
45
+ end
46
+
47
+ it 'should generate labels' do
48
+ output_buffer.should have_tag('form li label')
49
+ output_buffer.should have_tag('form li label[@for="project_time_zone"]')
50
+ output_buffer.should have_tag('form li label', /Time zone/)
51
+ end
52
+
53
+ it 'should generate select inputs' do
54
+ output_buffer.should have_tag("form li select")
55
+ output_buffer.should have_tag("form li select#project_time_zone")
56
+ output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
57
+ end
58
+ end
59
+
60
+ describe 'when :selected is set' do
61
+ before do
62
+ @output_buffer = ''
63
+ end
64
+
65
+ # Note: Not possible to override default selected value for time_zone input
66
+ # without overriding Rails time_zone_select. This Rails helper works "a bit different". =/
67
+ #
68
+ # describe "no selected items" do
69
+ # before do
70
+ # @new_post.stub!(:time_zone).and_return('Stockholm')
71
+ #
72
+ # semantic_form_for(@new_post) do |builder|
73
+ # concat(builder.input(:time_zone, :as => :time_zone, :selected => nil))
74
+ # end
75
+ # end
76
+ #
77
+ # it 'should not have any selected item(s)' do
78
+ # output_buffer.should_not have_tag("form li select option[@selected='selected']")
79
+ # end
80
+ # end
81
+
82
+ describe "single selected item" do
83
+ before do
84
+ # Note: See above...only works for the "attribute is nil" case.
85
+ # @new_post.stub!(:time_zone).and_return('Stockholm')
86
+ @new_post.stub!(:time_zone).and_return(nil)
87
+
88
+ semantic_form_for(@new_post) do |builder|
89
+ concat(builder.input(:time_zone, :as => :time_zone, :selected => 'Melbourne'))
90
+ end
91
+ end
92
+
93
+ it 'should have a selected item; the specified one' do
94
+ output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
95
+ output_buffer.should have_tag("form li select option[@selected='selected']", /Melbourne/i)
96
+ output_buffer.should have_tag("form li select option[@selected='selected'][@value='Melbourne']")
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,395 @@
1
+ # coding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe 'SemanticFormBuilder#inputs' do
5
+
6
+ include FormtasticSpecHelper
7
+
8
+ before do
9
+ @output_buffer = ''
10
+ mock_everything
11
+ end
12
+
13
+ describe 'with a block' 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
+ 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 render an ol inside the fieldset' do
35
+ output_buffer.should have_tag("form fieldset.inputs ol")
36
+ end
37
+
38
+ it 'should render the contents of the block inside the ol' do
39
+ output_buffer.should 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
+ semantic_form_for(:project, :url => 'http://test.host/') do |builder|
48
+ @inputs_output = builder.inputs do
49
+ concat('bye')
50
+ end
51
+ end
52
+
53
+ output_buffer.should have_tag("form fieldset.inputs ol", /bye/)
54
+ end
55
+ end
56
+
57
+ describe 'when a :for option is provided' do
58
+
59
+ before do
60
+ @new_post.stub!(:respond_to?).and_return(true, true)
61
+ @new_post.stub!(:author).and_return(@bob)
62
+ end
63
+
64
+ it 'should render nested inputs' do
65
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
66
+
67
+ semantic_form_for(@new_post) do |builder|
68
+ builder.inputs :for => [:author, @bob] do |bob_builder|
69
+ concat(bob_builder.input(:login))
70
+ end
71
+ end
72
+
73
+ output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
74
+ output_buffer.should_not have_tag("form fieldset.inputs #author_login")
75
+
76
+ end
77
+
78
+ describe "as a symbol representing the association name" do
79
+
80
+ it 'should nest the inputs with an _attributes suffix on the association name' do
81
+ semantic_form_for(@new_post) do |post|
82
+ post.inputs :for => :author do |author|
83
+ concat(author.input(:login))
84
+ end
85
+ end
86
+ output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
87
+ end
88
+
89
+ end
90
+
91
+ describe 'as an array containing the a symbole for the association name and the associated object' do
92
+
93
+ it 'should nest the inputs with an _attributes suffix on the association name' do
94
+ semantic_form_for(@new_post) do |post|
95
+ post.inputs :for => [:author, @new_post.author] do |author|
96
+ concat(author.input(:login))
97
+ end
98
+ end
99
+ output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
100
+ end
101
+
102
+ end
103
+
104
+ describe 'as an associated object' do
105
+
106
+ it 'should not nest the inputs with an _attributes suffix' do
107
+ semantic_form_for(@new_post) do |post|
108
+ post.inputs :for => @new_post.author do |author|
109
+ concat(author.input(:login))
110
+ end
111
+ end
112
+ output_buffer.should have_tag("form input[@name='post[author][login]']")
113
+ end
114
+
115
+ end
116
+
117
+ it 'should raise an error if :for and block with no argument is given' do
118
+ semantic_form_for(@new_post) do |builder|
119
+ proc {
120
+ builder.inputs(:for => [:author, @bob]) do
121
+ #
122
+ end
123
+ }.should raise_error(ArgumentError, 'You gave :for option with a block to inputs method, ' <<
124
+ 'but the block does not accept any argument.')
125
+ end
126
+ end
127
+
128
+ it 'should pass options down to semantic_fields_for' do
129
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
130
+
131
+ semantic_form_for(@new_post) do |builder|
132
+ builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
133
+ concat(bob_builder.input(:login))
134
+ end
135
+ end
136
+
137
+ output_buffer.should have_tag('form fieldset ol li #post_author_attributes_10_login')
138
+ end
139
+
140
+ it 'should not add builder as a fieldset attribute tag' do
141
+ semantic_form_for(@new_post) do |builder|
142
+ builder.inputs :for => [:author, @bob], :for_options => { :index => 10 } do |bob_builder|
143
+ concat('input')
144
+ end
145
+ end
146
+
147
+ output_buffer.should_not have_tag('fieldset[@builder="Formtastic::SemanticFormHelper"]')
148
+ end
149
+
150
+ it 'should send parent_builder as an option to allow child index interpolation' do
151
+ semantic_form_for(@new_post) do |builder|
152
+ builder.instance_variable_set('@nested_child_index', 0)
153
+ builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
154
+ concat('input')
155
+ end
156
+ end
157
+
158
+ output_buffer.should have_tag('fieldset legend', 'Author #1')
159
+ end
160
+
161
+ it 'should also provide child index interpolation when nested child index is a hash' do
162
+ semantic_form_for(@new_post) do |builder|
163
+ builder.instance_variable_set('@nested_child_index', :author => 10)
164
+ builder.inputs :for => [:author, @bob], :name => 'Author #%i' do |bob_builder|
165
+ concat('input')
166
+ end
167
+ end
168
+
169
+ output_buffer.should have_tag('fieldset legend', 'Author #11')
170
+ end
171
+ end
172
+
173
+ describe 'when a :name or :title option is provided' do
174
+ describe 'and is a string' do
175
+ before do
176
+ @legend_text = "Advanced options"
177
+ @legend_text_using_name = "Advanced options 2"
178
+ @legend_text_using_title = "Advanced options 3"
179
+ @nested_forms_legend_text = "This is a nested form title"
180
+ semantic_form_for(@new_post) do |builder|
181
+ builder.inputs @legend_text do
182
+ end
183
+ builder.inputs :name => @legend_text_using_name do
184
+ end
185
+ builder.inputs :title => @legend_text_using_title do
186
+ end
187
+ builder.inputs @nested_forms_legend_text, :for => :authors do |nf|
188
+ end
189
+ end
190
+ end
191
+
192
+ it 'should render a fieldset with a legend inside the form' do
193
+ output_buffer.should have_tag("form fieldset legend", /^#{@legend_text}$/)
194
+ output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_name}$/)
195
+ output_buffer.should have_tag("form fieldset legend", /^#{@legend_text_using_title}$/)
196
+ output_buffer.should have_tag("form fieldset legend", /^#{@nested_forms_legend_text}$/)
197
+ end
198
+ end
199
+
200
+ describe 'and is a symbol' do
201
+ before do
202
+ @localized_legend_text = "Localized advanced options"
203
+ @localized_legend_text_using_name = "Localized advanced options 2"
204
+ @localized_legend_text_using_title = "Localized advanced options 3"
205
+ @localized_nested_forms_legend_text = "This is a localized nested form title"
206
+ ::I18n.backend.store_translations :en, :formtastic => {
207
+ :titles => {
208
+ :post => {
209
+ :advanced_options => @localized_legend_text,
210
+ :advanced_options_using_name => @localized_legend_text_using_name,
211
+ :advanced_options_using_title => @localized_legend_text_using_title,
212
+ :nested_forms_title => @localized_nested_forms_legend_text
213
+ }
214
+ }
215
+ }
216
+ semantic_form_for(@new_post) do |builder|
217
+ builder.inputs :advanced_options do
218
+ end
219
+ builder.inputs :name => :advanced_options_using_name do
220
+ end
221
+ builder.inputs :title => :advanced_options_using_title do
222
+ end
223
+ builder.inputs :nested_forms_title, :for => :authors do |nf|
224
+ end
225
+ end
226
+ end
227
+
228
+ it 'should render a fieldset with a localized legend inside the form' do
229
+ output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text}$/)
230
+ output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_name}$/)
231
+ output_buffer.should have_tag("form fieldset legend", /^#{@localized_legend_text_using_title}$/)
232
+ output_buffer.should have_tag("form fieldset legend", /^#{@localized_nested_forms_legend_text}$/)
233
+ end
234
+ end
235
+ end
236
+
237
+ describe 'when other options are provided' do
238
+ before do
239
+ @id_option = 'advanced'
240
+ @class_option = 'wide'
241
+
242
+ semantic_form_for(@new_post) do |builder|
243
+ builder.inputs :id => @id_option, :class => @class_option do
244
+ end
245
+ end
246
+ end
247
+
248
+ it 'should pass the options into the fieldset tag as attributes' do
249
+ output_buffer.should have_tag("form fieldset##{@id_option}")
250
+ output_buffer.should have_tag("form fieldset.#{@class_option}")
251
+ end
252
+ end
253
+
254
+ end
255
+
256
+ describe 'without a block' do
257
+
258
+ before do
259
+ ::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to),
260
+ :comments => mock('reflection', :options => {}, :macro => :has_many) })
261
+ ::Author.stub!(:find).and_return([@fred, @bob])
262
+
263
+ @new_post.stub!(:title)
264
+ @new_post.stub!(:body)
265
+ @new_post.stub!(:author_id)
266
+
267
+ @new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 255))
268
+ @new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
269
+ @new_post.stub!(:column_for_attribute).with(:created_at).and_return(mock('column', :type => :datetime))
270
+ @new_post.stub!(:column_for_attribute).with(:author).and_return(nil)
271
+ end
272
+
273
+ describe 'with no args' do
274
+ before do
275
+ semantic_form_for(@new_post) do |builder|
276
+ concat(builder.inputs)
277
+ end
278
+ end
279
+
280
+ it 'should render a form' do
281
+ output_buffer.should have_tag('form')
282
+ end
283
+
284
+ it 'should render a fieldset inside the form' do
285
+ output_buffer.should have_tag('form > fieldset.inputs')
286
+ end
287
+
288
+ it 'should not render a legend in the fieldset' do
289
+ output_buffer.should_not have_tag('form > fieldset.inputs > legend')
290
+ end
291
+
292
+ it 'should render an ol in the fieldset' do
293
+ output_buffer.should have_tag('form > fieldset.inputs > ol')
294
+ end
295
+
296
+ it 'should render a list item in the ol for each column and reflection' do
297
+ # Remove the :has_many macro and :created_at column
298
+ count = ::Post.content_columns.size + ::Post.reflections.size - 2
299
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => count)
300
+ end
301
+
302
+ it 'should render a string list item for title' do
303
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
304
+ end
305
+
306
+ it 'should render a text list item for body' do
307
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
308
+ end
309
+
310
+ it 'should render a select list item for author_id' do
311
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.select', :count => 1)
312
+ end
313
+
314
+ it 'should not render timestamps inputs by default' do
315
+ output_buffer.should_not have_tag('form > fieldset.inputs > ol > li.datetime')
316
+ end
317
+ end
318
+
319
+ describe 'with column names as args' do
320
+ describe 'and an object is given' do
321
+ it 'should render a form with a fieldset containing two list items' do
322
+ semantic_form_for(@new_post) do |builder|
323
+ concat(builder.inputs(:title, :body))
324
+ end
325
+
326
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 2)
327
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.string')
328
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.text')
329
+ end
330
+ end
331
+
332
+ describe 'and no object is given' do
333
+ it 'should render a form with a fieldset containing two list items' do
334
+ semantic_form_for(:project, :url => 'http://test.host') do |builder|
335
+ concat(builder.inputs(:title, :body))
336
+ end
337
+
338
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li.string', :count => 2)
339
+ end
340
+ end
341
+ end
342
+
343
+ describe 'when a :for option is provided' do
344
+ describe 'and an object is given' do
345
+ it 'should render nested inputs' do
346
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
347
+
348
+ semantic_form_for(@new_post) do |builder|
349
+ concat(builder.inputs(:login, :for => @bob))
350
+ end
351
+
352
+ output_buffer.should have_tag("form fieldset.inputs #post_author_login")
353
+ output_buffer.should_not have_tag("form fieldset.inputs #author_login")
354
+ end
355
+ end
356
+
357
+ describe 'and no object is given' do
358
+ it 'should render nested inputs' do
359
+ semantic_form_for(:project, :url => 'http://test.host/') do |builder|
360
+ concat(builder.inputs(:login, :for => @bob))
361
+ end
362
+
363
+ output_buffer.should have_tag("form fieldset.inputs #project_author_login")
364
+ output_buffer.should_not have_tag("form fieldset.inputs #project_login")
365
+ end
366
+ end
367
+ end
368
+
369
+ describe 'with column names and an options hash as args' do
370
+ before do
371
+ semantic_form_for(@new_post) do |builder|
372
+ @legend_text_using_option = "Legendary Legend Text"
373
+ @legend_text_using_arg = "Legendary Legend Text 2"
374
+ concat(builder.inputs(:title, :body, :name => @legend_text_using_option, :id => "my-id"))
375
+ concat(builder.inputs(@legend_text_using_arg, :title, :body, :id => "my-id-2"))
376
+ end
377
+ end
378
+
379
+ it 'should render a form with a fieldset containing two list items' do
380
+ output_buffer.should have_tag('form > fieldset.inputs > ol > li', :count => 4)
381
+ end
382
+
383
+ it 'should pass the options down to the fieldset' do
384
+ output_buffer.should have_tag('form > fieldset#my-id.inputs')
385
+ end
386
+
387
+ it 'should use the special :name option as a text for the legend tag' do
388
+ output_buffer.should have_tag('form > fieldset#my-id.inputs > legend', /^#{@legend_text_using_option}$/)
389
+ output_buffer.should have_tag('form > fieldset#my-id-2.inputs > legend', /^#{@legend_text_using_arg}$/)
390
+ end
391
+ end
392
+
393
+ end
394
+
395
+ end