Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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