Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 494 lines (415 sloc) 20.613 kB
4a732fd @justinfrench Spec Refactor:
authored
1 module CustomMacros
2
3 def self.included(base)
4 base.extend(ClassMethods)
5 end
6
7 module ClassMethods
8
9 def it_should_have_input_wrapper_with_class(class_name)
10 it "should have input wrapper with class '#{class_name}'" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
11 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
12 output_buffer.should have_tag("form li.#{class_name}")
13 end
14 end
15
16 def it_should_have_input_wrapper_with_id(id_string)
17 it "should have input wrapper with id '#{id_string}'" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
18 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
19 output_buffer.should have_tag("form li##{id_string}")
20 end
21 end
22
23 def it_should_not_have_a_label
24 it "should not have a label" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
25 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
26 output_buffer.should_not have_tag("form li label")
27 end
28 end
29
30 def it_should_have_a_nested_fieldset
31 it "should have a nested_fieldset" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
32 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
33 output_buffer.should have_tag("form li fieldset")
34 end
35 end
36
37 def it_should_have_label_with_text(string_or_regex)
38 it "should have a label with text '#{string_or_regex}'" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
39 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
40 output_buffer.should have_tag("form li label", string_or_regex)
41 end
42 end
43
44 def it_should_have_label_for(element_id)
45 it "should have a label for ##{element_id}" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
46 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
47 output_buffer.should have_tag("form li label[@for='#{element_id}']")
48 end
49 end
50
51 def it_should_have_input_with_id(element_id)
52 it "should have an input with id '#{element_id}'" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
53 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
54 output_buffer.should have_tag("form li input##{element_id}")
55 end
56 end
57
58 def it_should_have_input_with_type(input_type)
59 it "should have a #{input_type} input" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
60 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
61 output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
62 end
63 end
64
65 def it_should_have_input_with_name(name)
66 it "should have an input named #{name}" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
67 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
68 output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
69 end
70 end
71
72 def it_should_have_textarea_with_name(name)
73 it "should have an input named #{name}" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
74 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
75 output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
76 end
77 end
78
79 def it_should_have_textarea_with_id(element_id)
80 it "should have an input with id '#{element_id}'" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
81 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
82 output_buffer.should have_tag("form li textarea##{element_id}")
83 end
84 end
85
86 def it_should_use_default_text_field_size_when_method_has_no_database_column(as)
87 it 'should use default_text_field_size when method has no database column' do
88 @new_post.stub!(:column_for_attribute).and_return(nil) # Return a nil column
c453c36 @grimen Failing spec and a "for some reason a non-working solution" for issue…
grimen authored
89
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
90 form = semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
91 concat(builder.input(:title, :as => as))
92 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
93 output_buffer.concat(form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
94 output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
95 end
96 end
97
98 def it_should_apply_custom_input_attributes_when_input_html_provided(as)
99 it 'it should apply custom input attributes when input_html provided' do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
100 form = semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
101 concat(builder.input(:title, :as => as, :input_html => { :class => 'myclass' }))
102 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
103 output_buffer.concat(form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
104 output_buffer.should have_tag("form li input.myclass")
105 end
106 end
107
108 def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
109 it 'it should apply custom for to label when input_html :id provided' do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
110 form = semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
111 concat(builder.input(:title, :as => as, :input_html => { :id => 'myid' }))
112 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
113 output_buffer.concat(form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
114 output_buffer.should have_tag('form li label[@for="myid"]')
115 end
116 end
117
118 def it_should_have_maxlength_matching_column_limit
119 it 'should have a maxlength matching column limit' do
120 @new_post.column_for_attribute(:title).limit.should == 50
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
121 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
122 output_buffer.should have_tag("form li input[@maxlength='50']")
123 end
124 end
125
126 def it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(as)
127 it 'should use default_text_field_size for columns longer than default_text_field_size' do
128 default_size = Formtastic::SemanticFormBuilder.default_text_field_size
129 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
130
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
131 form = semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
132 concat(builder.input(:title, :as => as))
133 end
134
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
135 output_buffer.concat(@form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
136 output_buffer.should have_tag("form li input[@size='#{default_size}']")
137 end
138 end
139
140 def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
141 it 'should use the column size for columns shorter than default_text_field_size' do
142 column_limit_shorted_than_default = 1
143 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
144
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
145 form = semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
146 concat(builder.input(:title, :as => as))
147 end
148
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
149 output_buffer.concat(form) if Formtastic::Util.rails3?
4a732fd @justinfrench Spec Refactor:
authored
150 output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
151 end
152 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
153
154 def it_should_apply_error_logic_for_input_type(type)
155 describe 'when there are errors on the object for this method' do
156 before do
157 @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
158 @errors = mock('errors')
159 @errors.stub!(:[]).with(:title).and_return(@title_errors)
160 @new_post.stub!(:errors).and_return(@errors)
161 end
162
163 it 'should apply an errors class to the list item' do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
164 form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
165 concat(builder.input(:title, :as => type))
166 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
167 output_buffer.concat(form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
168 output_buffer.should have_tag('form li.error')
169 end
170
171 it 'should not wrap the input with the Rails default error wrapping' do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
172 form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
173 concat(builder.input(:title, :as => type))
174 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
175 output_buffer.concat(form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
176 output_buffer.should_not have_tag('div.fieldWithErrors')
177 end
178
179 it 'should render a paragraph for the errors' do
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
180 ::Formtastic::SemanticFormBuilder.inline_errors = :sentence
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
181 form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
182 concat(builder.input(:title, :as => type))
183 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
184 output_buffer.concat(form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
185 output_buffer.should have_tag('form li.error p.inline-errors')
186 end
187
188 it 'should not display an error list' do
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
189 ::Formtastic::SemanticFormBuilder.inline_errors = :list
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
190 form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
191 concat(builder.input(:title, :as => type))
192 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
193 output_buffer.concat(form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
194 output_buffer.should have_tag('form li.error ul.errors')
195 end
196 end
197
198 describe 'when there are no errors on the object for this method' do
199 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
200 @form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
201 concat(builder.input(:title, :as => type))
202 end
203 end
204
205 it 'should not apply an errors class to the list item' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
206 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
207 output_buffer.should_not have_tag('form li.error')
208 end
209
210 it 'should not render a paragraph for the errors' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
211 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
212 output_buffer.should_not have_tag('form li.error p.inline-errors')
213 end
214
215 it 'should not display an error list' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
216 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
217 output_buffer.should_not have_tag('form li.error ul.errors')
218 end
219 end
220
221 describe 'when no object is provided' do
222 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
223 @form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
224 concat(builder.input(:title, :as => type))
225 end
226 end
227
228 it 'should not apply an errors class to the list item' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
229 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
230 output_buffer.should_not have_tag('form li.error')
231 end
232
233 it 'should not render a paragraph for the errors' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
234 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
235 output_buffer.should_not have_tag('form li.error p.inline-errors')
236 end
237
238 it 'should not display an error list' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
239 output_buffer.concat(@form) if Formtastic::Util.rails3?
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
240 output_buffer.should_not have_tag('form li.error ul.errors')
241 end
242 end
243 end
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored
244
245 def it_should_call_find_on_association_class_when_no_collection_is_provided(as)
246 it "should call find on the association class when no collection is provided" do
2f27975 @yabawock Fix testsuite to match use of :all.
yabawock authored
247 ::Author.should_receive(:all)
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
248 form = semantic_form_for(@new_post) do |builder|
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored
249 concat(builder.input(:author, :as => as))
250 end
251 end
252 end
c453c36 @grimen Failing spec and a "for some reason a non-working solution" for issue…
grimen authored
253
93cd786 @justinfrench created an ugly macro for testing collections
authored
254 def it_should_use_the_collection_when_provided(as, countable)
255 describe 'when the :collection option is provided' do
256
257 before do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
258 @authors = ::Author.all * 2
93cd786 @justinfrench created an ugly macro for testing collections
authored
259 output_buffer.replace '' # clears the output_buffer from the before block, hax!
260 end
261
262 it 'should use the provided collection' do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
263 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
264 concat(builder.input(:author, :as => as, :collection => @authors))
265 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
266 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
267 output_buffer.should have_tag("form li.#{as} #{countable}", :count => @authors.size + (as == :select ? 1 : 0))
268 end
269
270 describe 'and the :collection is an array of strings' do
271 before do
272 @categories = [ 'General', 'Design', 'Development', 'Quasi-Serious Inventions' ]
273 end
274
275 it "should use the string as the label text and value for each #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
276 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
277 concat(builder.input(:category_name, :as => as, :collection => @categories))
278 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
279 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
280
281 @categories.each do |value|
282 output_buffer.should have_tag("form li.#{as}", /#{value}/)
283 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
284 end
285 end
286
287 if as == :radio
288 it 'should generate a sanitized label for attribute' do
289 @bob.stub!(:category_name).and_return(@categories)
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
290 form = semantic_form_for(@new_post) do |builder|
291 fields = builder.semantic_fields_for(@bob) do |bob_builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
292 concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
293 end
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
294 concat(fields)
93cd786 @justinfrench created an ugly macro for testing collections
authored
295 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
296 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
297 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
298 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
299 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_development']")
300 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_quasiserious_inventions']")
301 end
302 end
303 end
304
305 describe 'and the :collection is a hash of strings' do
306 before do
307 @categories = { 'General' => 'gen', 'Design' => 'des','Development' => 'dev' }
308 end
309
310 it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
311 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
312 concat(builder.input(:category_name, :as => as, :collection => @categories))
313 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
314 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
315
316 @categories.each do |label, value|
317 output_buffer.should have_tag("form li.#{as}", /#{label}/)
318 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
319 end
320 end
321 end
322
323 describe 'and the :collection is an array of arrays' do
324 before do
325 @categories = { 'General' => 'gen', 'Design' => 'des', 'Development' => 'dev' }.to_a
326 end
327
328 it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
329 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
330 concat(builder.input(:category_name, :as => as, :collection => @categories))
331 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
332 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
333
334 @categories.each do |text, value|
335 label = as == :select ? :option : :label
336 output_buffer.should have_tag("form li.#{as} #{label}", /#{text}/i)
337 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
338 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
339 end
340 end
341 end
342
343 if as == :radio
344 describe 'and the :collection is an array of arrays with boolean values' do
345 before do
346 @choices = { 'Yeah' => true, 'Nah' => false }.to_a
347 end
348
349 it "should use the first value as the label text and the last value as the value attribute for #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
350 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
351 concat(builder.input(:category_name, :as => as, :collection => @choices))
352 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
353 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
354
355 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
356 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
357 end
358 end
359 end
360
361 describe 'and the :collection is an array of symbols' do
362 before do
363 @categories = [ :General, :Design, :Development ]
364 end
365
366 it "should use the symbol as the label text and value for each #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
367 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
368 concat(builder.input(:category_name, :as => as, :collection => @categories))
369 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
370 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
371
372 @categories.each do |value|
373 label = as == :select ? :option : :label
374 output_buffer.should have_tag("form li.#{as} #{label}", /#{value}/i)
375 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
376 end
377 end
378 end
379
380 describe 'and the :collection is an OrderedHash of strings' do
381 before do
382 @categories = ActiveSupport::OrderedHash.new('General' => 'gen', 'Design' => 'des','Development' => 'dev')
383 end
384
385 it "should use the key as the label text and the hash value as the value attribute for each #{countable}" do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
386 form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
387 concat(builder.input(:category_name, :as => as, :collection => @categories))
388 end
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
389 output_buffer.concat(form) if Formtastic::Util.rails3?
93cd786 @justinfrench created an ugly macro for testing collections
authored
390
391 @categories.each do |label, value|
392 output_buffer.should have_tag("form li.#{as}", /#{label}/)
393 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
394 end
395 end
396
397 end
398
399 describe 'when the :label_method option is provided' do
400
401 describe 'as a symbol' do
402 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
403 @form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
404 concat(builder.input(:author, :as => as, :label_method => :login))
405 end
406 end
407
408 it 'should have options with text content from the specified method' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
409 output_buffer.concat(@form) if Formtastic::Util.rails3?
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
410 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
411 output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
412 end
413 end
414 end
415
416 describe 'as a proc' do
417 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
418 @form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
419 concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
420 end
421 end
422
423 it 'should have options with the proc applied to each' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
424 output_buffer.concat(@form) if Formtastic::Util.rails3?
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
425 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
426 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
427 end
428 end
429 end
430
431 end
432
433 describe 'when the :label_method option is not provided' do
17f6668 @justinfrench Revert "This reverts commit 440bd2d8da117acdbca57fa199c115caefcd87c0."
authored
434 ::Formtastic::SemanticFormBuilder.collection_label_methods.each do |label_method|
93cd786 @justinfrench created an ugly macro for testing collections
authored
435
436 describe "when the collection objects respond to #{label_method}" do
437 before do
8fb219c @yabawock Refactor the label and value detection for collections
yabawock authored
438 @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
439 ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
93cd786 @justinfrench created an ugly macro for testing collections
authored
440
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
441 @form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
442 concat(builder.input(:author, :as => as))
443 end
444 end
445
446 it "should render the options with #{label_method} as the label" do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
447 output_buffer.concat(@form) if Formtastic::Util.rails3?
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
448 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
449 output_buffer.should have_tag("form li.#{as}", /The Label Text/)
450 end
451 end
452 end
453
454 end
455 end
456
457 describe 'when the :value_method option is provided' do
458
459 describe 'as a symbol' do
460 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
461 @form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
462 concat(builder.input(:author, :as => as, :value_method => :login))
463 end
464 end
465
466 it 'should have options with values from specified method' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
467 output_buffer.concat(@form) if Formtastic::Util.rails3?
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
468 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
469 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
470 end
471 end
472 end
473
474 describe 'as a proc' do
475 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
476 @form = semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
477 concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
478 end
479 end
480
481 it 'should have options with the proc applied to each value' do
ae3d5bc @yabawock Update spec suite to use new helper to check for rails3
yabawock authored
482 output_buffer.concat(@form) if Formtastic::Util.rails3?
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
483 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
484 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
485 end
486 end
487 end
488 end
489
490 end
491 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
492
4a732fd @justinfrench Spec Refactor:
authored
493 end
494 end
Something went wrong with that request. Please try again.