formtastic-rails3 0.9.7 → 0.9.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/README.textile +23 -7
  2. data/Rakefile +27 -4
  3. data/generators/formtastic/templates/formtastic.css +9 -7
  4. data/generators/formtastic/templates/formtastic.rb +1 -1
  5. data/generators/formtastic/templates/formtastic_changes.css +4 -0
  6. data/lib/formtastic.rb +190 -142
  7. data/lib/formtastic/i18n.rb +8 -5
  8. data/lib/formtastic/railtie.rb +12 -0
  9. data/lib/formtastic/util.rb +35 -0
  10. data/lib/generators/formtastic/form/form_generator.rb +4 -3
  11. data/lib/generators/formtastic/install/install_generator.rb +2 -1
  12. data/rails/init.rb +5 -0
  13. data/spec/buttons_spec.rb +25 -8
  14. data/spec/commit_button_spec.rb +88 -64
  15. data/spec/custom_builder_spec.rb +1 -1
  16. data/spec/custom_macros.rb +67 -26
  17. data/spec/error_proc_spec.rb +1 -1
  18. data/spec/errors_spec.rb +21 -1
  19. data/spec/form_helper_spec.rb +47 -15
  20. data/spec/i18n_spec.rb +40 -19
  21. data/spec/include_blank_spec.rb +9 -5
  22. data/spec/input_spec.rb +224 -76
  23. data/spec/inputs/boolean_input_spec.rb +22 -11
  24. data/spec/inputs/check_boxes_input_spec.rb +103 -11
  25. data/spec/inputs/country_input_spec.rb +46 -8
  26. data/spec/inputs/date_input_spec.rb +80 -55
  27. data/spec/inputs/datetime_input_spec.rb +134 -83
  28. data/spec/inputs/file_input_spec.rb +4 -3
  29. data/spec/inputs/hidden_input_spec.rb +17 -3
  30. data/spec/inputs/numeric_input_spec.rb +3 -3
  31. data/spec/inputs/password_input_spec.rb +3 -3
  32. data/spec/inputs/radio_input_spec.rb +28 -11
  33. data/spec/inputs/select_input_spec.rb +122 -46
  34. data/spec/inputs/string_input_spec.rb +3 -3
  35. data/spec/inputs/text_input_spec.rb +4 -3
  36. data/spec/inputs/time_input_spec.rb +109 -53
  37. data/spec/inputs/time_zone_input_spec.rb +15 -7
  38. data/spec/inputs_spec.rb +85 -39
  39. data/spec/label_spec.rb +1 -1
  40. data/spec/layout_helper_spec.rb +5 -16
  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 +102 -36
  44. metadata +11 -14
  45. data/lib/generators/formtastic/form/templates/_form.html.erb +0 -5
  46. data/lib/generators/formtastic/form/templates/_form.html.haml +0 -4
  47. data/lib/generators/formtastic/install/templates/formtastic.css +0 -144
  48. data/lib/generators/formtastic/install/templates/formtastic.rb +0 -58
  49. data/lib/generators/formtastic/install/templates/formtastic_changes.css +0 -10
  50. data/spec/inputs/currency_input_spec.rb +0 -80
@@ -6,10 +6,10 @@ describe 'numeric input' do
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
- @output_buffer = ActiveSupport::SafeBuffer.new
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
@@ -6,10 +6,10 @@ describe 'password input' do
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
- @output_buffer = ActiveSupport::SafeBuffer.new
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
@@ -6,13 +6,13 @@ describe 'radio input' do
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
- @output_buffer = ActiveSupport::SafeBuffer.new
9
+ @output_buffer = ''
10
10
  mock_everything
11
11
  end
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^="post_author_id_"]')
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,10 +77,11 @@ 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
  end
@@ -81,20 +89,23 @@ describe 'radio input' do
81
89
  describe 'and no object is given' do
82
90
  before(:each) do
83
91
  output_buffer.replace ''
84
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
92
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
85
93
  concat(builder.input(:author_id, :as => :radio, :collection => ::Author.find(:all)))
86
94
  end
87
95
  end
88
96
 
89
97
  it 'should generate a fieldset with legend' do
98
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
90
99
  output_buffer.should have_tag('form li fieldset legend', /Author/)
91
100
  end
92
101
 
93
102
  it 'should generate an li tag for each item in the collection' do
103
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
94
104
  output_buffer.should have_tag('form li fieldset ol li', :count => ::Author.find(:all).size)
95
105
  end
96
106
 
97
107
  it 'should generate labels for each item' do
108
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
98
109
  ::Author.find(:all).each do |author|
99
110
  output_buffer.should have_tag('form li fieldset ol li label', /#{author.to_label}/)
100
111
  output_buffer.should have_tag("form li fieldset ol li label[@for='project_author_id_#{author.id}']")
@@ -102,6 +113,7 @@ describe 'radio input' do
102
113
  end
103
114
 
104
115
  it 'should generate inputs for each item' do
116
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
105
117
  ::Author.find(:all).each do |author|
106
118
  output_buffer.should have_tag("form li fieldset ol li label input#project_author_id_#{author.id}")
107
119
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio']")
@@ -114,19 +126,22 @@ describe 'radio input' do
114
126
 
115
127
  describe 'when :selected is set' do
116
128
  before do
117
- @output_buffer = ActiveSupport::SafeBuffer.new
129
+ @output_buffer = ''
118
130
  end
119
131
 
120
132
  describe "no selected items" do
121
133
  before do
122
134
  @new_post.stub!(:author_ids).and_return(nil)
123
-
124
- semantic_form_for(@new_post) do |builder|
125
- concat(builder.input(:authors, :as => :radio, :selected => nil))
135
+
136
+ with_deprecation_silenced do
137
+ @form = semantic_form_for(@new_post) do |builder|
138
+ concat(builder.input(:authors, :as => :radio, :selected => nil))
139
+ end
126
140
  end
127
141
  end
128
142
 
129
143
  it 'should not have any selected item(s)' do
144
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
130
145
  output_buffer.should_not have_tag("form li fieldset ol li label input[@checked='checked']")
131
146
  end
132
147
  end
@@ -134,13 +149,15 @@ describe 'radio input' do
134
149
  describe "single selected item" do
135
150
  before do
136
151
  @new_post.stub!(:author_ids).and_return(nil)
137
-
138
- semantic_form_for(@new_post) do |builder|
139
- concat(builder.input(:authors, :as => :radio, :selected => @fred.id))
152
+ with_deprecation_silenced do
153
+ @form = semantic_form_for(@new_post) do |builder|
154
+ concat(builder.input(:authors, :as => :radio, :selected => @fred.id))
155
+ end
140
156
  end
141
157
  end
142
158
 
143
159
  it "should have one item selected; the specified one" do
160
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
144
161
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked']", :count => 1)
145
162
  output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
146
163
  output_buffer.should have_tag("form li fieldset ol li label input[@type='radio'][@checked='checked'][@value='#{@fred.id}']")
@@ -6,7 +6,7 @@ describe 'select input' do
6
6
  include FormtasticSpecHelper
7
7
 
8
8
  before do
9
- @output_buffer = ActiveSupport::SafeBuffer.new
9
+ @output_buffer = ''
10
10
  mock_everything
11
11
  end
12
12
 
@@ -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,8 +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))
101
+ concat(builder.input(:reviewer, :as => :select))
97
102
  end
98
103
  end
99
104
 
@@ -106,36 +111,45 @@ describe 'select input' do
106
111
  it_should_use_the_collection_when_provided(:select, 'option')
107
112
 
108
113
  it 'should have a select inside the wrapper' do
114
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
109
115
  output_buffer.should have_tag('form li select')
110
116
  output_buffer.should have_tag('form li select#post_author_id')
117
+ output_buffer.should have_tag('form li select#post_reviewer_id')
111
118
  end
112
119
 
113
120
  it 'should have a valid name' do
121
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
114
122
  output_buffer.should have_tag("form li select[@name='post[author_id]']")
115
123
  output_buffer.should_not have_tag("form li select[@name='post[author_id][]']")
124
+ output_buffer.should_not have_tag("form li select[@name='post[reviewer_id][]']")
116
125
  end
117
126
 
118
127
  it 'should not create a multi-select' do
128
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
119
129
  output_buffer.should_not have_tag('form li select[@multiple]')
120
130
  end
121
131
 
122
132
  it 'should create a select without size' do
133
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
123
134
  output_buffer.should_not have_tag('form li select[@size]')
124
135
  end
125
136
 
126
137
  it 'should have a blank option' do
138
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
127
139
  output_buffer.should have_tag("form li select option[@value='']")
128
140
  end
129
141
 
130
142
  it 'should have a select option for each Author' do
131
- output_buffer.should have_tag('form li select option', :count => ::Author.find(:all).size + 1)
143
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
144
+ output_buffer.should have_tag("form li select[@name='post[author_id]'] option", :count => ::Author.find(:all).size + 1)
132
145
  ::Author.find(:all).each do |author|
133
146
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
134
147
  end
135
148
  end
136
149
 
137
150
  it 'should have one option with a "selected" attribute' do
138
- output_buffer.should have_tag('form li select option[@selected]', :count => 1)
151
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
152
+ output_buffer.should have_tag("form li select[@name='post[author_id]'] option[@selected]", :count => 1)
139
153
  end
140
154
 
141
155
  it 'should not singularize the association name' do
@@ -143,24 +157,11 @@ describe 'select input' do
143
157
  @new_post.stub!(:author_status_id).and_return(@bob.id)
144
158
  @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :integer, :limit => 255))
145
159
 
146
- semantic_form_for(@new_post) do |builder|
160
+ form = semantic_form_for(@new_post) do |builder|
147
161
  concat(builder.input(:author_status, :as => :select))
148
162
  end
149
163
 
150
- output_buffer.should have_tag('form li select#post_author_status_id')
151
- end
152
-
153
- it 'should use the "class_name" option' do
154
- @new_post.stub!(:status).and_return(@bob)
155
- @new_post.stub!(:author_status_id).and_return(@bob.id)
156
-
157
- ::Post.stub!(:reflect_on_association).with(:status).and_return(
158
- mock('reflection', :options => {:class_name => 'AuthorStatus'}, :klass => ::Author, :macro => :belongs_to))
159
-
160
- semantic_form_for(@new_post) do |builder|
161
- concat(builder.input(:status, :as => :select))
162
- end
163
-
164
+ output_buffer.concat(form) if Formtastic::Util.rails3?
164
165
  output_buffer.should have_tag('form li select#post_author_status_id')
165
166
  end
166
167
  end
@@ -176,6 +177,34 @@ describe 'select input' do
176
177
  end
177
178
  end
178
179
 
180
+ describe "for a belongs_to association with :conditions" do
181
+ before do
182
+ ::Post.stub!(:reflect_on_association).with(:author).and_return do
183
+ mock = mock('reflection', :options => {:conditions => {:active => true}}, :klass => ::Author, :macro => :belongs_to)
184
+ mock.stub!(:[]).with(:class_name).and_return("Author")
185
+ mock
186
+ end
187
+ end
188
+
189
+ it "should call author.find with association conditions" do
190
+ ::Author.should_receive(:merge_conditions).with({:active => true}, nil).and_return(:active => true)
191
+ ::Author.should_receive(:find).with(:all, :conditions => {:active => true})
192
+
193
+ semantic_form_for(@new_post) do |builder|
194
+ concat(builder.input(:author, :as => :select))
195
+ end
196
+ end
197
+
198
+ it "should call author.find with association conditions and find_options conditions" do
199
+ ::Author.should_receive(:merge_conditions).with({:active => true}, {:publisher => true}).and_return(:active => true, :publisher => true)
200
+ ::Author.should_receive(:find).with(:all, :conditions => {:active => true, :publisher => true})
201
+
202
+ semantic_form_for(@new_post) do |builder|
203
+ concat(builder.input(:author, :as => :select, :find_options => {:conditions => {:publisher => true}}))
204
+ end
205
+ end
206
+ end
207
+
179
208
  describe 'for a belongs_to association with :group_by => :continent' do
180
209
  before do
181
210
  @authors = [@bob, @fred, @fred, @fred]
@@ -193,7 +222,7 @@ describe 'select input' do
193
222
  continent.stub!(:authors).and_return([@authors[i]])
194
223
  end
195
224
 
196
- semantic_form_for(@new_post) do |builder|
225
+ @form = semantic_form_for(@new_post) do |builder|
197
226
  concat(builder.input(:author, :as => :select, :group_by => :continent ) )
198
227
  concat(builder.input(:author, :as => :select, :group_by => :continent, :group_label_method => :id ) )
199
228
  end
@@ -208,19 +237,23 @@ describe 'select input' do
208
237
 
209
238
  0.upto(1) do |i|
210
239
  it 'should have all option groups and the right values' do
240
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
211
241
  output_buffer.should have_tag("form li select optgroup[@label='#{@continent_names[i]}']", @authors[i].to_label)
212
242
  end
213
243
 
214
244
  it 'should have custom group labels' do
245
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
215
246
  output_buffer.should have_tag("form li select optgroup[@label='#{@continents[i].id}']", @authors[i].to_label)
216
247
  end
217
248
  end
218
249
 
219
250
  it 'should have no duplicate groups' do
251
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
220
252
  output_buffer.should have_tag('form li select optgroup', :count => 4)
221
253
  end
222
254
 
223
255
  it 'should sort the groups on the label method' do
256
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
224
257
  output_buffer.should have_tag("form li select optgroup[@label='Africa']")
225
258
  output_buffer.should have_tag("form li select optgroup[@label='99']")
226
259
  end
@@ -236,7 +269,7 @@ describe 'select input' do
236
269
 
237
270
  describe 'for a has_many association' do
238
271
  before do
239
- semantic_form_for(@fred) do |builder|
272
+ @form = semantic_form_for(@fred) do |builder|
240
273
  concat(builder.input(:posts, :as => :select))
241
274
  end
242
275
  end
@@ -250,15 +283,18 @@ describe 'select input' do
250
283
  it_should_use_the_collection_when_provided(:select, 'option')
251
284
 
252
285
  it 'should have a select inside the wrapper' do
286
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
253
287
  output_buffer.should have_tag('form li select')
254
288
  output_buffer.should have_tag('form li select#author_post_ids')
255
289
  end
256
290
 
257
291
  it 'should have a multi-select select' do
292
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
258
293
  output_buffer.should have_tag('form li select[@multiple="multiple"]')
259
294
  end
260
295
 
261
296
  it 'should have a select option for each Post' do
297
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
262
298
  output_buffer.should have_tag('form li select option', :count => ::Post.find(:all).size)
263
299
  ::Post.find(:all).each do |post|
264
300
  output_buffer.should have_tag("form li select option[@value='#{post.id}']", /#{post.to_label}/)
@@ -266,17 +302,19 @@ describe 'select input' do
266
302
  end
267
303
 
268
304
  it 'should not have a blank option' do
305
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
269
306
  output_buffer.should_not have_tag("form li select option[@value='']")
270
307
  end
271
308
 
272
309
  it 'should have one option with a "selected" attribute' do
310
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
273
311
  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
274
312
  end
275
313
  end
276
314
 
277
315
  describe 'for a has_and_belongs_to_many association' do
278
316
  before do
279
- semantic_form_for(@freds_post) do |builder|
317
+ @form = semantic_form_for(@freds_post) do |builder|
280
318
  concat(builder.input(:authors, :as => :select))
281
319
  end
282
320
  end
@@ -290,15 +328,18 @@ describe 'select input' do
290
328
  it_should_use_the_collection_when_provided(:select, 'option')
291
329
 
292
330
  it 'should have a select inside the wrapper' do
331
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
293
332
  output_buffer.should have_tag('form li select')
294
333
  output_buffer.should have_tag('form li select#post_author_ids')
295
334
  end
296
335
 
297
336
  it 'should have a multi-select select' do
337
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
298
338
  output_buffer.should have_tag('form li select[@multiple="multiple"]')
299
339
  end
300
340
 
301
341
  it 'should have a select option for each Author' do
342
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
302
343
  output_buffer.should have_tag('form li select option', :count => ::Author.find(:all).size)
303
344
  ::Author.find(:all).each do |author|
304
345
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
@@ -306,10 +347,12 @@ describe 'select input' do
306
347
  end
307
348
 
308
349
  it 'should not have a blank option' do
350
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
309
351
  output_buffer.should_not have_tag("form li select option[@value='']")
310
352
  end
311
353
 
312
354
  it 'should have one option with a "selected" attribute' do
355
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
313
356
  output_buffer.should have_tag('form li select option[@selected]', :count => 1)
314
357
  end
315
358
  end
@@ -317,58 +360,66 @@ describe 'select input' do
317
360
  describe 'when :prompt => "choose something" is set' do
318
361
  before do
319
362
  @new_post.stub!(:author_id).and_return(nil)
320
- semantic_form_for(@new_post) do |builder|
363
+ @form = semantic_form_for(@new_post) do |builder|
321
364
  concat(builder.input(:author, :as => :select, :prompt => "choose author"))
322
365
  end
323
366
  end
324
367
 
325
368
  it 'should have a select with prompt' do
369
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
326
370
  output_buffer.should have_tag("form li select option[@value='']", /choose author/)
327
371
  end
328
372
 
329
373
  it 'should not have a blank select option' do
374
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
330
375
  output_buffer.should_not have_tag("form li select option[@value='']", "")
331
376
  end
332
377
  end
333
378
 
334
379
  describe 'when no object is given' do
335
380
  before(:each) do
336
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
381
+ @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
337
382
  concat(builder.input(:author, :as => :select, :collection => ::Author.find(:all)))
338
383
  end
339
384
  end
340
385
 
341
386
  it 'should generate label' do
387
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
342
388
  output_buffer.should have_tag('form li label', /Author/)
343
389
  output_buffer.should have_tag("form li label[@for='project_author']")
344
390
  end
345
391
 
346
392
  it 'should generate select inputs' do
393
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
347
394
  output_buffer.should have_tag('form li select#project_author')
348
395
  output_buffer.should have_tag('form li select option', :count => ::Author.find(:all).size + 1)
349
396
  end
350
397
 
351
398
  it 'should generate an option to each item' do
399
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
352
400
  ::Author.find(:all).each do |author|
353
401
  output_buffer.should have_tag("form li select option[@value='#{author.id}']", /#{author.to_label}/)
354
402
  end
355
403
  end
356
404
  end
357
-
405
+
358
406
  describe 'when :selected is set' do
359
407
  before do
360
- @output_buffer = ActiveSupport::SafeBuffer.new
408
+ @output_buffer = ''
361
409
  end
362
410
 
363
411
  describe "no selected items" do
364
412
  before do
365
413
  @new_post.stub!(:author_id).and_return(nil)
366
- semantic_form_for(@new_post) do |builder|
367
- concat(builder.input(:author, :as => :select, :selected => nil))
414
+ with_deprecation_silenced do
415
+ @form = semantic_form_for(@new_post) do |builder|
416
+ concat(builder.input(:author, :as => :select, :selected => nil))
417
+ end
368
418
  end
369
419
  end
370
-
420
+
371
421
  it 'should not have any selected item(s)' do
422
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
372
423
  output_buffer.should_not have_tag("form li select option[@selected='selected']")
373
424
  end
374
425
  end
@@ -376,12 +427,15 @@ describe 'select input' do
376
427
  describe "single selected item" do
377
428
  before do
378
429
  @new_post.stub!(:author_id).and_return(nil)
379
- semantic_form_for(@new_post) do |builder|
380
- concat(builder.input(:author, :as => :select, :selected => @bob.id))
430
+ with_deprecation_silenced do
431
+ @form = semantic_form_for(@new_post) do |builder|
432
+ concat(builder.input(:author, :as => :select, :selected => @bob.id))
433
+ end
381
434
  end
382
435
  end
383
436
 
384
437
  it 'should have a selected item; the specified one' do
438
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
385
439
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
386
440
  output_buffer.should have_tag("form li select option[@selected='selected']", /bob/i)
387
441
  output_buffer.should have_tag("form li select option[@selected='selected'][@value='#{@bob.id}']")
@@ -394,12 +448,15 @@ describe 'select input' do
394
448
  before do
395
449
  @new_post.stub!(:author_ids).and_return(nil)
396
450
 
397
- semantic_form_for(@new_post) do |builder|
398
- concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id], :multiple => false))
451
+ with_deprecation_silenced do
452
+ @form = semantic_form_for(@new_post) do |builder|
453
+ concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id], :multiple => false))
454
+ end
399
455
  end
400
456
  end
401
457
 
402
458
  it "should only select the first value" do
459
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
403
460
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 1)
404
461
  output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected']", /bob/i)
405
462
  output_buffer.should have_tag("form li select:not([@multiple]) option[@selected='selected'][@value='#{@bob.id}']")
@@ -410,12 +467,15 @@ describe 'select input' do
410
467
  before do
411
468
  @new_post.stub!(:author_ids).and_return(nil)
412
469
 
413
- semantic_form_for(@new_post) do |builder|
414
- concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id]))
470
+ with_deprecation_silenced do
471
+ @form = semantic_form_for(@new_post) do |builder|
472
+ concat(builder.input(:authors, :as => :select, :selected => [@bob.id, @fred.id]))
473
+ end
415
474
  end
416
475
  end
417
476
 
418
477
  it "should have multiple items selected; the specified ones" do
478
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
419
479
  output_buffer.should have_tag("form li select option[@selected='selected']", :count => 2)
420
480
  output_buffer.should have_tag("form li select[@multiple] option[@selected='selected']", /bob/i)
421
481
  output_buffer.should have_tag("form li select[@multiple] option[@selected='selected'][@value='#{@bob.id}']")
@@ -427,25 +487,28 @@ describe 'select input' do
427
487
  end
428
488
 
429
489
  end
430
-
490
+
431
491
  describe "enum" do
432
492
  before do
433
- @output_buffer = ActiveSupport::SafeBuffer.new
493
+ @output_buffer = ''
434
494
  @some_meta_descriptions = ["One", "Two", "Three"]
435
495
  @new_post.stub!(:meta_description).any_number_of_times
436
496
  end
437
497
 
438
498
  describe ":as is not set" do
439
499
  before do
440
- semantic_form_for(@new_post) do |builder|
500
+ @form_new_post = semantic_form_for(@new_post) do |builder|
441
501
  concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
442
502
  end
443
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
503
+ @form_project = semantic_form_for(:project, :url => 'http://test.host') do |builder|
444
504
  concat(builder.input(:meta_description, :collection => @some_meta_descriptions))
445
505
  end
506
+
446
507
  end
447
508
 
448
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?
449
512
  output_buffer.should have_tag("form li select", :count => 2)
450
513
  end
451
514
  end
@@ -453,18 +516,31 @@ describe 'select input' do
453
516
  describe ":as is set" do
454
517
  before do
455
518
  # Should not be a case, but just checking :as got highest priority in setting input type.
456
- semantic_form_for(@new_post) do |builder|
519
+ @form_new_post = semantic_form_for(@new_post) do |builder|
457
520
  concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
458
521
  end
459
- semantic_form_for(:project, :url => 'http://test.host') do |builder|
522
+ @form_project = semantic_form_for(:project, :url => 'http://test.host') do |builder|
460
523
  concat(builder.input(:meta_description, :as => :string, :collection => @some_meta_descriptions))
461
524
  end
462
525
  end
463
526
 
464
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?
465
530
  output_buffer.should have_tag("form li input[@type='text']", :count => 2)
466
531
  end
467
532
  end
468
533
  end
469
-
534
+
535
+ it 'should warn about :selected deprecation' do
536
+ with_deprecation_silenced do
537
+ ::ActiveSupport::Deprecation.should_receive(:warn).any_number_of_times
538
+ semantic_form_for(@new_post) do |builder|
539
+ concat(builder.input(:author_id, :as => :select, :selected => @bob.id))
540
+ end
541
+ end
542
+ end
543
+
544
+
545
+
470
546
  end