Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (73 sloc) 3.506 kb
0a59e0c @yabawock Always use # encoding: utf-8 declaration
yabawock authored
1 # encoding: utf-8
480e559 @yabawock Make tests use require 'spec_helper'
yabawock authored
2 require 'spec_helper'
481fe14 @justinfrench moved label spec to separate file
authored
3
4 describe 'SemanticFormBuilder#label' do
5
6 include FormtasticSpecHelper
433dae2 @yabawock Whitespace Cleanup
yabawock authored
7
481fe14 @justinfrench moved label spec to separate file
authored
8 before do
9 @output_buffer = ''
10 mock_everything
11 end
12
13 it 'should humanize the given attribute' do
14 semantic_form_for(@new_post) do |builder|
15 builder.label(:login).should have_tag('label', :with => /Login/)
16 end
17 end
18
19 describe 'when required is given' do
20 it 'should append a required note' do
21 semantic_form_for(@new_post) do |builder|
22 builder.label(:login, nil, :required => true).should have_tag('label abbr')
23 end
24 end
25
26 it 'should allow require option to be given as second argument' do
27 semantic_form_for(@new_post) do |builder|
28 builder.label(:login, :required => true).should have_tag('label abbr')
29 end
30 end
31 end
32
12029dc @yabawock Ensure :value_method gets used for collections of arrays
yabawock authored
33 describe 'when a collection is given' do
34 it 'should use a supplied label_method for simple collections' do
8b5d0ee @yabawock Update testsuite for RSpec 2.0
yabawock authored
35 form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
1420c6b @yabawock Always use supplied label_method for collection (GH-301)
yabawock authored
36 concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :value_method => :to_s, :label_method => proc {|f| ('Label_%s' % [f])}))
37 end
8b5d0ee @yabawock Update testsuite for RSpec 2.0
yabawock authored
38 output_buffer.concat(form) if Formtastic::Util.rails3?
1420c6b @yabawock Always use supplied label_method for collection (GH-301)
yabawock authored
39 output_buffer.should have_tag('form li fieldset ol li label', :with => /Label_[abc]/, :count => 3)
40 end
12029dc @yabawock Ensure :value_method gets used for collections of arrays
yabawock authored
41
42 it 'should use a supplied value_method for simple collections' do
8b5d0ee @yabawock Update testsuite for RSpec 2.0
yabawock authored
43 form = semantic_form_for(:project, :url => 'http://test.host') do |builder|
12029dc @yabawock Ensure :value_method gets used for collections of arrays
yabawock authored
44 concat(builder.input(:author_id, :as => :check_boxes, :collection => [:a, :b, :c], :value_method => proc {|f| ('Value_%s' % [f.to_s])}))
45 end
8b5d0ee @yabawock Update testsuite for RSpec 2.0
yabawock authored
46 output_buffer.concat(form) if Formtastic::Util.rails3?
12029dc @yabawock Ensure :value_method gets used for collections of arrays
yabawock authored
47 output_buffer.should have_tag('form li fieldset ol li label input[value="Value_a"]')
48 output_buffer.should have_tag('form li fieldset ol li label input[value="Value_b"]')
49 output_buffer.should have_tag('form li fieldset ol li label input[value="Value_c"]')
50 end
1420c6b @yabawock Always use supplied label_method for collection (GH-301)
yabawock authored
51 end
52
481fe14 @justinfrench moved label spec to separate file
authored
53 describe 'when label is given' do
54 it 'should allow the text to be given as label option' do
55 semantic_form_for(@new_post) do |builder|
56 builder.label(:login, :required => true, :label => 'My label').should have_tag('label', :with => /My label/)
57 end
58 end
59
60 it 'should return nil if label is false' do
61 semantic_form_for(@new_post) do |builder|
62 builder.label(:login, :label => false).should be_blank
63 end
64 end
364ae5c @yabawock HTML-escape the label strings (GH-292)
yabawock authored
65
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
66 it 'should html escape the label string by default' do
364ae5c @yabawock HTML-escape the label strings (GH-292)
yabawock authored
67 semantic_form_for(@new_post) do |builder|
68 builder.label(:login, :required => false, :label => '<b>My label</b>').should == "<label for=\"post_login\">&lt;b&gt;My label&lt;/b&gt;</label>"
69 end
70 end
2d2d813 @yabawock More intelligent way to html_escape labels and hints (GH-299)
yabawock authored
71
72 it 'should not html escape the label if configured that way' do
73 ::Formtastic::SemanticFormBuilder.escape_html_entities_in_hints_and_labels = false
74 semantic_form_for(@new_post) do |builder|
75 builder.label(:login, :required => false, :label => '<b>My label</b>').should == "<label for=\"post_login\"><b>My label</b></label>"
76 end
77 end
78
79 it 'should not html escape the label string for html_safe strings' do
80 ::Formtastic::SemanticFormBuilder.escape_html_entities_in_hints_and_labels = true
81 semantic_form_for(@new_post) do |builder|
82 builder.label(:login, :required => false, :label => '<b>My label</b>'.html_safe).should == "<label for=\"post_login\"><b>My label</b></label>"
83 end
84 end
85
481fe14 @justinfrench moved label spec to separate file
authored
86 end
433dae2 @yabawock Whitespace Cleanup
yabawock authored
87
481fe14 @justinfrench moved label spec to separate file
authored
88 end
89
Something went wrong with that request. Please try again.