formtastic-rails3 0.9.7 → 0.9.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +23 -7
- data/Rakefile +27 -4
- data/generators/formtastic/templates/formtastic.css +9 -7
- data/generators/formtastic/templates/formtastic.rb +1 -1
- data/generators/formtastic/templates/formtastic_changes.css +4 -0
- data/lib/formtastic.rb +190 -142
- data/lib/formtastic/i18n.rb +8 -5
- data/lib/formtastic/railtie.rb +12 -0
- data/lib/formtastic/util.rb +35 -0
- data/lib/generators/formtastic/form/form_generator.rb +4 -3
- data/lib/generators/formtastic/install/install_generator.rb +2 -1
- data/rails/init.rb +5 -0
- data/spec/buttons_spec.rb +25 -8
- data/spec/commit_button_spec.rb +88 -64
- data/spec/custom_builder_spec.rb +1 -1
- data/spec/custom_macros.rb +67 -26
- data/spec/error_proc_spec.rb +1 -1
- data/spec/errors_spec.rb +21 -1
- data/spec/form_helper_spec.rb +47 -15
- data/spec/i18n_spec.rb +40 -19
- data/spec/include_blank_spec.rb +9 -5
- data/spec/input_spec.rb +224 -76
- data/spec/inputs/boolean_input_spec.rb +22 -11
- data/spec/inputs/check_boxes_input_spec.rb +103 -11
- data/spec/inputs/country_input_spec.rb +46 -8
- data/spec/inputs/date_input_spec.rb +80 -55
- data/spec/inputs/datetime_input_spec.rb +134 -83
- data/spec/inputs/file_input_spec.rb +4 -3
- data/spec/inputs/hidden_input_spec.rb +17 -3
- data/spec/inputs/numeric_input_spec.rb +3 -3
- data/spec/inputs/password_input_spec.rb +3 -3
- data/spec/inputs/radio_input_spec.rb +28 -11
- data/spec/inputs/select_input_spec.rb +122 -46
- data/spec/inputs/string_input_spec.rb +3 -3
- data/spec/inputs/text_input_spec.rb +4 -3
- data/spec/inputs/time_input_spec.rb +109 -53
- data/spec/inputs/time_zone_input_spec.rb +15 -7
- data/spec/inputs_spec.rb +85 -39
- data/spec/label_spec.rb +1 -1
- data/spec/layout_helper_spec.rb +5 -16
- data/spec/semantic_errors_spec.rb +7 -7
- data/spec/semantic_fields_for_spec.rb +5 -4
- data/spec/spec_helper.rb +102 -36
- metadata +11 -14
- data/lib/generators/formtastic/form/templates/_form.html.erb +0 -5
- data/lib/generators/formtastic/form/templates/_form.html.haml +0 -4
- data/lib/generators/formtastic/install/templates/formtastic.css +0 -144
- data/lib/generators/formtastic/install/templates/formtastic.rb +0 -58
- data/lib/generators/formtastic/install/templates/formtastic_changes.css +0 -10
- data/spec/inputs/currency_input_spec.rb +0 -80
data/spec/custom_builder_spec.rb
CHANGED
data/spec/custom_macros.rb
CHANGED
@@ -8,66 +8,77 @@ module CustomMacros
|
|
8
8
|
|
9
9
|
def it_should_have_input_wrapper_with_class(class_name)
|
10
10
|
it "should have input wrapper with class '#{class_name}'" do
|
11
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
11
12
|
output_buffer.should have_tag("form li.#{class_name}")
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
def it_should_have_input_wrapper_with_id(id_string)
|
16
17
|
it "should have input wrapper with id '#{id_string}'" do
|
18
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
17
19
|
output_buffer.should have_tag("form li##{id_string}")
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def it_should_not_have_a_label
|
22
24
|
it "should not have a label" do
|
25
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
23
26
|
output_buffer.should_not have_tag("form li label")
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
30
|
def it_should_have_a_nested_fieldset
|
28
31
|
it "should have a nested_fieldset" do
|
32
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
29
33
|
output_buffer.should have_tag("form li fieldset")
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def it_should_have_label_with_text(string_or_regex)
|
34
38
|
it "should have a label with text '#{string_or_regex}'" do
|
39
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
35
40
|
output_buffer.should have_tag("form li label", string_or_regex)
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
44
|
def it_should_have_label_for(element_id)
|
40
45
|
it "should have a label for ##{element_id}" do
|
46
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
41
47
|
output_buffer.should have_tag("form li label[@for='#{element_id}']")
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
51
|
def it_should_have_input_with_id(element_id)
|
46
52
|
it "should have an input with id '#{element_id}'" do
|
53
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
47
54
|
output_buffer.should have_tag("form li input##{element_id}")
|
48
55
|
end
|
49
56
|
end
|
50
57
|
|
51
58
|
def it_should_have_input_with_type(input_type)
|
52
59
|
it "should have a #{input_type} input" do
|
60
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
53
61
|
output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
57
65
|
def it_should_have_input_with_name(name)
|
58
66
|
it "should have an input named #{name}" do
|
67
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
59
68
|
output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
63
72
|
def it_should_have_textarea_with_name(name)
|
64
73
|
it "should have an input named #{name}" do
|
74
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
65
75
|
output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
79
|
def it_should_have_textarea_with_id(element_id)
|
70
80
|
it "should have an input with id '#{element_id}'" do
|
81
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
71
82
|
output_buffer.should have_tag("form li textarea##{element_id}")
|
72
83
|
end
|
73
84
|
end
|
@@ -76,27 +87,30 @@ module CustomMacros
|
|
76
87
|
it 'should use default_text_field_size when method has no database column' do
|
77
88
|
@new_post.stub!(:column_for_attribute).and_return(nil) # Return a nil column
|
78
89
|
|
79
|
-
semantic_form_for(@new_post) do |builder|
|
90
|
+
form = semantic_form_for(@new_post) do |builder|
|
80
91
|
concat(builder.input(:title, :as => as))
|
81
92
|
end
|
93
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
82
94
|
output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
86
98
|
def it_should_apply_custom_input_attributes_when_input_html_provided(as)
|
87
99
|
it 'it should apply custom input attributes when input_html provided' do
|
88
|
-
semantic_form_for(@new_post) do |builder|
|
100
|
+
form = semantic_form_for(@new_post) do |builder|
|
89
101
|
concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
|
90
102
|
end
|
103
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
91
104
|
output_buffer.should have_tag("form li input.myclass")
|
92
105
|
end
|
93
106
|
end
|
94
107
|
|
95
108
|
def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
|
96
109
|
it 'it should apply custom for to label when input_html :id provided' do
|
97
|
-
semantic_form_for(@new_post) do |builder|
|
110
|
+
form = semantic_form_for(@new_post) do |builder|
|
98
111
|
concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
|
99
112
|
end
|
113
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
100
114
|
output_buffer.should have_tag('form li label[@for="myid"]')
|
101
115
|
end
|
102
116
|
end
|
@@ -104,6 +118,7 @@ module CustomMacros
|
|
104
118
|
def it_should_have_maxlength_matching_column_limit
|
105
119
|
it 'should have a maxlength matching column limit' do
|
106
120
|
@new_post.column_for_attribute(:title).limit.should == 50
|
121
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
107
122
|
output_buffer.should have_tag("form li input[@maxlength='50']")
|
108
123
|
end
|
109
124
|
end
|
@@ -113,10 +128,11 @@ module CustomMacros
|
|
113
128
|
default_size = Formtastic::SemanticFormBuilder.default_text_field_size
|
114
129
|
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
|
115
130
|
|
116
|
-
semantic_form_for(@new_post) do |builder|
|
131
|
+
form = semantic_form_for(@new_post) do |builder|
|
117
132
|
concat(builder.input(:title, :as => as))
|
118
133
|
end
|
119
134
|
|
135
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
120
136
|
output_buffer.should have_tag("form li input[@size='#{default_size}']")
|
121
137
|
end
|
122
138
|
end
|
@@ -126,10 +142,11 @@ module CustomMacros
|
|
126
142
|
column_limit_shorted_than_default = 1
|
127
143
|
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
|
128
144
|
|
129
|
-
semantic_form_for(@new_post) do |builder|
|
145
|
+
form = semantic_form_for(@new_post) do |builder|
|
130
146
|
concat(builder.input(:title, :as => as))
|
131
147
|
end
|
132
148
|
|
149
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
133
150
|
output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
|
134
151
|
end
|
135
152
|
end
|
@@ -144,72 +161,82 @@ module CustomMacros
|
|
144
161
|
end
|
145
162
|
|
146
163
|
it 'should apply an errors class to the list item' do
|
147
|
-
semantic_form_for(@new_post) do |builder|
|
164
|
+
form = semantic_form_for(@new_post) do |builder|
|
148
165
|
concat(builder.input(:title, :as => type))
|
149
166
|
end
|
167
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
150
168
|
output_buffer.should have_tag('form li.error')
|
151
169
|
end
|
152
170
|
|
153
171
|
it 'should not wrap the input with the Rails default error wrapping' do
|
154
|
-
semantic_form_for(@new_post) do |builder|
|
172
|
+
form = semantic_form_for(@new_post) do |builder|
|
155
173
|
concat(builder.input(:title, :as => type))
|
156
174
|
end
|
175
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
157
176
|
output_buffer.should_not have_tag('div.fieldWithErrors')
|
158
177
|
end
|
159
178
|
|
160
179
|
it 'should render a paragraph for the errors' do
|
161
180
|
::Formtastic::SemanticFormBuilder.inline_errors = :sentence
|
162
|
-
semantic_form_for(@new_post) do |builder|
|
181
|
+
form = semantic_form_for(@new_post) do |builder|
|
163
182
|
concat(builder.input(:title, :as => type))
|
164
183
|
end
|
184
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
165
185
|
output_buffer.should have_tag('form li.error p.inline-errors')
|
166
186
|
end
|
167
187
|
|
168
188
|
it 'should not display an error list' do
|
169
189
|
::Formtastic::SemanticFormBuilder.inline_errors = :list
|
170
|
-
semantic_form_for(@new_post) do |builder|
|
190
|
+
form = semantic_form_for(@new_post) do |builder|
|
171
191
|
concat(builder.input(:title, :as => type))
|
172
192
|
end
|
193
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
173
194
|
output_buffer.should have_tag('form li.error ul.errors')
|
174
195
|
end
|
175
196
|
end
|
176
197
|
|
177
198
|
describe 'when there are no errors on the object for this method' do
|
178
199
|
before do
|
179
|
-
semantic_form_for(@new_post) do |builder|
|
200
|
+
@form = semantic_form_for(@new_post) do |builder|
|
180
201
|
concat(builder.input(:title, :as => type))
|
181
202
|
end
|
182
203
|
end
|
183
204
|
|
184
205
|
it 'should not apply an errors class to the list item' do
|
206
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
185
207
|
output_buffer.should_not have_tag('form li.error')
|
186
208
|
end
|
187
209
|
|
188
210
|
it 'should not render a paragraph for the errors' do
|
211
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
189
212
|
output_buffer.should_not have_tag('form li.error p.inline-errors')
|
190
213
|
end
|
191
214
|
|
192
215
|
it 'should not display an error list' do
|
216
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
193
217
|
output_buffer.should_not have_tag('form li.error ul.errors')
|
194
218
|
end
|
195
219
|
end
|
196
220
|
|
197
221
|
describe 'when no object is provided' do
|
198
222
|
before do
|
199
|
-
semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
223
|
+
@form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
|
200
224
|
concat(builder.input(:title, :as => type))
|
201
225
|
end
|
202
226
|
end
|
203
227
|
|
204
228
|
it 'should not apply an errors class to the list item' do
|
229
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
205
230
|
output_buffer.should_not have_tag('form li.error')
|
206
231
|
end
|
207
232
|
|
208
233
|
it 'should not render a paragraph for the errors' do
|
234
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
209
235
|
output_buffer.should_not have_tag('form li.error p.inline-errors')
|
210
236
|
end
|
211
237
|
|
212
238
|
it 'should not display an error list' do
|
239
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
213
240
|
output_buffer.should_not have_tag('form li.error ul.errors')
|
214
241
|
end
|
215
242
|
end
|
@@ -218,7 +245,7 @@ module CustomMacros
|
|
218
245
|
def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
|
219
246
|
it "should call find on the association class when no collection is provided" do
|
220
247
|
::Author.should_receive(:find)
|
221
|
-
semantic_form_for(@new_post) do |builder|
|
248
|
+
form = semantic_form_for(@new_post) do |builder|
|
222
249
|
concat(builder.input(:author, :as => as))
|
223
250
|
end
|
224
251
|
end
|
@@ -240,9 +267,10 @@ module CustomMacros
|
|
240
267
|
end
|
241
268
|
|
242
269
|
it 'should use the provided collection' do
|
243
|
-
semantic_form_for(@new_post) do |builder|
|
270
|
+
form = semantic_form_for(@new_post) do |builder|
|
244
271
|
concat(builder.input(:author, :as => as, :collection => @authors))
|
245
272
|
end
|
273
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
246
274
|
output_buffer.should have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
|
247
275
|
end
|
248
276
|
|
@@ -252,9 +280,10 @@ module CustomMacros
|
|
252
280
|
end
|
253
281
|
|
254
282
|
it "should use the string as the label text and value for each #{countable}" do
|
255
|
-
semantic_form_for(@new_post) do |builder|
|
283
|
+
form = semantic_form_for(@new_post) do |builder|
|
256
284
|
concat(builder.input(:category_name, :as => as, :collection => @categories))
|
257
285
|
end
|
286
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
258
287
|
|
259
288
|
@categories.each do |value|
|
260
289
|
output_buffer.should have_tag("form li.#{as}", /#{value}/)
|
@@ -265,11 +294,13 @@ module CustomMacros
|
|
265
294
|
if as == :radio
|
266
295
|
it 'should generate a sanitized label for attribute' do
|
267
296
|
@bob.stub!(:category_name).and_return(@categories)
|
268
|
-
semantic_form_for(@new_post) do |builder|
|
269
|
-
builder.semantic_fields_for(@bob) do |bob_builder|
|
297
|
+
form = semantic_form_for(@new_post) do |builder|
|
298
|
+
fields = builder.semantic_fields_for(@bob) do |bob_builder|
|
270
299
|
concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
|
271
300
|
end
|
301
|
+
concat(fields)
|
272
302
|
end
|
303
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
273
304
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
|
274
305
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
|
275
306
|
output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
|
@@ -284,9 +315,10 @@ module CustomMacros
|
|
284
315
|
end
|
285
316
|
|
286
317
|
it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
|
287
|
-
semantic_form_for(@new_post) do |builder|
|
318
|
+
form = semantic_form_for(@new_post) do |builder|
|
288
319
|
concat(builder.input(:category_name, :as => as, :collection => @categories))
|
289
320
|
end
|
321
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
290
322
|
|
291
323
|
@categories.each do |label, value|
|
292
324
|
output_buffer.should have_tag("form li.#{as}", /#{label}/)
|
@@ -301,9 +333,10 @@ module CustomMacros
|
|
301
333
|
end
|
302
334
|
|
303
335
|
it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
|
304
|
-
semantic_form_for(@new_post) do |builder|
|
336
|
+
form = semantic_form_for(@new_post) do |builder|
|
305
337
|
concat(builder.input(:category_name, :as => as, :collection => @categories))
|
306
338
|
end
|
339
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
307
340
|
|
308
341
|
@categories.each do |text, value|
|
309
342
|
label = as == :select ? :option : :label
|
@@ -321,9 +354,10 @@ module CustomMacros
|
|
321
354
|
end
|
322
355
|
|
323
356
|
it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
|
324
|
-
semantic_form_for(@new_post) do |builder|
|
357
|
+
form = semantic_form_for(@new_post) do |builder|
|
325
358
|
concat(builder.input(:category_name, :as => as, :collection => @choices))
|
326
359
|
end
|
360
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
327
361
|
|
328
362
|
output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
|
329
363
|
output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
|
@@ -337,9 +371,10 @@ module CustomMacros
|
|
337
371
|
end
|
338
372
|
|
339
373
|
it "should use the symbol as the label text and value for each #{countable}" do
|
340
|
-
semantic_form_for(@new_post) do |builder|
|
374
|
+
form = semantic_form_for(@new_post) do |builder|
|
341
375
|
concat(builder.input(:category_name, :as => as, :collection => @categories))
|
342
376
|
end
|
377
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
343
378
|
|
344
379
|
@categories.each do |value|
|
345
380
|
label = as == :select ? :option : :label
|
@@ -355,9 +390,10 @@ module CustomMacros
|
|
355
390
|
end
|
356
391
|
|
357
392
|
it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
|
358
|
-
semantic_form_for(@new_post) do |builder|
|
393
|
+
form = semantic_form_for(@new_post) do |builder|
|
359
394
|
concat(builder.input(:category_name, :as => as, :collection => @categories))
|
360
395
|
end
|
396
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
361
397
|
|
362
398
|
@categories.each do |label, value|
|
363
399
|
output_buffer.should have_tag("form li.#{as}", /#{label}/)
|
@@ -371,12 +407,13 @@ module CustomMacros
|
|
371
407
|
|
372
408
|
describe 'as a symbol' do
|
373
409
|
before do
|
374
|
-
semantic_form_for(@new_post) do |builder|
|
410
|
+
@form = semantic_form_for(@new_post) do |builder|
|
375
411
|
concat(builder.input(:author, :as => as, :label_method => :login))
|
376
412
|
end
|
377
413
|
end
|
378
414
|
|
379
415
|
it 'should have options with text content from the specified method' do
|
416
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
380
417
|
::Author.find(:all).each do |author|
|
381
418
|
output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
|
382
419
|
end
|
@@ -385,12 +422,13 @@ module CustomMacros
|
|
385
422
|
|
386
423
|
describe 'as a proc' do
|
387
424
|
before do
|
388
|
-
semantic_form_for(@new_post) do |builder|
|
425
|
+
@form = semantic_form_for(@new_post) do |builder|
|
389
426
|
concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
|
390
427
|
end
|
391
428
|
end
|
392
429
|
|
393
430
|
it 'should have options with the proc applied to each' do
|
431
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
394
432
|
::Author.find(:all).each do |author|
|
395
433
|
output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
|
396
434
|
end
|
@@ -407,12 +445,13 @@ module CustomMacros
|
|
407
445
|
@fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method }
|
408
446
|
::Author.find(:all).each { |a| a.stub!(label_method).and_return('The Label Text') }
|
409
447
|
|
410
|
-
semantic_form_for(@new_post) do |builder|
|
448
|
+
@form = semantic_form_for(@new_post) do |builder|
|
411
449
|
concat(builder.input(:author, :as => as))
|
412
450
|
end
|
413
451
|
end
|
414
452
|
|
415
453
|
it "should render the options with #{label_method} as the label" do
|
454
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
416
455
|
::Author.find(:all).each do |author|
|
417
456
|
output_buffer.should have_tag("form li.#{as}", /The Label Text/)
|
418
457
|
end
|
@@ -426,12 +465,13 @@ module CustomMacros
|
|
426
465
|
|
427
466
|
describe 'as a symbol' do
|
428
467
|
before do
|
429
|
-
semantic_form_for(@new_post) do |builder|
|
468
|
+
@form = semantic_form_for(@new_post) do |builder|
|
430
469
|
concat(builder.input(:author, :as => as, :value_method => :login))
|
431
470
|
end
|
432
471
|
end
|
433
472
|
|
434
473
|
it 'should have options with values from specified method' do
|
474
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
435
475
|
::Author.find(:all).each do |author|
|
436
476
|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
|
437
477
|
end
|
@@ -440,12 +480,13 @@ module CustomMacros
|
|
440
480
|
|
441
481
|
describe 'as a proc' do
|
442
482
|
before do
|
443
|
-
semantic_form_for(@new_post) do |builder|
|
483
|
+
@form = semantic_form_for(@new_post) do |builder|
|
444
484
|
concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
|
445
485
|
end
|
446
486
|
end
|
447
487
|
|
448
488
|
it 'should have options with the proc applied to each value' do
|
489
|
+
output_buffer.concat(@form) if Formtastic::Util.rails3?
|
449
490
|
::Author.find(:all).each do |author|
|
450
491
|
output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
|
451
492
|
end
|
data/spec/error_proc_spec.rb
CHANGED
data/spec/errors_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
6
6
|
include FormtasticSpecHelper
|
7
7
|
|
8
8
|
before do
|
9
|
-
@output_buffer =
|
9
|
+
@output_buffer = ''
|
10
10
|
mock_everything
|
11
11
|
@title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
|
12
12
|
@errors = mock('errors')
|
@@ -81,5 +81,25 @@ describe 'SemanticFormBuilder#errors_on' do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
|
85
|
+
describe 'when there are errors on the association and column' do
|
86
|
+
|
87
|
+
it "should list all unique errors" do
|
88
|
+
::Formtastic::SemanticFormBuilder.inline_errors = :list
|
89
|
+
::Post.stub!(:reflections).and_return({:author => mock('reflection', :options => {}, :macro => :belongs_to)})
|
90
|
+
|
91
|
+
@errors.stub!(:[]).with(:author).and_return(['must not be blank'])
|
92
|
+
@errors.stub!(:[]).with(:author_id).and_return(['is already taken', 'must not be blank']) # note the duplicate of association
|
93
|
+
|
94
|
+
form = semantic_form_for(@new_post) do |builder|
|
95
|
+
concat(builder.input(:author))
|
96
|
+
end
|
97
|
+
output_buffer.concat(form) if Formtastic::Util.rails3?
|
98
|
+
output_buffer.should have_tag("ul.errors li", /must not be blank/, :count => 1)
|
99
|
+
output_buffer.should have_tag("ul.errors li", /is already taken/, :count => 1)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
84
104
|
end
|
85
105
|
|