Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 651 lines (546 sloc) 24.681 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
55 output_buffer.should have_tag("form li label[@for='#{element_id}']")
56 end
57 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
58
4a732fd @justinfrench Spec Refactor:
authored
59 def it_should_have_input_with_id(element_id)
60 it "should have an input with id '#{element_id}'" do
61 output_buffer.should have_tag("form li input##{element_id}")
62 end
63 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
64
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
65 def it_should_have_select_with_id(element_id)
66 it "should have a select box with id '#{element_id}'" do
67 output_buffer.should have_tag("form li select##{element_id}")
68 end
69 end
70
4a732fd @justinfrench Spec Refactor:
authored
71 def it_should_have_input_with_type(input_type)
72 it "should have a #{input_type} input" do
73 output_buffer.should have_tag("form li input[@type=\"#{input_type}\"]")
74 end
75 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
76
4a732fd @justinfrench Spec Refactor:
authored
77 def it_should_have_input_with_name(name)
78 it "should have an input named #{name}" do
79 output_buffer.should have_tag("form li input[@name=\"#{name}\"]")
80 end
81 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
82
4a732fd @justinfrench Spec Refactor:
authored
83 def it_should_have_textarea_with_name(name)
84 it "should have an input named #{name}" do
85 output_buffer.should have_tag("form li textarea[@name=\"#{name}\"]")
86 end
87 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
88
4a732fd @justinfrench Spec Refactor:
authored
89 def it_should_have_textarea_with_id(element_id)
90 it "should have an input with id '#{element_id}'" do
91 output_buffer.should have_tag("form li textarea##{element_id}")
92 end
93 end
7444066 @yabawock Whitespace cleanup from HTML5 merge
yabawock authored
94
717d8e8 @asanghi full(ish) implementation of namespacing a form's id prefix; more test…
asanghi authored
95 def it_should_have_label_and_input_with_id(element_id)
96 it "should have an input with id '#{element_id}'" do
97 output_buffer.should have_tag("form li input##{element_id}")
98 output_buffer.should have_tag("form li label[@for='#{element_id}']")
99 end
100 end
101
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored
102 def it_should_use_default_text_field_size_when_not_nil(as)
103 it 'should use default_text_field_size when not nil' do
104 with_config :default_text_field_size, 30 do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
105 concat(semantic_form_for(@new_post) do |builder|
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored
106 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
107 end)
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored
108 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 a…
authored
109 end
110 end
111 end
7444066 @yabawock Whitespace cleanup from HTML5 merge
yabawock authored
112
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored
113 def it_should_not_use_default_text_field_size_when_nil(as)
114 it 'should not use default_text_field_size when nil' do
115 with_config :default_text_field_size, nil do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
116 concat(semantic_form_for(@new_post) do |builder|
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored
117 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
118 end)
b766ddc @justinfrench string|numeric|password and other basic inputs no longer add a size a…
authored
119 output_buffer.should have_tag("form li input")
120 output_buffer.should_not have_tag("form li input[@size]")
4a732fd @justinfrench Spec Refactor:
authored
121 end
122 end
123 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
124
4a732fd @justinfrench Spec Refactor:
authored
125 def it_should_apply_custom_input_attributes_when_input_html_provided(as)
126 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 s…
authored
127 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
128 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 s…
authored
129 end)
4a732fd @justinfrench Spec Refactor:
authored
130 output_buffer.should have_tag("form li input.myclass")
131 end
132 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
133
4a732fd @justinfrench Spec Refactor:
authored
134 def it_should_apply_custom_for_to_label_when_input_html_id_provided(as)
135 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 s…
authored
136 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
137 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 s…
authored
138 end)
4a732fd @justinfrench Spec Refactor:
authored
139 output_buffer.should have_tag('form li label[@for="myid"]')
140 end
141 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
142
4a732fd @justinfrench Spec Refactor:
authored
143 def it_should_have_maxlength_matching_column_limit
144 it 'should have a maxlength matching column limit' do
145 @new_post.column_for_attribute(:title).limit.should == 50
146 output_buffer.should have_tag("form li input[@maxlength='50']")
147 end
148 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
149
4a732fd @justinfrench Spec Refactor:
authored
150 def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
151 it 'should use the column size for columns shorter than default_text_field_size' do
152 column_limit_shorted_than_default = 1
153 @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => column_limit_shorted_than_default))
154
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
155 concat(semantic_form_for(@new_post) do |builder|
4a732fd @justinfrench Spec Refactor:
authored
156 concat(builder.input(:title, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
157 end)
4a732fd @justinfrench Spec Refactor:
authored
158
159 output_buffer.should have_tag("form li input[@size='#{column_limit_shorted_than_default}']")
160 end
161 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
162
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
163 def it_should_apply_error_logic_for_input_type(type)
164 describe 'when there are errors on the object for this method' do
165 before do
166 @title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
167 @errors = mock('errors')
168 @errors.stub!(:[]).with(:title).and_return(@title_errors)
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored
169 Formtastic::FormBuilder.file_metadata_suffixes.each do |suffix|
deb9f9b @asanghi automatic deduction of errors related to file type fields
asanghi authored
170 @errors.stub!(:[]).with("title_#{suffix}".to_sym).and_return(nil)
171 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
172 @new_post.stub!(:errors).and_return(@errors)
173 end
174
175 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 s…
authored
176 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
177 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
178 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
179 output_buffer.should have_tag('form li.error')
180 end
181
182 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 s…
authored
183 concat(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))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
185 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
186 output_buffer.should_not have_tag('div.fieldWithErrors')
187 end
188
189 it 'should render a paragraph for the errors' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored
190 Formtastic::FormBuilder.inline_errors = :sentence
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
191 concat(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))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
193 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
194 output_buffer.should have_tag('form li.error p.inline-errors')
195 end
196
197 it 'should not display an error list' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored
198 Formtastic::FormBuilder.inline_errors = :list
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
199 concat(semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
200 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
201 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
202 output_buffer.should have_tag('form li.error ul.errors')
203 end
204 end
205
206 describe 'when there are no errors on the object for this method' do
207 before do
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
208 @form = semantic_form_for(@new_post) do |builder|
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
209 concat(builder.input(:title, :as => type))
210 end
211 end
212
213 it 'should not apply an errors class to the list item' do
214 output_buffer.should_not have_tag('form li.error')
215 end
216
217 it 'should not render a paragraph for the errors' do
218 output_buffer.should_not have_tag('form li.error p.inline-errors')
219 end
220
221 it 'should not display an error list' do
222 output_buffer.should_not have_tag('form li.error ul.errors')
223 end
224 end
225
226 describe 'when no object is provided' do
227 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
228 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 …
authored
229 concat(builder.input(:title, :as => type))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
230 end)
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
231 end
232
233 it 'should not apply an errors class to the list item' do
234 output_buffer.should_not have_tag('form li.error')
235 end
236
237 it 'should not render a paragraph for the errors' do
238 output_buffer.should_not have_tag('form li.error p.inline-errors')
239 end
240
241 it 'should not display an error list' do
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
4134c12 @justinfrench fix a bunch of issues and failing select input specs around #where vs…
authored
249 ::Author.should_receive(:where)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
250 concat(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))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
252 end)
446e173 @justinfrench add macro for default collection logic, shifting it out of the collec…
authored
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
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
261 output_buffer.replace ''
93cd786 @justinfrench created an ugly macro for testing collections
authored
262 end
263
264 it 'should use the provided collection' do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
265 concat(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))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
267 end)
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
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
277 concat(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))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
279 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
280
281 @categories.each do |value|
282 output_buffer.should have_tag("form li.#{as}", /#{value}/)
283 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
284 end
285 end
286
287 if as == :radio
288 it 'should generate a sanitized label for attribute' do
289 @bob.stub!(:category_name).and_return(@categories)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
290 concat(semantic_form_for(@new_post) do |builder|
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
291 fields = builder.semantic_fields_for(@bob) do |bob_builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
292 concat(bob_builder.input(:category_name, :as => as, :collection => @categories))
293 end
d7a729d @yabawock Capture returns from formtastic and append them to the output_buffer …
yabawock authored
294 concat(fields)
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
295 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
296 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_general']")
297 output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_category_name_design']")
298 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
299 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
300 end
301 end
302 end
303
304 describe 'and the :collection is a hash of strings' do
305 before do
306 @categories = { 'General' => 'gen', 'Design' => 'des','Development' => 'dev' }
307 end
308
309 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 s…
authored
310 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
311 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 s…
authored
312 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
313
314 @categories.each do |label, value|
315 output_buffer.should have_tag("form li.#{as}", /#{label}/)
316 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
317 end
318 end
319 end
320
321 describe 'and the :collection is an array of arrays' do
322 before do
323 @categories = { 'General' => 'gen', 'Design' => 'des', 'Development' => 'dev' }.to_a
324 end
325
326 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 s…
authored
327 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
328 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 s…
authored
329 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
330
331 @categories.each do |text, value|
332 label = as == :select ? :option : :label
333 output_buffer.should have_tag("form li.#{as} #{label}", /#{text}/i)
334 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
335 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_#{value.to_s}") if as == :radio
336 end
337 end
338 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
339
93cd786 @justinfrench created an ugly macro for testing collections
authored
340 if as == :radio
341 describe 'and the :collection is an array of arrays with boolean values' do
342 before do
343 @choices = { 'Yeah' => true, 'Nah' => false }.to_a
344 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
345
93cd786 @justinfrench created an ugly macro for testing collections
authored
346 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 s…
authored
347 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
348 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 s…
authored
349 end)
433dae2 @yabawock Whitespace Cleanup
yabawock authored
350
93cd786 @justinfrench created an ugly macro for testing collections
authored
351 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_true")
352 output_buffer.should have_tag("form li.#{as} #{countable}#post_category_name_false")
353 end
354 end
355 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
356
93cd786 @justinfrench created an ugly macro for testing collections
authored
357 describe 'and the :collection is an array of symbols' do
358 before do
359 @categories = [ :General, :Design, :Development ]
360 end
361
362 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 s…
authored
363 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
364 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 s…
authored
365 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
366
367 @categories.each do |value|
368 label = as == :select ? :option : :label
369 output_buffer.should have_tag("form li.#{as} #{label}", /#{value}/i)
370 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value.to_s}']")
371 end
372 end
373 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
374
93cd786 @justinfrench created an ugly macro for testing collections
authored
375 describe 'and the :collection is an OrderedHash of strings' do
376 before do
377 @categories = ActiveSupport::OrderedHash.new('General' => 'gen', 'Design' => 'des','Development' => 'dev')
378 end
379
380 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 s…
authored
381 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
382 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 s…
authored
383 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
384
385 @categories.each do |label, value|
386 output_buffer.should have_tag("form li.#{as}", /#{label}/)
387 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{value}']")
388 end
389 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
390
93cd786 @justinfrench created an ugly macro for testing collections
authored
391 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
392
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
393 describe 'when the :member_label option is provided' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
394
93cd786 @justinfrench created an ugly macro for testing collections
authored
395 describe 'as a symbol' do
396 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
397 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
398 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 s…
authored
399 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
400 end
401
402 it 'should have options with text content from the specified method' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
403 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
404 output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
405 end
406 end
407 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
408
93cd786 @justinfrench created an ugly macro for testing collections
authored
409 describe 'as a proc' do
410 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
411 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
412 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 s…
authored
413 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
414 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
415
93cd786 @justinfrench created an ugly macro for testing collections
authored
416 it 'should have options with the proc applied to each' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
417 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
418 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
419 end
420 end
421 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
422
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored
423 describe 'as a method object' do
424 before do
425 def reverse_login(a)
426 a.login.reverse
427 end
428 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
429 concat(builder.input(:author, :as => as, :member_label => method(:reverse_login)))
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored
430 end)
431 end
432
433 it 'should have options with the proc applied to each' do
434 ::Author.all.each do |author|
435 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
436 end
437 end
438 end
93cd786 @justinfrench created an ugly macro for testing collections
authored
439 end
440
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
441 describe 'when the :member_label option is not provided' do
549ef7a @justinfrench Renamed all instances of Formtastic::SemanticFormBuilder to Formtasti…
authored
442 Formtastic::FormBuilder.collection_label_methods.each do |label_method|
93cd786 @justinfrench created an ugly macro for testing collections
authored
443
444 describe "when the collection objects respond to #{label_method}" do
445 before do
8fb219c @yabawock Refactor the label and value detection for collections
yabawock authored
446 @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
447 ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
93cd786 @justinfrench created an ugly macro for testing collections
authored
448
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
449 concat(semantic_form_for(@new_post) do |builder|
93cd786 @justinfrench created an ugly macro for testing collections
authored
450 concat(builder.input(:author, :as => as))
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
451 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
452 end
453
454 it "should render the options with #{label_method} as the label" do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
455 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
456 output_buffer.should have_tag("form li.#{as}", /The Label Text/)
457 end
458 end
459 end
460
461 end
462 end
463
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
464 describe 'when the :member_value option is provided' do
433dae2 @yabawock Whitespace Cleanup
yabawock authored
465
93cd786 @justinfrench created an ugly macro for testing collections
authored
466 describe 'as a symbol' do
467 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
468 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
469 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 s…
authored
470 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
471 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
472
93cd786 @justinfrench created an ugly macro for testing collections
authored
473 it 'should have options with values from specified method' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
474 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
475 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
476 end
477 end
478 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
479
93cd786 @justinfrench created an ugly macro for testing collections
authored
480 describe 'as a proc' do
481 before do
39470ee @justinfrench No need for output_buffer.concat(form) any more now that we're only s…
authored
482 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
483 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 s…
authored
484 end)
93cd786 @justinfrench created an ugly macro for testing collections
authored
485 end
486
487 it 'should have options with the proc applied to each value' do
fc663a0 @sobrinho Change all `find(:all)` to `all`
sobrinho authored
488 ::Author.all.each do |author|
93cd786 @justinfrench created an ugly macro for testing collections
authored
489 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
490 end
491 end
492 end
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored
493
494 describe 'as a method object' do
495 before do
496 def reverse_login(a)
497 a.login.reverse
498 end
499 concat(semantic_form_for(@new_post) do |builder|
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
500 concat(builder.input(:author, :as => as, :member_value => method(:reverse_login)))
40b3cd3 @bruce Support Method objects for :label_method and :value_method.
bruce authored
501 end)
502 end
503
504 it 'should have options with the proc applied to each value' do
505 ::Author.all.each do |author|
506 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
507 end
508 end
509 end
93cd786 @justinfrench created an ugly macro for testing collections
authored
510 end
511
454dd44 @justinfrench Renamed (with backwards compatibility) and deprecation notices) :labe…
authored
512 describe 'when the deprecated :label_method option is provided' do
513
514 describe 'as a symbol' do
515 before do
516 with_deprecation_silenced do
517 concat(semantic_form_for(@new_post) do |builder|
518 concat(builder.input(:author, :as => as, :label_method => :login))
519 end)
520 end
521 end
522
523 it 'should have options with text content from the specified method' do
524 ::Author.all.each do |author|
525 output_buffer.should have_tag("form li.#{as}", /#{author.login}/)
526 end
527 end
528 end
529
530 describe 'as a proc' do
531
532 before do
533 with_deprecation_silenced do
534 concat(semantic_form_for(@new_post) do |builder|
535 concat(builder.input(:author, :as => as, :label_method => Proc.new {|a| a.login.reverse }))
536 end)
537 end
538 end
539
540 it 'should have options with the proc applied to each' do
541 ::Author.all.each do |author|
542 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
543 end
544 end
545 end
546
547 describe 'as a method object' do
548 before do
549 def reverse_login(a)
550 a.login.reverse
551 end
552 with_deprecation_silenced do
553 concat(semantic_form_for(@new_post) do |builder|
554 concat(builder.input(:author, :as => as, :label_method => method(:reverse_login)))
555 end)
556 end
557 end
558
559 it 'should have options with the proc applied to each' do
560 ::Author.all.each do |author|
561 output_buffer.should have_tag("form li.#{as}", /#{author.login.reverse}/)
562 end
563 end
564 end
565 end
566
567 describe 'when the deprecated :label_method option is not provided' do
568 Formtastic::FormBuilder.collection_label_methods.each do |label_method|
569
570 describe "when the collection objects respond to #{label_method}" do
571 before do
572 @fred.stub!(:respond_to?).and_return { |m| m.to_s == label_method || m.to_s == 'id' }
573 ::Author.all.each { |a| a.stub!(label_method).and_return('The Label Text') }
574
575 with_deprecation_silenced do
576 concat(semantic_form_for(@new_post) do |builder|
577 concat(builder.input(:author, :as => as))
578 end)
579 end
580 end
581
582 it "should render the options with #{label_method} as the label" do
583 ::Author.all.each do |author|
584 output_buffer.should have_tag("form li.#{as}", /The Label Text/)
585 end
586 end
587 end
588
589 end
590 end
591
592 describe 'when the deprecated :value_method option is provided' do
593
594 describe 'as a symbol' do
595 before do
596 with_deprecation_silenced do
597 concat(semantic_form_for(@new_post) do |builder|
598 concat(builder.input(:author, :as => as, :value_method => :login))
599 end)
600 end
601 end
602
603 it 'should have options with values from specified method' do
604 ::Author.all.each do |author|
605 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login}']")
606 end
607 end
608 end
609
610 describe 'as a proc' do
611 before do
612 with_deprecation_silenced do
613 concat(semantic_form_for(@new_post) do |builder|
614 concat(builder.input(:author, :as => as, :value_method => Proc.new {|a| a.login.reverse }))
615 end)
616 end
617 end
618
619 it 'should have options with the proc applied to each value' do
620 ::Author.all.each do |author|
621 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
622 end
623 end
624 end
625
626 describe 'as a method object' do
627 before do
628 def reverse_login(a)
629 a.login.reverse
630 end
631 with_deprecation_silenced do
632 concat(semantic_form_for(@new_post) do |builder|
633 concat(builder.input(:author, :as => as, :value_method => method(:reverse_login)))
634 end)
635 end
636 end
637
638 it 'should have options with the proc applied to each value' do
639 ::Author.all.each do |author|
640 output_buffer.should have_tag("form li.#{as} #{countable}[@value='#{author.login.reverse}']")
641 end
642 end
643 end
644 end
645
93cd786 @justinfrench created an ugly macro for testing collections
authored
646 end
647 end
6859376 @justinfrench added a macro for error logic specs, which is being called in almost …
authored
648
4a732fd @justinfrench Spec Refactor:
authored
649 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
650 end
Something went wrong with that request. Please try again.