Skip to content

HTTPS clone URL

Subversion checkout URL

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