Skip to content

HTTPS clone URL

Subversion checkout URL

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