formtastic 1.0.1 → 1.1.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.textile +2 -2
  2. data/Rakefile +33 -8
  3. data/generators/formtastic/templates/formtastic.css +3 -18
  4. data/init.rb +5 -0
  5. data/lib/formtastic.rb +180 -82
  6. data/lib/formtastic/i18n.rb +8 -9
  7. data/lib/formtastic/layout_helper.rb +0 -1
  8. data/lib/formtastic/railtie.rb +12 -0
  9. data/lib/formtastic/util.rb +7 -0
  10. data/lib/generators/formtastic/form/form_generator.rb +86 -0
  11. data/lib/generators/formtastic/install/install_generator.rb +24 -0
  12. data/rails/init.rb +1 -6
  13. data/spec/buttons_spec.rb +25 -8
  14. data/spec/commit_button_spec.rb +67 -29
  15. data/spec/custom_builder_spec.rb +40 -4
  16. data/spec/defaults_spec.rb +1 -1
  17. data/spec/error_proc_spec.rb +1 -1
  18. data/spec/errors_spec.rb +3 -2
  19. data/spec/form_helper_spec.rb +33 -17
  20. data/spec/helpers/layout_helper_spec.rb +21 -0
  21. data/spec/i18n_spec.rb +13 -9
  22. data/spec/include_blank_spec.rb +9 -5
  23. data/spec/input_spec.rb +188 -48
  24. data/spec/inputs/boolean_input_spec.rb +14 -7
  25. data/spec/inputs/check_boxes_input_spec.rb +150 -20
  26. data/spec/inputs/country_input_spec.rb +9 -5
  27. data/spec/inputs/date_input_spec.rb +21 -9
  28. data/spec/inputs/datetime_input_spec.rb +33 -14
  29. data/spec/inputs/file_input_spec.rb +4 -3
  30. data/spec/inputs/hidden_input_spec.rb +11 -4
  31. data/spec/inputs/numeric_input_spec.rb +3 -3
  32. data/spec/inputs/password_input_spec.rb +3 -3
  33. data/spec/inputs/radio_input_spec.rb +29 -10
  34. data/spec/inputs/select_input_spec.rb +66 -26
  35. data/spec/inputs/string_input_spec.rb +5 -4
  36. data/spec/inputs/text_input_spec.rb +4 -3
  37. data/spec/inputs/time_input_spec.rb +26 -10
  38. data/spec/inputs/time_zone_input_spec.rb +11 -5
  39. data/spec/inputs_spec.rb +103 -39
  40. data/spec/label_spec.rb +5 -3
  41. data/spec/semantic_errors_spec.rb +7 -7
  42. data/spec/semantic_fields_for_spec.rb +5 -4
  43. data/spec/spec_helper.rb +86 -38
  44. data/spec/{custom_macros.rb → support/custom_macros.rb} +69 -35
  45. data/spec/support/output_buffer.rb +4 -0
  46. data/spec/support/test_environment.rb +45 -0
  47. metadata +26 -28
  48. data/spec/layout_helper_spec.rb +0 -29
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe 'numeric input' do
5
5
 
@@ -9,7 +9,7 @@ describe 'numeric input' do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
11
 
12
- semantic_form_for(@new_post) do |builder|
12
+ @form = semantic_form_for(@new_post) do |builder|
13
13
  concat(builder.input(:title, :as => :numeric))
14
14
  end
15
15
  end
@@ -28,7 +28,7 @@ describe 'numeric input' do
28
28
 
29
29
  describe "when no object is provided" do
30
30
  before do
31
- semantic_form_for(:project, :url => 'http://test.host/') do |builder|
31
+ @form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
32
32
  concat(builder.input(:title, :as => :numeric))
33
33
  end
34
34
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe 'password input' do
5
5
 
@@ -9,7 +9,7 @@ describe 'password input' do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
11
 
12
- semantic_form_for(@new_post) do |builder|
12
+ @form = semantic_form_for(@new_post) do |builder|
13
13
  concat(builder.input(:title, :as => :password))
14
14
  end
15
15
  end
@@ -31,7 +31,7 @@ describe 'password input' do
31
31
 
32
32
  describe "when no object is provided" do
33
33
  before do
34
- semantic_form_for(:project, :url => 'http://test.host/') do |builder|
34
+ @form = semantic_form_for(:project, :url => 'http://test.host/') do |builder|
35
35
  concat(builder.input(:title, :as => :password))
36
36
  end
37
37
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe 'radio input' do
5
5
 
@@ -12,7 +12,7 @@ describe 'radio input' do
12
12
 
13
13
  describe 'for belongs_to association' do
14
14
  before do
15
- semantic_form_for(@new_post) do |builder|
15
+ @form = semantic_form_for(@new_post) do |builder|
16
16
  concat(builder.input(:author, :as => :radio, :value_as_class => true))
17
17
  end
18
18
  end
@@ -24,26 +24,31 @@ describe 'radio input' do
24
24
  it_should_use_the_collection_when_provided(:radio, 'input')
25
25
 
26
26
  it 'should generate a legend containing a label with text for the input' do
27
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
27
28
  output_buffer.should have_tag('form li fieldset legend.label label')
28
29
  output_buffer.should have_tag('form li fieldset legend.label label', /Author/)
29
30
  end
30
31
 
31
32
  it 'should not link the label within the legend to any input' do
33
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
32
34
  output_buffer.should_not have_tag('form li fieldset legend label[@for]')
33
35
  end
34
36
 
35
37
  it 'should generate an ordered list with a list item for each choice' do
38
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
36
39
  output_buffer.should have_tag('form li fieldset ol')
37
40
  output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
38
41
  end
39
42
 
40
43
  it 'should have one option with a "checked" attribute' do
44
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
41
45
  output_buffer.should have_tag('form li input[@checked]', :count => 1)
42
46
  end
43
47
 
44
48
  describe "each choice" do
45
49
 
46
50
  it 'should contain a label for the radio input with a nested input and label text' do
51
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
47
52
  ::Author.find(:all).each do |author|
48
53
  output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
49
54
  output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_id_#{author.id}']")
@@ -51,12 +56,14 @@ describe 'radio input' do
51
56
  end
52
57
 
53
58
  it 'should use values as li.class when value_as_class is true' do
59
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
54
60
  ::Author.find(:all).each do |author|
55
61
  output_buffer.should have_tag("form li fieldset ol li.author_#{author.id} label")
56
62
  end
57
63
  end
58
64
 
59
65
  it "should have a radio input" do
66
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
60
67
  ::Author.find(:all).each do |author|
61
68
  output_buffer.should have_tag("form li fieldset ol li label input#post_author_id_#{author.id}")
62
69
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
@@ -70,19 +77,21 @@ describe 'radio input' do
70
77
  @new_post.author.id.should == @bob.id
71
78
  @new_post.author.should == @bob
72
79
 
73
- semantic_form_for(@new_post) do |builder|
80
+ form = semantic_form_for(@new_post) do |builder|
74
81
  concat(builder.input(:author, :as => :radio))
75
82
  end
76
83
 
84
+ output_buffer.concat(form) if Formtastic::Util.rails3?
77
85
  output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
78
86
  end
79
87
 
80
88
  it "should not contain invalid HTML attributes" do
81
89
 
82
- semantic_form_for(@new_post) do |builder|
90
+ form = semantic_form_for(@new_post) do |builder|
83
91
  concat(builder.input(:author, :as => :radio))
84
92
  end
85
93
 
94
+ output_buffer.concat(form) if Formtastic::Util.rails3?
86
95
  output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
87
96
  end
88
97
 
@@ -91,20 +100,23 @@ describe 'radio input' do
91
100
  describe 'and no object is given' do
92
101
  before(:each) do
93
102
  output_buffer.replace ''
94
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
103
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
95
104
  concat(builder.input(:author_id, :as => :radio, :collection => ::Author.find(:all)))
96
105
  end
97
106
  end
98
107
 
99
108
  it 'should generate a fieldset with legend' do
109
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
100
110
  output_buffer.should have_tag('form li fieldset legend', /Author/)
101
111
  end
102
112
 
103
113
  it 'should generate an li tag for each item in the collection' do
114
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
104
115
  output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
105
116
  end
106
117
 
107
118
  it 'should generate labels for each item' do
119
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
108
120
  ::Author.find(:all).each do |author|
109
121
  output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
110
122
  output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
@@ -113,15 +125,17 @@ describe 'radio input' do
113
125
 
114
126
  it 'should html escape the label string' do
115
127
  output_buffer.replace ''
116
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
128
+ form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
117
129
  concat(builder.input(:author_id, :as => :radio, :collection => [["<b>Item 1</b>", 1], ["<b>Item 2</b>", 2]]))
118
130
  end
131
+ output_buffer.concat(form) if Formtastic::Util.rails3?
119
132
  output_buffer.should have_tag('form li fieldset ol li label') do |label|
120
133
  label.body.should match /&lt;b&gt;Item [12]&lt;\/b&gt;$/
121
134
  end
122
135
  end
123
136
 
124
137
  it 'should generate inputs for each item' do
138
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
125
139
  ::Author.find(:all).each do |author|
126
140
  output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
127
141
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
@@ -142,13 +156,14 @@ describe 'radio input' do
142
156
  @new_post.stub!(:author_ids).and_return(nil)
143
157
 
144
158
  with_deprecation_silenced do
145
- semantic_form_for(@new_post) do |builder|
159
+ @form = semantic_form_for(@new_post) do |builder|
146
160
  concat(builder.input(:authors, :as => :radio, :selected => nil))
147
161
  end
148
162
  end
149
163
  end
150
164
 
151
165
  it 'should not have any selected item(s)' do
166
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
152
167
  output_buffer.should_not have_tag("form li fieldset ol li label input[@checked='checked']")
153
168
  end
154
169
  end
@@ -157,13 +172,14 @@ describe 'radio input' do
157
172
  before do
158
173
  @new_post.stub!(:author_ids).and_return(nil)
159
174
  with_deprecation_silenced do
160
- semantic_form_for(@new_post) do |builder|
175
+ @form = semantic_form_for(@new_post) do |builder|
161
176
  concat(builder.input(:authors, :as => :radio, :selected => @fred.id))
162
177
  end
163
178
  end
164
179
  end
165
180
 
166
181
  it "should have one item selected; the specified one" do
182
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
167
183
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked']", :count => 1)
168
184
  output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
169
185
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked'][@value='#{@fred.id}']")
@@ -179,7 +195,7 @@ describe 'radio input' do
179
195
 
180
196
  Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
181
197
  @new_post.stub!(:author_ids).and_return(nil)
182
- semantic_form_for(@new_post) do |builder|
198
+ @form = semantic_form_for(@new_post) do |builder|
183
199
  concat(builder.input(:authors, :as => :radio))
184
200
  end
185
201
  end
@@ -190,6 +206,7 @@ describe 'radio input' do
190
206
  end
191
207
 
192
208
  it "should do foo" do
209
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
193
210
  output_buffer.should have_tag("legend.label label", /Translated/)
194
211
  end
195
212
 
@@ -204,6 +221,7 @@ describe 'radio input' do
204
221
  end
205
222
 
206
223
  it "should output the correct label title" do
224
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
207
225
  output_buffer.should have_tag("legend.label label", /The authors/)
208
226
  end
209
227
  end
@@ -212,12 +230,13 @@ describe 'radio input' do
212
230
  before do
213
231
  @output_buffer = ''
214
232
  @new_post.stub!(:author_ids).and_return(nil)
215
- semantic_form_for(@new_post) do |builder|
233
+ @form = semantic_form_for(@new_post) do |builder|
216
234
  concat(builder.input(:authors, :as => :radio, :label => false))
217
235
  end
218
236
  end
219
237
 
220
238
  it "should not output the legend" do
239
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
221
240
  output_buffer.should_not have_tag("legend.label")
222
241
  end
223
242
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'spec_helper'
3
3
 
4
4
  describe 'select input' do
5
5
 
@@ -15,13 +15,14 @@ describe 'select input' do
15
15
  before do
16
16
  @array_with_values = ["Title A", "Title B", "Title C"]
17
17
  @array_with_keys_and_values = [["Title D", 1], ["Title E", 2], ["Title F", 3]]
18
- semantic_form_for(@new_post) do |builder|
18
+ @form = semantic_form_for(@new_post) do |builder|
19
19
  concat(builder.input(:title, :as => :select, :collection => @array_with_values))
20
20
  concat(builder.input(:title, :as => :select, :collection => @array_with_keys_and_values))
21
21
  end
22
22
  end
23
23
 
24
24
  it 'should have a option for each key and/or value' do
25
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
25
26
  @array_with_values.each do |v|
26
27
  output_buffer.should have_tag("form li select option[@value='#{v}']", /^#{v}$/)
27
28
  end
@@ -34,12 +35,13 @@ describe 'select input' do
34
35
  describe 'using a range' do
35
36
  before do
36
37
  @range_with_values = 1..5
37
- semantic_form_for(@new_post) do |builder|
38
+ @form = semantic_form_for(@new_post) do |builder|
38
39
  concat(builder.input(:title, :as => :select, :collection => @range_with_values))
39
40
  end
40
41
  end
41
42
 
42
43
  it 'should have an option for each value' do
44
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
43
45
  @range_with_values.each do |v|
44
46
  output_buffer.should have_tag("form li select option[@value='#{v}']", /^#{v}$/)
45
47
  end
@@ -54,7 +56,7 @@ describe 'select input' do
54
56
  ::I18n.load_path = [File.join(File.dirname(__FILE__), *%w[.. .. lib locale en.yml])]
55
57
  ::I18n.backend.send(:init_translations)
56
58
 
57
- semantic_form_for(@new_post) do |builder|
59
+ @form = semantic_form_for(@new_post) do |builder|
58
60
  concat(builder.input(:published, :as => :select))
59
61
  end
60
62
  end
@@ -64,6 +66,7 @@ describe 'select input' do
64
66
  end
65
67
 
66
68
  it 'should render a select with at least options: true/false' do
69
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
67
70
  output_buffer.should have_tag("form li select option[@value='true']", /^Yes$/)
68
71
  output_buffer.should have_tag("form li select option[@value='false']", /^No$/)
69
72
  end
@@ -74,7 +77,7 @@ describe 'select input' do
74
77
  @boolean_select_labels = {:yes => 'Yep', :no => 'Nope'}
75
78
  ::I18n.backend.store_translations :en, :formtastic => @boolean_select_labels
76
79
 
77
- semantic_form_for(@new_post) do |builder|
80
+ @form = semantic_form_for(@new_post) do |builder|
78
81
  concat(builder.input(:published, :as => :select))
79
82
  end
80
83
  end
@@ -84,6 +87,7 @@ describe 'select input' do
84
87
  end
85
88
 
86
89
  it 'should render a select with at least options: true/false' do
90
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
87
91
  output_buffer.should have_tag("form li select option[@value='true']", /#{@boolean_select_labels[:yes]}/)
88
92
  output_buffer.should have_tag("form li select option[@value='false']", /#{@boolean_select_labels[:no]}/)
89
93
  end
@@ -92,9 +96,9 @@ describe 'select input' do
92
96
 
93
97
  describe 'for a belongs_to association' do
94
98
  before do
95
- semantic_form_for(@new_post) do |builder|
99
+ @form = semantic_form_for(@new_post) do |builder|
96
100
  concat(builder.input(:author, :as => :select))
97
- concat(builder.input(:reviewer, :as => :select))
101
+ concat(builder.input(:reviewer, :as => :select))
98
102
  end
99
103
  end
100
104
 
@@ -107,30 +111,36 @@ describe 'select input' do
107
111
  it_should_use_the_collection_when_provided(:select, 'option')
108
112
 
109
113
  it 'should have a select inside the wrapper' do
114
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
110
115
  output_buffer.should have_tag('form li select')
111
116
  output_buffer.should have_tag('form li select#post_author_id')
112
- output_buffer.should have_tag('form li select#post_reviewer_id')
117
+ output_buffer.should have_tag('form li select#post_reviewer_id')
113
118
  end
114
119
 
115
120
  it 'should have a valid name' do
121
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
116
122
  output_buffer.should have_tag("form li select[@name='post[author_id]']")
117
123
  output_buffer.should_not have_tag("form li select[@name='post[author_id][]']")
118
- output_buffer.should_not have_tag("form li select[@name='post[reviewer_id][]']")
124
+ output_buffer.should_not have_tag("form li select[@name='post[reviewer_id][]']")
119
125
  end
120
126
 
121
127
  it 'should not create a multi-select' do
128
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
122
129
  output_buffer.should_not have_tag('form li select[@multiple]')
123
130
  end
124
131
 
125
132
  it 'should create a select without size' do
133
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
126
134
  output_buffer.should_not have_tag('form li select[@size]')
127
135
  end
128
136
 
129
137
  it 'should have a blank option' do
138
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
130
139
  output_buffer.should have_tag("form li select option[@value='']")
131
140
  end
132
141
 
133
142
  it 'should have a select option for each Author' do
143
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
134
144
  output_buffer.should have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.find(:all).size + 1)
135
145
  ::Author.find(:all).each do |author|
136
146
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
@@ -138,6 +148,7 @@ describe 'select input' do
138
148
  end
139
149
 
140
150
  it 'should have one option with a "selected" attribute' do
151
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
141
152
  output_buffer.should have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
142
153
  end
143
154
 
@@ -146,10 +157,11 @@ describe 'select input' do
146
157
  @new_post.stub!(:author_status_id).and_return(@bob.id)
147
158
  @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :integer, :limit => 255))
148
159
 
149
- semantic_form_for(@new_post) do |builder|
160
+ form = semantic_form_for(@new_post) do |builder|
150
161
  concat(builder.input(:author_status, :as => :select))
151
162
  end
152
163
 
164
+ output_buffer.concat(form) if Formtastic::Util.rails3?
153
165
  output_buffer.should have_tag('form li select#post_author_status_id')
154
166
  end
155
167
  end
@@ -176,7 +188,7 @@ describe 'select input' do
176
188
 
177
189
  it "should call author.find with association conditions" do
178
190
  ::Author.should_receive(:merge_conditions).with({:active => true}, nil).and_return(:active => true)
179
- ::Author.should_receive(:find).with(:all, :conditions => {:active => true})
191
+ ::Author.should_receive(:all).with(:conditions => {:active => true})
180
192
 
181
193
  semantic_form_for(@new_post) do |builder|
182
194
  concat(builder.input(:author, :as => :select))
@@ -185,7 +197,7 @@ describe 'select input' do
185
197
 
186
198
  it "should call author.find with association conditions and find_options conditions" do
187
199
  ::Author.should_receive(:merge_conditions).with({:active => true}, {:publisher => true}).and_return(:active => true, :publisher => true)
188
- ::Author.should_receive(:find).with(:all, :conditions => {:active => true, :publisher => true})
200
+ ::Author.should_receive(:all).with(:conditions => {:active => true, :publisher => true})
189
201
 
190
202
  semantic_form_for(@new_post) do |builder|
191
203
  concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
@@ -210,7 +222,7 @@ describe 'select input' do
210
222
  continent.stub!(:authors).and_return([@authors[i]])
211
223
  end
212
224
 
213
- semantic_form_for(@new_post) do |builder|
225
+ @form = semantic_form_for(@new_post) do |builder|
214
226
  concat(builder.input(:author, :as => :select, :group_by => :continent ) )
215
227
  concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label_method => :id ) )
216
228
  end
@@ -225,25 +237,29 @@ describe 'select input' do
225
237
 
226
238
  0.upto(1) do |i|
227
239
  it 'should have all option groups and the right values' do
240
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
228
241
  output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
229
242
  end
230
243
 
231
244
  it 'should have custom group labels' do
245
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
232
246
  output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
233
247
  end
234
248
  end
235
249
 
236
250
  it 'should have no duplicate groups' do
251
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
237
252
  output_buffer.should have_tag('form li select optgroup', :count => 4)
238
253
  end
239
254
 
240
255
  it 'should sort the groups on the label method' do
256
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
241
257
  output_buffer.should have_tag("form li select optgroup[@label='Africa']")
242
258
  output_buffer.should have_tag("form li select optgroup[@label='99']")
243
259
  end
244
260
 
245
261
  it 'should call find with :include for more optimized queries' do
246
- Author.should_receive(:find).with(:all, :include => :continent)
262
+ Author.should_receive(:all).with(:include => :continent)
247
263
 
248
264
  semantic_form_for(@new_post) do |builder|
249
265
  concat(builder.input(:author, :as => :select, :group_by => :continent ) )
@@ -253,7 +269,7 @@ describe 'select input' do
253
269
 
254
270
  describe 'for a has_many association' do
255
271
  before do
256
- semantic_form_for(@fred) do |builder|
272
+ @form = semantic_form_for(@fred) do |builder|
257
273
  concat(builder.input(:posts, :as => :select))
258
274
  end
259
275
  end
@@ -267,15 +283,18 @@ describe 'select input' do
267
283
  it_should_use_the_collection_when_provided(:select, 'option')
268
284
 
269
285
  it 'should have a select inside the wrapper' do
286
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
270
287
  output_buffer.should have_tag('form li select')
271
288
  output_buffer.should have_tag('form li select#author_post_ids')
272
289
  end
273
290
 
274
291
  it 'should have a multi-select select' do
292
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
275
293
  output_buffer.should have_tag('form li select[@multiple="multiple"]')
276
294
  end
277
295
 
278
296
  it 'should have a select option for each Post' do
297
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
279
298
  output_buffer.should have_tag('form li select option', :count => ::Post.find(:all).size)
280
299
  ::Post.find(:all).each do |post|
281
300
  output_buffer.should have_tag("form li select option[@value='#{post.id}']", /#{post.to_label}/)
@@ -283,17 +302,19 @@ describe 'select input' do
283
302
  end
284
303
 
285
304
  it 'should not have a blank option' do
305
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
286
306
  output_buffer.should_not have_tag("form li select option[@value='']")
287
307
  end
288
308
 
289
309
  it 'should have one option with a "selected" attribute' do
310
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
290
311
  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
291
312
  end
292
313
  end
293
314
 
294
315
  describe 'for a has_and_belongs_to_many association' do
295
316
  before do
296
- semantic_form_for(@freds_post) do |builder|
317
+ @form = semantic_form_for(@freds_post) do |builder|
297
318
  concat(builder.input(:authors, :as => :select))
298
319
  end
299
320
  end
@@ -307,15 +328,18 @@ describe 'select input' do
307
328
  it_should_use_the_collection_when_provided(:select, 'option')
308
329
 
309
330
  it 'should have a select inside the wrapper' do
331
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
310
332
  output_buffer.should have_tag('form li select')
311
333
  output_buffer.should have_tag('form li select#post_author_ids')
312
334
  end
313
335
 
314
336
  it 'should have a multi-select select' do
337
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
315
338
  output_buffer.should have_tag('form li select[@multiple="multiple"]')
316
339
  end
317
340
 
318
341
  it 'should have a select option for each Author' do
342
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
319
343
  output_buffer.should have_tag('form li select option', :count => ::Author.find(:all).size)
320
344
  ::Author.find(:all).each do |author|
321
345
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
@@ -323,10 +347,12 @@ describe 'select input' do
323
347
  end
324
348
 
325
349
  it 'should not have a blank option' do
350
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
326
351
  output_buffer.should_not have_tag("form li select option[@value='']")
327
352
  end
328
353
 
329
354
  it 'should have one option with a "selected" attribute' do
355
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
330
356
  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
331
357
  end
332
358
  end
@@ -334,38 +360,43 @@ describe 'select input' do
334
360
  describe 'when :prompt => "choose something" is set' do
335
361
  before do
336
362
  @new_post.stub!(:author_id).and_return(nil)
337
- semantic_form_for(@new_post) do |builder|
363
+ @form = semantic_form_for(@new_post) do |builder|
338
364
  concat(builder.input(:author, :as => :select, :prompt => "choose author"))
339
365
  end
340
366
  end
341
367
 
342
368
  it 'should have a select with prompt' do
369
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
343
370
  output_buffer.should have_tag("form li select option[@value='']", /choose author/)
344
371
  end
345
372
 
346
373
  it 'should not have a blank select option' do
374
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
347
375
  output_buffer.should_not have_tag("form li select option[@value='']", "")
348
376
  end
349
377
  end
350
378
 
351
379
  describe 'when no object is given' do
352
380
  before(:each) do
353
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
381
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
354
382
  concat(builder.input(:author, :as => :select, :collection => ::Author.find(:all)))
355
383
  end
356
384
  end
357
385
 
358
386
  it 'should generate label' do
387
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
359
388
  output_buffer.should have_tag('form li label', /Author/)
360
389
  output_buffer.should have_tag("form li label[@for='project_author']")
361
390
  end
362
391
 
363
392
  it 'should generate select inputs' do
393
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
364
394
  output_buffer.should have_tag('form li select#project_author')
365
395
  output_buffer.should have_tag('form li select option', :count => ::Author.find(:all).size + 1)
366
396
  end
367
397
 
368
398
  it 'should generate an option to each item' do
399
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
369
400
  ::Author.find(:all).each do |author|
370
401
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
371
402
  end
@@ -381,13 +412,14 @@ describe 'select input' do
381
412
  before do
382
413
  @new_post.stub!(:author_id).and_return(nil)
383
414
  with_deprecation_silenced do
384
- semantic_form_for(@new_post) do |builder|
415
+ @form = semantic_form_for(@new_post) do |builder|
385
416
  concat(builder.input(:author, :as => :select, :selected => nil))
386
417
  end
387
418
  end
388
419
  end
389
420
 
390
421
  it 'should not have any selected item(s)' do
422
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
391
423
  output_buffer.should_not have_tag("form li select option[@selected='selected']")
392
424
  end
393
425
  end
@@ -396,13 +428,14 @@ describe 'select input' do
396
428
  before do
397
429
  @new_post.stub!(:author_id).and_return(nil)
398
430
  with_deprecation_silenced do
399
- semantic_form_for(@new_post) do |builder|
431
+ @form = semantic_form_for(@new_post) do |builder|
400
432
  concat(builder.input(:author, :as => :select, :selected => @bob.id))
401
433
  end
402
434
  end
403
435
  end
404
436
 
405
437
  it 'should have a selected item; the specified one' do
438
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
406
439
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
407
440
  output_buffer.should have_tag("form li select option[@selected='selected']", /bob/i)
408
441
  output_buffer.should have_tag("form li select option[@selected='selected'][@value='#{@bob.id}']")
@@ -416,13 +449,14 @@ describe 'select input' do
416
449
  @new_post.stub!(:author_ids).and_return(nil)
417
450
 
418
451
  with_deprecation_silenced do
419
- semantic_form_for(@new_post) do |builder|
452
+ @form = semantic_form_for(@new_post) do |builder|
420
453
  concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id], :multiple => false))
421
454
  end
422
455
  end
423
456
  end
424
457
 
425
458
  it "should only select the first value" do
459
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
426
460
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
427
461
  output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected']", /bob/i)
428
462
  output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected'][@value='#{@bob.id}']")
@@ -434,13 +468,14 @@ describe 'select input' do
434
468
  @new_post.stub!(:author_ids).and_return(nil)
435
469
 
436
470
  with_deprecation_silenced do
437
- semantic_form_for(@new_post) do |builder|
471
+ @form = semantic_form_for(@new_post) do |builder|
438
472
  concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id]))
439
473
  end
440
474
  end
441
475
  end
442
476
 
443
477
  it "should have multiple items selected; the specified ones" do
478
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
444
479
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 2)
445
480
  output_buffer.should have_tag("form li select[@multiple] option[@selected='selected']", /bob/i)
446
481
  output_buffer.should have_tag("form li select[@multiple] option[@selected='selected'][@value='#{@bob.id}']")
@@ -462,15 +497,18 @@ describe 'select input' do
462
497
 
463
498
  describe ":as is not set" do
464
499
  before do
465
- semantic_form_for(@new_post) do |builder|
500
+ @form_new_post = semantic_form_for(@new_post) do |builder|
466
501
  concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
467
502
  end
468
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
503
+ @form_project = semantic_form_for(:project, :url => 'http://test.host') do |builder|
469
504
  concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
470
505
  end
506
+
471
507
  end
472
508
 
473
509
  it "should render a select field" do
510
+ output_buffer.concat(@form_new_post) if Formtastic::Util.rails3?
511
+ output_buffer.concat(@form_project) if Formtastic::Util.rails3?
474
512
  output_buffer.should have_tag("form li select", :count => 2)
475
513
  end
476
514
  end
@@ -478,15 +516,17 @@ describe 'select input' do
478
516
  describe ":as is set" do
479
517
  before do
480
518
  # Should not be a case, but just checking :as got highest priority in setting input type.
481
- semantic_form_for(@new_post) do |builder|
519
+ @form_new_post = semantic_form_for(@new_post) do |builder|
482
520
  concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
483
521
  end
484
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
522
+ @form_project = semantic_form_for(:project, :url => 'http://test.host') do |builder|
485
523
  concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
486
524
  end
487
525
  end
488
526
 
489
527
  it "should render a text field" do
528
+ output_buffer.concat(@form_new_post) if Formtastic::Util.rails3?
529
+ output_buffer.concat(@form_project) if Formtastic::Util.rails3?
490
530
  output_buffer.should have_tag("form li input[@type='text']", :count => 2)
491
531
  end
492
532
  end