Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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