|
1 |
| -shared_examples "a bootstrap form" do |
2 |
| - describe "with no options" do |
3 |
| - describe "error_messages" do |
4 |
| - it "returns empty string without errors" do |
5 |
| - @builder.error_messages.should == "" |
| 1 | +shared_examples 'a bootstrap form' do |
| 2 | + describe 'with no options' do |
| 3 | + describe 'error_messages' do |
| 4 | + it 'returns empty string without errors' do |
| 5 | + @builder.error_messages.should == '' |
6 | 6 | end
|
7 | 7 | end
|
8 | 8 |
|
9 |
| - describe "text_area" do |
| 9 | + describe 'text_area' do |
10 | 10 | before(:each) do
|
11 |
| - @result = @builder.text_area "name" |
| 11 | + @result = @builder.text_area 'name' |
12 | 12 | end
|
13 | 13 |
|
14 |
| - it "has textarea input" do |
| 14 | + it 'has textarea input' do |
15 | 15 | @result.should match /textarea/
|
16 | 16 | end
|
17 | 17 | end
|
18 | 18 |
|
19 |
| - describe "uneditable_input" do |
20 |
| - it "generates wrapped input" do |
21 |
| - @builder.uneditable_input("name").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><span class=\"uneditable-input\"></span></div></div>" |
| 19 | + describe 'uneditable_input' do |
| 20 | + it 'generates wrapped input' do |
| 21 | + @builder.uneditable_input('name').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><span class=\"uneditable-input\"></span></div></div>" |
22 | 22 | end
|
23 | 23 |
|
24 |
| - it "allows for an id" do |
25 |
| - @builder.uneditable_input("name", :id => "myid").should match /<span.*id="myid"/ |
| 24 | + it 'allows for an id' do |
| 25 | + @builder.uneditable_input('name', :id => 'myid').should match /<span.*id="myid"/ |
26 | 26 | end
|
27 | 27 | end
|
28 | 28 |
|
29 |
| - describe "check_box" do |
30 |
| - it "generates wrapped input" do |
31 |
| - @builder.check_box("name").should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" for=\"item_name\"><input name=\"item[name]\" type=\"hidden\" value=\"0\" /><input id=\"item_name\" name=\"item[name]\" type=\"checkbox\" value=\"1\" />Name</label></div></div>" |
| 29 | + describe 'check_box' do |
| 30 | + it 'generates wrapped input' do |
| 31 | + @builder.check_box('name').should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" for=\"item_name\"><input name=\"item[name]\" type=\"hidden\" value=\"0\" /><input id=\"item_name\" name=\"item[name]\" type=\"checkbox\" value=\"1\" />Name</label></div></div>" |
32 | 32 | end
|
33 | 33 |
|
34 |
| - it "allows custom label" do |
35 |
| - @builder.check_box("name", :label => "custom label").should match /custom label<\/label>/ |
| 34 | + it 'allows custom label' do |
| 35 | + @builder.check_box('name', :label => 'custom label').should match /custom label<\/label>/ |
36 | 36 | end
|
37 | 37 |
|
38 |
| - it "allows no label with :label => false " do |
39 |
| - @builder.check_box("name", :label => false).should_not match /<\/label>/ |
| 38 | + it 'allows no label with :label => false ' do |
| 39 | + @builder.check_box('name', :label => false).should_not match /<\/label>/ |
40 | 40 | end
|
41 |
| - it "allows no label with :label => '' " do |
42 |
| - @builder.check_box("name", :label => '').should_not match /<\/label>/ |
| 41 | + it 'allows no label with :label => '' ' do |
| 42 | + @builder.check_box('name', :label => '').should_not match /<\/label>/ |
43 | 43 | end
|
44 | 44 | end
|
45 | 45 |
|
46 |
| - describe "radio_buttons" do |
| 46 | + describe 'radio_buttons' do |
47 | 47 | before do
|
48 | 48 | if RUBY_VERSION < '1.9'
|
49 | 49 | @options = ActiveSupport::OrderedHash.new
|
|
54 | 54 | end
|
55 | 55 | end
|
56 | 56 |
|
57 |
| - it "doesn't use field_options from previously generated field" do |
| 57 | + it 'doesn\'t use field_options from previously generated field' do |
58 | 58 | @builder.text_field :name, :label => 'Heading', :help_inline => 'Inline help', :help_block => 'Block help'
|
59 | 59 | @builder.radio_buttons(:name, @options).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
|
60 | 60 | end
|
61 | 61 |
|
62 |
| - it "sets field_options" do |
63 |
| - @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"}) |
64 |
| - @builder.instance_variable_get("@field_options").should == {:error => nil} |
| 62 | + it 'sets field_options' do |
| 63 | + @builder.radio_buttons(:name, {'One' => '1', 'Two' => '2'}) |
| 64 | + @builder.instance_variable_get('@field_options').should == {:error => nil} |
65 | 65 | end
|
66 | 66 |
|
67 |
| - it "generates wrapped input" do |
| 67 | + it 'generates wrapped input' do |
68 | 68 | @builder.radio_buttons(:name, @options).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
|
69 | 69 | end
|
70 | 70 |
|
71 |
| - it "allows custom label" do |
72 |
| - @builder.radio_buttons(:name, @options, {:label => "custom label"}).should match /custom label<\/label>/ |
| 71 | + it 'allows custom label' do |
| 72 | + @builder.radio_buttons(:name, @options, {:label => 'custom label'}).should match /custom label<\/label>/ |
73 | 73 | end
|
74 |
| - |
75 |
| - it "allows no label" do |
| 74 | + |
| 75 | + it 'allows no label' do |
76 | 76 | @builder.radio_buttons(:name, @options, {:label => false}).should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
|
77 | 77 | end
|
78 | 78 | end
|
79 | 79 |
|
80 |
| - (%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [["telephone_field", "tel"], ["phone_field", "tel"]]).each do |field, type| |
| 80 | + (%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [['telephone_field', 'tel'], ['phone_field', 'tel']]).each do |field, type| |
81 | 81 | describe "#{field}" do
|
82 |
| - context "result" do |
| 82 | + context 'result' do |
83 | 83 | before(:each) do
|
84 |
| - @result = @builder.send(field, "name") |
| 84 | + @result = @builder.send(field, 'name') |
85 | 85 | end
|
86 | 86 |
|
87 |
| - it "is wrapped" do |
| 87 | + it 'is wrapped' do |
88 | 88 | @result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>$/
|
89 | 89 | end
|
90 | 90 |
|
|
93 | 93 | end
|
94 | 94 | end # result
|
95 | 95 |
|
96 |
| - context "call expectations" do |
| 96 | + context 'call expectations' do |
97 | 97 | %w(control_group_div label_field input_div extras).map(&:to_sym).each do |method|
|
98 | 98 | it "calls #{method}" do
|
99 | 99 | @builder.should_receive(method).and_return("")
|
100 | 100 | end
|
101 | 101 | end
|
102 | 102 |
|
103 | 103 | after(:each) do
|
104 |
| - @builder.send(field, "name") |
| 104 | + @builder.send(field, 'name') |
105 | 105 | end
|
106 | 106 | end # call expectations
|
107 | 107 |
|
108 | 108 | end # field
|
109 | 109 | end # fields
|
110 | 110 | end # no options
|
111 | 111 |
|
112 |
| - describe "extras" do |
113 |
| - context "text_field" do |
114 |
| - it "adds span for inline help" do |
| 112 | + describe 'extras' do |
| 113 | + context 'text_field' do |
| 114 | + it 'adds span for inline help' do |
115 | 115 | @builder.text_field(:name, :help_inline => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">help me!</span></div></div>"
|
116 | 116 | end
|
117 | 117 |
|
118 |
| - it "adds help block" do |
| 118 | + it 'adds help block' do |
119 | 119 | @builder.text_field(:name, :help_block => 'help me!').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><p class=\"help-block\">help me!</p></div></div>"
|
120 | 120 | end
|
121 | 121 |
|
122 |
| - it "adds error message and class" do |
| 122 | + it 'adds error message and class' do |
123 | 123 | @builder.text_field(:name, :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!</span></div></div>"
|
124 | 124 | end
|
125 | 125 |
|
126 |
| - it "adds success message and class" do |
| 126 | + it 'adds success message and class' do |
127 | 127 | @builder.text_field(:name, :success => 'This checked out OK').should == "<div class=\"control-group success\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This checked out OK</span></div></div>"
|
128 | 128 | end
|
129 | 129 |
|
130 |
| - it "adds warning message and class" do |
| 130 | + it 'adds warning message and class' do |
131 | 131 | @builder.text_field(:name, :warning => 'Take a look at this...').should == "<div class=\"control-group warning\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Take a look at this...</span></div></div>"
|
132 | 132 | end
|
133 | 133 |
|
134 |
| - it "prepends passed text" do |
| 134 | + it 'prepends passed text' do |
135 | 135 | @builder.text_field(:name, :prepend => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">@</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div></div></div>"
|
136 | 136 | end
|
137 | 137 |
|
138 |
| - it "appends passed text" do |
| 138 | + it 'appends passed text' do |
139 | 139 | @builder.text_field(:name, :append => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
|
140 | 140 | end
|
141 | 141 |
|
142 |
| - it "prepends and appends passed text" do |
| 142 | + it 'prepends and appends passed text' do |
143 | 143 | @builder.text_field(:name, :append => '@', :prepend => '#').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend input-append\"><span class=\"add-on\">\#</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
|
144 | 144 | end
|
145 | 145 | end
|
146 | 146 |
|
147 |
| - context "label option" do |
| 147 | + context 'label option' do |
148 | 148 | %w(select email_field file_field number_field password_field search_field text_area text_field url_field).each do |method_name|
|
149 |
| - |
| 149 | + |
150 | 150 | it "should not add a label when ''" do
|
151 | 151 | @builder.send(method_name.to_sym, 'name', :label => '').should_not match /<\/label>/
|
152 | 152 | end
|
153 | 153 |
|
154 |
| - it "should not add a label when false" do |
| 154 | + it 'should not add a label when false' do |
155 | 155 | @builder.send(method_name.to_sym, 'name', :label => false).should_not match /<\/label>/
|
156 | 156 | end
|
157 | 157 | end
|
158 | 158 | end
|
159 | 159 | end # extras
|
160 | 160 |
|
161 |
| - describe "form actions" do |
162 |
| - context "actions" do |
163 |
| - it "adds additional block content" do |
| 161 | + describe 'form actions' do |
| 162 | + context 'actions' do |
| 163 | + it 'adds additional block content' do |
164 | 164 | @builder.actions do
|
165 | 165 | @builder.submit
|
166 | 166 | end.should match(/<div class=\"form-actions\">.*?<\/div>/)
|
167 | 167 | end
|
168 | 168 | end
|
169 | 169 |
|
170 |
| - context "submit" do |
171 |
| - it "adds btn primary class if no class is defined" do |
| 170 | + context 'submit' do |
| 171 | + it 'adds btn primary class if no class is defined' do |
172 | 172 | @builder.submit.should match /class=\"btn btn-primary\"/
|
173 | 173 | end
|
174 | 174 |
|
175 |
| - it "allows for custom classes" do |
| 175 | + it 'allows for custom classes' do |
176 | 176 | @builder.submit(:class => 'btn btn-large btn-success').should match /class=\"btn btn-large btn-success\"/
|
177 | 177 | end
|
178 | 178 | end
|
179 | 179 |
|
180 |
| - context "button" do |
181 |
| - it "adds btn primary class if no class is defined" do |
| 180 | + context 'button' do |
| 181 | + it 'adds btn primary class if no class is defined' do |
182 | 182 | @builder.button.should match /class=\"btn btn-primary\"/
|
183 | 183 | end
|
184 | 184 |
|
185 |
| - it "allows for custom classes" do |
| 185 | + it 'allows for custom classes' do |
186 | 186 | @builder.button(:class => 'btn btn-large btn-success').should match /class=\"btn btn-large btn-success\"/
|
187 | 187 | end
|
188 | 188 | end
|
189 | 189 |
|
190 |
| - context "cancel" do |
191 |
| - it "creates a link with cancel btn class if no class is defined" do |
| 190 | + context 'cancel' do |
| 191 | + it 'creates a link with cancel btn class if no class is defined' do |
192 | 192 | @builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn cancel').and_return("")
|
193 | 193 | @builder.cancel
|
194 | 194 | end
|
195 | 195 |
|
196 |
| - it "creates a link with custom classes when defined" do |
| 196 | + it 'creates a link with custom classes when defined' do |
197 | 197 | @builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn btn-large my-cancel').and_return("")
|
198 | 198 | @builder.cancel(:class => 'btn btn-large my-cancel')
|
199 | 199 | end
|
|
0 commit comments