bootstrap_form 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,218 @@
1
+ require 'test_helper'
2
+
3
+ class BootstrapFormGroupTest < ActionView::TestCase
4
+ include BootstrapForm::Helper
5
+
6
+ def setup
7
+ setup_test_fixture
8
+ end
9
+
10
+ test "changing the label text" do
11
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
12
+ assert_equal expected, @builder.text_field(:email, label: 'Email Address')
13
+ end
14
+
15
+ test "hiding a label" do
16
+ expected = %{<div class="form-group"><label class="sr-only control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
17
+ assert_equal expected, @builder.text_field(:email, hide_label: true)
18
+ end
19
+
20
+ test "adding prepend text" do
21
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><span class="input-group-addon">@</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
22
+ assert_equal expected, @builder.text_field(:email, prepend: '@')
23
+ end
24
+
25
+ test "adding append text" do
26
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
27
+ assert_equal expected, @builder.text_field(:email, append: '.00')
28
+ end
29
+
30
+ test "append and prepend button" do
31
+ prefix = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group">}
32
+ field = %{<input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" />}
33
+ button = %{<span class="input-group-btn"><a class="btn btn-default" href="#">Click</a></span>}
34
+ suffix = %{</div></div>}
35
+ after_button = prefix + field + button + suffix
36
+ before_button = prefix + button + field + suffix
37
+ both_button = prefix + button + field + button + suffix
38
+ button_src = link_to("Click", "#", class: "btn btn-default")
39
+ assert_equal after_button, @builder.text_field(:email, append: button_src)
40
+ assert_equal before_button, @builder.text_field(:email, prepend: button_src)
41
+ assert_equal both_button, @builder.text_field(:email, append: button_src, prepend: button_src)
42
+ end
43
+
44
+ test "adding both prepend and append text" do
45
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><span class="input-group-addon">$</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
46
+ assert_equal expected, @builder.text_field(:email, prepend: '$', append: '.00')
47
+ end
48
+
49
+ test "help messages for default forms" do
50
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="help-block">This is required</span></div>}
51
+ assert_equal expected, @builder.text_field(:email, help: 'This is required')
52
+ end
53
+
54
+ test "help messages for horizontal forms" do
55
+ expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="help-block">This is required</span></div></div>}
56
+ assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required")
57
+ end
58
+
59
+ test "help messages to look up I18n automatically" do
60
+ expected = %{<div class="form-group"><label class="control-label" for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="text" value="secret" /><span class="help-block">A good password should be at least six characters long</span></div>}
61
+ assert_equal expected, @builder.text_field(:password)
62
+ end
63
+
64
+ test "help messages to ignore translation when user disables help" do
65
+ expected = %{<div class="form-group"><label class="control-label" for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="text" value="secret" /></div>}
66
+ assert_equal expected, @builder.text_field(:password, help: false)
67
+ end
68
+
69
+ test "form_group creates a valid structure and allows arbitrary html to be added via a block" do
70
+ output = @horizontal_builder.form_group :nil, label: { text: 'Foo' } do
71
+ %{<p class="form-control-static">Bar</p>}.html_safe
72
+ end
73
+
74
+ expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_nil">Foo</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
75
+ assert_equal expected, output
76
+ end
77
+
78
+ test "form_group adds a spacer when no label exists for a horizontal form" do
79
+ output = @horizontal_builder.form_group do
80
+ %{<p class="form-control-static">Bar</p>}.html_safe
81
+ end
82
+
83
+ expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
84
+ assert_equal expected, output
85
+ end
86
+
87
+ test "form_group renders the label correctly" do
88
+ output = @horizontal_builder.form_group :email, label: { text: 'Custom Control' } do
89
+ %{<p class="form-control-static">Bar</p>}.html_safe
90
+ end
91
+
92
+ expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_email">Custom Control</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
93
+ assert_equal expected, output
94
+ end
95
+
96
+ test "form_group accepts class thorugh options hash" do
97
+ output = @horizontal_builder.form_group :email, class: "foo" do
98
+ %{<p class="form-control-static">Bar</p>}.html_safe
99
+ end
100
+
101
+ expected = %{<div class="form-group foo"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
102
+ assert_equal expected, output
103
+ end
104
+
105
+ test "form_group accepts class thorugh options hash without needing a name" do
106
+ output = @horizontal_builder.form_group class: "foo" do
107
+ %{<p class="form-control-static">Bar</p>}.html_safe
108
+ end
109
+
110
+ expected = %{<div class="form-group foo"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
111
+ assert_equal expected, output
112
+ end
113
+
114
+ test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do
115
+ output = @horizontal_builder.form_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
116
+ %{<p class="form-control-static">Bar</p>}.html_safe
117
+ end
118
+
119
+ expected = %{<div class="form-group"><label class="foo control-label col-sm-2" for="bar">Custom Control</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
120
+ assert_equal expected, output
121
+ end
122
+
123
+ test 'form_group renders the "error" class and message corrrectly when object is invalid' do
124
+ @user.email = nil
125
+ @user.valid?
126
+
127
+ output = @builder.form_group :email do
128
+ %{<p class="form-control-static">Bar</p>}.html_safe
129
+ end
130
+
131
+ expected = %{<div class="form-group has-error"><p class="form-control-static">Bar</p><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div>}
132
+ assert_equal expected, output
133
+ end
134
+
135
+ test "adds class to wrapped form_group by a field" do
136
+ expected = %{<div class="form-group none-margin"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="search" /></div>}
137
+ assert_equal expected, @builder.search_field(:misc, wrapper_class: 'none-margin')
138
+ end
139
+
140
+ test "adds class to wrapped form_group by a field with errors" do
141
+ @user.email = nil
142
+ @user.valid?
143
+
144
+ expected = %{<div class="form-group none-margin has-error"><div class="field_with_errors"><label class="control-label" for="user_email">Email</label></div><div class="field_with_errors"><input class="form-control" id="user_email" name="user[email]" type="email" /></div><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div>}
145
+ assert_equal expected, @builder.email_field(:email, wrapper_class: 'none-margin')
146
+ end
147
+
148
+ test "adds class to wrapped form_group by a field with errors when bootstrap_form_for is used" do
149
+ @user.email = nil
150
+ @user.valid?
151
+
152
+ output = bootstrap_form_for(@user) do |f|
153
+ f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin')
154
+ end
155
+
156
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group none-margin has-error"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
157
+ assert_equal expected, output
158
+ end
159
+
160
+ test "adds offset for form_group without label" do
161
+ output = @horizontal_builder.form_group do
162
+ @horizontal_builder.submit
163
+ end
164
+
165
+ expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2"><input class="btn btn-default" name="commit" type="submit" value="Create User" /></div></div>}
166
+ assert_equal expected, output
167
+ end
168
+
169
+ test "adds offset for form_group without label but specific label_col" do
170
+ output = @horizontal_builder.form_group label_col: 'col-sm-5', control_col: 'col-sm-8' do
171
+ @horizontal_builder.submit
172
+ end
173
+
174
+ expected = %{<div class="form-group"><div class="col-sm-8 col-sm-offset-5"><input class="btn btn-default" name="commit" type="submit" value="Create User" /></div></div>}
175
+ assert_equal expected, output
176
+ end
177
+
178
+ test "adding an icon to a field" do
179
+ expected = %{<div class="form-group has-feedback"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="email" /><span class="glyphicon glyphicon-ok form-control-feedback"></span></div>}
180
+ assert_equal expected, @builder.email_field(:misc, icon: 'ok')
181
+ end
182
+
183
+ test "single form_group call in horizontal form should not be smash design" do
184
+ output = ''
185
+ output = @horizontal_builder.form_group do
186
+ "Hallo"
187
+ end
188
+
189
+ output = output + @horizontal_builder.text_field(:email)
190
+
191
+ expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2">Hallo</div></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
192
+ assert_equal expected, output
193
+ end
194
+
195
+ test "adds data-attributes (or any other options) to wrapper" do
196
+ expected = %{<div class="form-group" data-foo="bar"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="search" /></div>}
197
+ assert_equal expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } })
198
+ end
199
+
200
+ test "passing options to a form control get passed through" do
201
+ expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><input autofocus="autofocus" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
202
+ assert_equal expected, @builder.text_field(:email, autofocus: true)
203
+ end
204
+
205
+ test "doesn't throw undefined method error when the content block returns nil" do
206
+ output = @builder.form_group :nil, label: { text: 'Foo' } do
207
+ nil
208
+ end
209
+
210
+ expected = %{<div class="form-group"><label class="control-label" for="user_nil">Foo</label></div>}
211
+ assert_equal expected, output
212
+ end
213
+
214
+ test "custom form group layout option" do
215
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></form>}
216
+ assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline }
217
+ end
218
+ end
@@ -4,52 +4,60 @@ class BootstrapFormTest < ActionView::TestCase
4
4
  include BootstrapForm::Helper
5
5
 
6
6
  def setup
7
- @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment')
8
- @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
9
- @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10" })
7
+ setup_test_fixture
10
8
  end
11
9
 
12
10
  test "default-style forms" do
13
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
11
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
14
12
  assert_equal expected, bootstrap_form_for(@user) { |f| nil }
15
13
  end
16
14
 
17
15
  test "inline-style forms" do
18
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
16
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
19
17
  assert_equal expected, bootstrap_form_for(@user, layout: :inline) { |f| nil }
20
18
  end
21
19
 
22
20
  test "horizontal-style forms" do
23
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
21
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
24
22
  assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email }
25
23
  end
26
24
 
27
25
  test "existing styles aren't clobbered when specifying a form style" do
28
- expected = %{<form accept-charset="UTF-8" action="/users" class="my-style form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
26
+ expected = %{<form accept-charset="UTF-8" action="/users" class="my-style form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
29
27
  assert_equal expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email }
30
28
  end
31
29
 
30
+ test "given role attribute should not be covered by default role attribute" do
31
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="not-a-form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
32
+ assert_equal expected, bootstrap_form_for(@user, html: { role: 'not-a-form'}) {|f| nil}
33
+ end
34
+
32
35
  test "bootstrap_form_tag acts like a form tag" do
33
- expected = %{<form accept-charset="UTF-8" action="/users" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="email">Your Email</label><input class="form-control" id="email" name="email" type="text" /></div></form>}
36
+ expected = %{<form accept-charset="UTF-8" action="/users" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="email">Your Email</label><input class="form-control" id="email" name="email" type="text" /></div></form>}
34
37
  assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, label: "Your Email" }
35
38
  end
36
39
 
37
40
  test "bootstrap_form_tag does not clobber custom options" do
38
- expected = %{<form accept-charset="UTF-8" action="/users" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="ID">Email</label><input class="form-control" id="ID" name="NAME" type="text" /></div></form>}
41
+ expected = %{<form accept-charset="UTF-8" action="/users" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="ID">Email</label><input class="form-control" id="ID" name="NAME" type="text" /></div></form>}
39
42
  assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, name: 'NAME', id: "ID" }
40
43
  end
41
44
 
45
+ test "bootstrap_form_tag allows an empty name for checkboxes" do
46
+ expected = %{<form accept-charset="UTF-8" action="/users" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="checkbox"><label for="_misc"><input name="[misc]" type="hidden" value="0" /><input id="_misc" name="[misc]" type="checkbox" value="1" /> Misc</label></div></form>}
47
+ assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc }
48
+ end
49
+
42
50
  test "alert message is wrapped correctly" do
43
51
  @user.email = nil
44
52
  @user.valid?
45
- expected = %{<div class="alert alert-danger"><p>Please fix the following errors:</p></div>}
53
+ expected = %{<div class="alert alert-danger"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can&#39;t be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div>}
46
54
  assert_equal expected, @builder.alert_message('Please fix the following errors:')
47
55
  end
48
56
 
49
57
  test "changing the class name for the alert message" do
50
58
  @user.email = nil
51
59
  @user.valid?
52
- expected = %{<div class="my-css-class"><p>Please fix the following errors:</p></div>}
60
+ expected = %{<div class="my-css-class"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can&#39;t be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div>}
53
61
  assert_equal expected, @builder.alert_message('Please fix the following errors:', class: 'my-css-class')
54
62
  end
55
63
 
@@ -61,7 +69,7 @@ class BootstrapFormTest < ActionView::TestCase
61
69
  f.alert_message('Please fix the following errors:')
62
70
  end
63
71
 
64
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can&#39;t be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div></form>}
72
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can&#39;t be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div></form>}
65
73
  assert_equal expected, output
66
74
  end
67
75
 
@@ -73,7 +81,19 @@ class BootstrapFormTest < ActionView::TestCase
73
81
  f.alert_message('Please fix the following errors:', error_summary: false)
74
82
  end
75
83
 
76
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p></div></form>}
84
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p></div></form>}
85
+ assert_equal expected, output
86
+ end
87
+
88
+ test "alert_message allows the error_summary to be turned on with inline_errors also turned on" do
89
+ @user.email = nil
90
+ @user.valid?
91
+
92
+ output = bootstrap_form_for(@user, inline_errors: true) do |f|
93
+ f.alert_message('Please fix the following errors:', error_summary: true)
94
+ end
95
+
96
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can&#39;t be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div></form>}
77
97
  assert_equal expected, output
78
98
  end
79
99
 
@@ -93,407 +113,16 @@ class BootstrapFormTest < ActionView::TestCase
93
113
  assert_equal expected, @builder.errors_on(:email)
94
114
  end
95
115
 
96
- test "color fields are wrapped correctly" do
97
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="color" value="#000000" /></div>}
98
- assert_equal expected, @builder.color_field(:misc)
99
- end
100
-
101
- test "date fields are wrapped correctly" do
102
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="date" /></div>}
103
- assert_equal expected, @builder.date_field(:misc)
104
- end
105
-
106
- test "date time fields are wrapped correctly" do
107
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="datetime" /></div>}
108
- assert_equal expected, @builder.datetime_field(:misc)
109
- end
110
-
111
- test "date time local fields are wrapped correctly" do
112
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="datetime-local" /></div>}
113
- assert_equal expected, @builder.datetime_local_field(:misc)
114
- end
115
-
116
- test "email fields are wrapped correctly" do
117
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="email" /></div>}
118
- assert_equal expected, @builder.email_field(:misc)
119
- end
120
-
121
- test "file fields are wrapped correctly" do
122
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input id="user_misc" name="user[misc]" type="file" /></div>}
123
- assert_equal expected, @builder.file_field(:misc)
124
- end
125
-
126
- test "hidden fields are supported" do
127
- expected = %{<input id="user_misc" name="user[misc]" type="hidden" />}
128
- assert_equal expected, @builder.hidden_field(:misc)
129
- end
130
-
131
- test "month local fields are wrapped correctly" do
132
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="month" /></div>}
133
- assert_equal expected, @builder.month_field(:misc)
134
- end
135
-
136
- test "number fields are wrapped correctly" do
137
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="number" /></div>}
138
- assert_equal expected, @builder.number_field(:misc)
139
- end
140
-
141
- test "password fields are wrapped correctly" do
142
- expected = %{<div class="form-group"><label class="control-label" for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="password" /></div>}
143
- assert_equal expected, @builder.password_field(:password)
144
- end
145
-
146
- test "phone/telephone fields are wrapped correctly" do
147
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="tel" /></div>}
148
- assert_equal expected, @builder.phone_field(:misc)
149
- assert_equal expected, @builder.telephone_field(:misc)
150
- end
151
-
152
- test "range fields are wrapped correctly" do
153
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="range" /></div>}
154
- assert_equal expected, @builder.range_field(:misc)
155
- end
156
-
157
- test "search fields are wrapped correctly" do
158
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="search" /></div>}
159
- assert_equal expected, @builder.search_field(:misc)
160
- end
161
-
162
- test "text areas are wrapped correctly" do
163
- expected = %{<div class="form-group"><label class="control-label" for="user_comments">Comments</label><textarea class="form-control" id="user_comments" name="user[comments]">\nmy comment</textarea></div>}
164
- assert_equal expected, @builder.text_area(:comments)
165
- end
166
-
167
- test "text fields are wrapped correctly" do
168
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
169
- assert_equal expected, @builder.text_field(:email)
170
- end
171
-
172
- test "time fields are wrapped correctly" do
173
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="time" /></div>}
174
- assert_equal expected, @builder.time_field(:misc)
175
- end
176
-
177
- test "url fields are wrapped correctly" do
178
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="url" /></div>}
179
- assert_equal expected, @builder.url_field(:misc)
180
- end
181
-
182
- test "week fields are wrapped correctly" do
183
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="week" /></div>}
184
- assert_equal expected, @builder.week_field(:misc)
185
- end
186
-
187
- test "selects are wrapped correctly" do
188
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"><option value="1">activated</option>\n<option value="2">blocked</option></select></div>}
189
- assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]])
190
- end
191
-
192
- test "bootstrap_specific options are handled correctly" do
193
- expected = %{<div class="form-group"><label class="control-label" for="user_status">My Status Label</label><select class="form-control" id="user_status" name="user[status]"><option value="1">activated</option>\n<option value="2">blocked</option></select><span class="help-block">Help!</span></div>}
194
- assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" )
195
- end
196
-
197
- test "selects with options are wrapped correctly" do
198
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"><option value="">Please Select</option>\n<option value="1">activated</option>\n<option value="2">blocked</option></select></div>}
199
- assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prompt: "Please Select")
200
- end
201
-
202
- test "selects with both options and html_options are wrapped correctly" do
203
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control my-select" id="user_status" name="user[status]"><option value="">Please Select</option>\n<option value="1">activated</option>\n<option value="2">blocked</option></select></div>}
204
- assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select")
205
- end
206
-
207
- test "selects render labels properly" do
208
- expected = %{<div class="form-group"><label class="control-label" for="user_status">User Status</label><select class="form-control" id="user_status" name="user[status]"><option value="1">activated</option>\n<option value="2">blocked</option></select></div>}
209
- assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "User Status")
210
- end
211
-
212
- test "collection_selects are wrapped correctly" do
213
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"></select></div>}
214
- assert_equal expected, @builder.collection_select(:status, [], :id, :name)
215
- end
216
-
217
- test "collection_selects with options are wrapped correctly" do
218
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"><option value="">Please Select</option>\n</select></div>}
219
- assert_equal expected, @builder.collection_select(:status, [], :id, :name, prompt: "Please Select")
220
- end
221
-
222
- test "collection_selects with options and html_options are wrapped correctly" do
223
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control my-select" id="user_status" name="user[status]"><option value="">Please Select</option>\n</select></div>}
224
- assert_equal expected, @builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select")
225
- end
226
-
227
- test "grouped_collection_selects are wrapped correctly" do
228
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"></select></div>}
229
- assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s)
230
- end
231
-
232
- test "grouped_collection_selects with options are wrapped correctly" do
233
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"><option value="">Please Select</option>\n</select></div>}
234
- assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, prompt: "Please Select")
235
- end
236
-
237
- test "grouped_collection_selects with options and html_options are wrapped correctly" do
238
- expected = %{<div class="form-group"><label class="control-label" for="user_status">Status</label><select class="form-control my-select" id="user_status" name="user[status]"><option value="">Please Select</option>\n</select></div>}
239
- assert_equal expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, { prompt: "Please Select" }, class: "my-select")
240
- end
241
-
242
- test "date selects are wrapped correctly" do
243
- Timecop.freeze(Time.utc(2012, 2, 3)) do
244
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-date-select"><select class="form-control" id="user_misc_1i" name="user[misc(1i)]">\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option selected="selected" value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control" id="user_misc_2i" name="user[misc(2i)]">\n<option value="1">January</option>\n<option selected="selected" value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control" id="user_misc_3i" name="user[misc(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option selected="selected" value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</div></div>}
245
- assert_equal expected, @builder.date_select(:misc)
246
- end
247
- end
248
-
249
- test "date selects with options are wrapped correctly" do
250
- Timecop.freeze(Time.utc(2012, 2, 3)) do
251
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-date-select"><select class="form-control" id="user_misc_1i" name="user[misc(1i)]">\n<option value=""></option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control" id="user_misc_2i" name="user[misc(2i)]">\n<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control" id="user_misc_3i" name="user[misc(3i)]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</div></div>}
252
- assert_equal expected, @builder.date_select(:misc, include_blank: true)
253
- end
254
- end
255
-
256
- test "date selects with options and html_options are wrapped correctly" do
257
- Timecop.freeze(Time.utc(2012, 2, 3)) do
258
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-date-select"><select class="form-control my-date-select" id="user_misc_1i" name="user[misc(1i)]">\n<option value=""></option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control my-date-select" id="user_misc_2i" name="user[misc(2i)]">\n<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control my-date-select" id="user_misc_3i" name="user[misc(3i)]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</div></div>}
259
- assert_equal expected, @builder.date_select(:misc, { include_blank: true }, class: "my-date-select")
260
- end
261
- end
262
-
263
- test "time selects are wrapped correctly" do
264
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
265
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-time-select"><input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />\n<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />\n<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />\n<select class="form-control" id="user_misc_4i" name="user[misc(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option selected="selected" value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control" id="user_misc_5i" name="user[misc(5i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
266
- assert_equal expected, @builder.time_select(:misc)
267
- end
268
- end
269
-
270
- test "time selects with options are wrapped correctly" do
271
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
272
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-time-select"><input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />\n<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />\n<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />\n<select class="form-control" id="user_misc_4i" name="user[misc(4i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control" id="user_misc_5i" name="user[misc(5i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
273
- assert_equal expected, @builder.time_select(:misc, include_blank: true)
274
- end
275
- end
276
-
277
- test "time selects with options and html_options are wrapped correctly" do
278
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
279
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-time-select"><input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="1" />\n<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="1" />\n<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="1" />\n<select class="form-control my-time-select" id="user_misc_4i" name="user[misc(4i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control my-time-select" id="user_misc_5i" name="user[misc(5i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
280
- assert_equal expected, @builder.time_select(:misc, { include_blank: true }, class: "my-time-select")
281
- end
282
- end
283
-
284
- test "datetime selects are wrapped correctly" do
285
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
286
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-datetime-select"><select class="form-control" id="user_misc_1i" name="user[misc(1i)]">\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option selected="selected" value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control" id="user_misc_2i" name="user[misc(2i)]">\n<option value="1">January</option>\n<option selected="selected" value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control" id="user_misc_3i" name="user[misc(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option selected="selected" value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select class="form-control" id="user_misc_4i" name="user[misc(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option selected="selected" value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control" id="user_misc_5i" name="user[misc(5i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
287
- assert_equal expected, @builder.datetime_select(:misc)
288
- end
289
- end
290
-
291
- test "datetime selects with options are wrapped correctly" do
292
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
293
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-datetime-select"><select class="form-control" id="user_misc_1i" name="user[misc(1i)]">\n<option value=""></option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control" id="user_misc_2i" name="user[misc(2i)]">\n<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control" id="user_misc_3i" name="user[misc(3i)]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select class="form-control" id="user_misc_4i" name="user[misc(4i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control" id="user_misc_5i" name="user[misc(5i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
294
- assert_equal expected, @builder.datetime_select(:misc, include_blank: true)
295
- end
296
- end
297
-
298
- test "datetime selects with options and html_options are wrapped correctly" do
299
- Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
300
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="rails-bootstrap-forms-datetime-select"><select class="form-control my-datetime-select" id="user_misc_1i" name="user[misc(1i)]">\n<option value=""></option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select class="form-control my-datetime-select" id="user_misc_2i" name="user[misc(2i)]">\n<option value=""></option>\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select class="form-control my-datetime-select" id="user_misc_3i" name="user[misc(3i)]">\n<option value=""></option>\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select class="form-control my-datetime-select" id="user_misc_4i" name="user[misc(4i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select class="form-control my-datetime-select" id="user_misc_5i" name="user[misc(5i)]">\n<option value=""></option>\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div></div>}
301
- assert_equal expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select")
302
- end
303
- end
304
-
305
- test "check_box is wrapped correctly" do
306
- expected = %{<div class="checkbox"><label for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label></div>}
307
- assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms')
308
- end
309
-
310
- test "check_box label allows html" do
311
- expected = %{<div class="checkbox"><label for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the <a href="#">terms</a></label></div>}
312
- assert_equal expected, @builder.check_box(:terms, label: %{I agree to the <a href="#">terms</a>}.html_safe)
313
- end
314
-
315
- test "check_box accepts a block to define the label" do
316
- expected = %{<div class="checkbox"><label for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label></div>}
317
- assert_equal expected, @builder.check_box(:terms) { "I agree to the terms" }
318
- end
319
-
320
- test "check_box responds to checked_value and unchecked_value arguments" do
321
- expected = %{<div class="checkbox"><label for="user_terms"><input name="user[terms]" type="hidden" value="no" /><input id="user_terms" name="user[terms]" type="checkbox" value="yes" /> I agree to the terms</label></div>}
322
- assert_equal expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no')
323
- end
324
-
325
- test "inline checkboxes" do
326
- expected = %{<label class="checkbox-inline" for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label>}
327
- assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true)
328
- end
329
-
330
- test "radio_button is wrapped correctly" do
331
- expected = %{<label class="radio"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
332
- assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button')
333
- end
334
-
335
- test "radio_button inline label is set correctly" do
336
- expected = %{<label class="radio-inline"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
337
- assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true)
338
- end
339
-
340
- test "changing the label text" do
341
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
342
- assert_equal expected, @builder.text_field(:email, label: 'Email Address')
343
- end
344
-
345
- test "hiding a label" do
346
- expected = %{<div class="form-group"><label class="sr-only control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
347
- assert_equal expected, @builder.text_field(:email, hide_label: true)
348
- end
349
-
350
- test "adding prepend text" do
351
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><span class="input-group-addon">@</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
352
- assert_equal expected, @builder.text_field(:email, prepend: '@')
353
- end
354
-
355
- test "adding append text" do
356
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
357
- assert_equal expected, @builder.text_field(:email, append: '.00')
358
- end
359
-
360
- test "adding both prepend and append text" do
361
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><span class="input-group-addon">$</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
362
- assert_equal expected, @builder.text_field(:email, prepend: '$', append: '.00')
363
- end
364
-
365
- test "help messages for default forms" do
366
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="help-block">This is required</span></div>}
367
- assert_equal expected, @builder.text_field(:email, help: 'This is required')
368
- end
369
-
370
- test "help messages for horizontal forms" do
371
- expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="help-block">This is required</span></div></div>}
372
- assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required")
373
- end
374
-
375
116
  test "custom label width for horizontal forms" do
376
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-1" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
117
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-1" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
377
118
  assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' }
378
119
  end
379
120
 
380
121
  test "custom input width for horizontal forms" do
381
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-5"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
122
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-5"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
382
123
  assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' }
383
124
  end
384
125
 
385
- test "custom form group layout option" do
386
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></form>}
387
- assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline }
388
- end
389
-
390
- test "passing options to a form control get passed through" do
391
- expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><input autofocus="autofocus" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
392
- assert_equal expected, @builder.text_field(:email, autofocus: true)
393
- end
394
-
395
- test "form_group creates a valid structure and allows arbitrary html to be added via a block" do
396
- output = @horizontal_builder.form_group :nil, label: { text: 'Foo' } do
397
- %{<p class="form-control-static">Bar</p>}.html_safe
398
- end
399
-
400
- expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_nil">Foo</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
401
- assert_equal expected, output
402
- end
403
-
404
- test "form_group adds a spacer when no label exists for a horizontal form" do
405
- output = @horizontal_builder.form_group do
406
- %{<p class="form-control-static">Bar</p>}.html_safe
407
- end
408
-
409
- expected = %{<div class="form-group"><label class="control-label col-sm-2"></label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
410
- assert_equal expected, output
411
- end
412
-
413
- test "form_group renders the label correctly" do
414
- output = @horizontal_builder.form_group :email, label: { text: 'Custom Control' } do
415
- %{<p class="form-control-static">Bar</p>}.html_safe
416
- end
417
-
418
- expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_email">Custom Control</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
419
- assert_equal expected, output
420
- end
421
-
422
- test "form_group accepts class thorugh options hash" do
423
- output = @horizontal_builder.form_group :email, class: "foo" do
424
- %{<p class="form-control-static">Bar</p>}.html_safe
425
- end
426
-
427
- expected = %{<div class="form-group foo"><label class="control-label col-sm-2"></label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
428
- assert_equal expected, output
429
- end
430
-
431
- test "form_group accepts class thorugh options hash without needing a name" do
432
- output = @horizontal_builder.form_group class: "foo" do
433
- %{<p class="form-control-static">Bar</p>}.html_safe
434
- end
435
-
436
- expected = %{<div class="form-group foo"><label class="control-label col-sm-2"></label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
437
- assert_equal expected, output
438
- end
439
-
440
- test "static control" do
441
- output = @horizontal_builder.static_control :email
442
-
443
- expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_email">Email</label><div class="col-sm-10"><p class="form-control-static">steve@example.com</p></div></div>}
444
- assert_equal expected, output
445
- end
446
-
447
- test "static control doesn't require an actual attribute" do
448
- output = @horizontal_builder.static_control nil, label: "My Label" do
449
- "this is a test"
450
- end
451
-
452
- expected = %{<div class="form-group"><label class="control-label col-sm-2" for="user_">My Label</label><div class="col-sm-10"><p class="form-control-static">this is a test</p></div></div>}
453
- assert_equal expected, output
454
- end
455
-
456
- test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do
457
- output = @horizontal_builder.form_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
458
- %{<p class="form-control-static">Bar</p>}.html_safe
459
- end
460
-
461
- expected = %{<div class="form-group"><label class="foo control-label col-sm-2" for="bar">Custom Control</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
462
- assert_equal expected, output
463
- end
464
-
465
- test 'form_group renders the "error" class and message corrrectly when object is invalid' do
466
- @user.email = nil
467
- @user.valid?
468
-
469
- output = @builder.form_group :email do
470
- %{<p class="form-control-static">Bar</p>}.html_safe
471
- end
472
-
473
- expected = %{<div class="form-group has-error"><p class="form-control-static">Bar</p><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div>}
474
- assert_equal expected, output
475
- end
476
-
477
- test "submit button defaults to rails action name" do
478
- expected = %{<input class="btn btn-default" name="commit" type="submit" value="Create User" />}
479
- assert_equal expected, @builder.submit
480
- end
481
-
482
- test "submit button uses default button classes" do
483
- expected = %{<input class="btn btn-default" name="commit" type="submit" value="Submit Form" />}
484
- assert_equal expected, @builder.submit("Submit Form")
485
- end
486
-
487
- test "override submit button classes" do
488
- expected = %{<input class="btn btn-primary" name="commit" type="submit" value="Submit Form" />}
489
- assert_equal expected, @builder.submit("Submit Form", class: "btn btn-primary")
490
- end
491
-
492
- test "primary button uses proper css classes" do
493
- expected = %{<input class="btn btn-primary" name="commit" type="submit" value="Submit Form" />}
494
- assert_equal expected, @builder.primary("Submit Form")
495
- end
496
-
497
126
  test "the field contains the error and is not wrapped in div.field_with_errors when bootstrap_form_for is used" do
498
127
  @user.email = nil
499
128
  @user.valid?
@@ -502,19 +131,7 @@ class BootstrapFormTest < ActionView::TestCase
502
131
  f.text_field(:email, help: 'This is required')
503
132
  end
504
133
 
505
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
506
- assert_equal expected, output
507
- end
508
-
509
- test "help is preserved when inline_errors: false is passed to bootstrap_form_for" do
510
- @user.email = nil
511
- @user.valid?
512
-
513
- output = bootstrap_form_for(@user, inline_errors: false) do |f|
514
- f.text_field(:email, help: 'This is required')
515
- end
516
-
517
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">This is required</span></div></form>}
134
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
518
135
  assert_equal expected, output
519
136
  end
520
137
 
@@ -530,55 +147,15 @@ class BootstrapFormTest < ActionView::TestCase
530
147
  assert_equal expected, output
531
148
  end
532
149
 
533
- test "bootstrap_form_for helper works for associations" do
534
- @user.address = Address.new(street: '123 Main Street')
535
-
536
- output = bootstrap_form_for(@user) do |f|
537
- f.fields_for :address do |af|
538
- af.text_field(:street)
539
- end
540
- end
541
-
542
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="user_address_attributes_street">Street</label><input class="form-control" id="user_address_attributes_street" name="user[address_attributes][street]" type="text" value="123 Main Street" /></div></form>}
543
- assert_equal expected, output
544
- end
545
-
546
- test "bootstrap_form_for helper works for serialized hash attributes" do
547
- @user.preferences = { favorite_color: "cerulean" }
548
-
549
- output = bootstrap_form_for(@user) do |f|
550
- f.fields_for :preferences do |builder|
551
- builder.text_field :favorite_color, value: @user.preferences[:favorite_color]
552
- end
553
- end
554
-
555
- expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="user_preferences_favorite_color">Favorite color</label><input class="form-control" id="user_preferences_favorite_color" name="user[preferences][favorite_color]" type="text" value="cerulean" /></div></form>}
556
- assert_equal expected, output
557
- end
558
-
559
- test "fields_for correctly passes horizontal style from parent builder" do
560
- @user.address = Address.new(street: '123 Main Street')
561
-
562
- output = bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-sm-2', control_col: 'col-sm-10') do |f|
563
- f.fields_for :address do |af|
564
- af.text_field(:street)
565
- end
566
- end
567
-
568
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label col-sm-2" for="user_address_attributes_street">Street</label><div class="col-sm-10"><input class="form-control" id="user_address_attributes_street" name="user[address_attributes][street]" type="text" value="123 Main Street" /></div></div></form>}
569
- assert_equal expected, output
570
- end
571
-
572
- test "fields_for correctly passes inline style from parent builder" do
573
- @user.address = Address.new(street: '123 Main Street')
150
+ test "help is preserved when inline_errors: false is passed to bootstrap_form_for" do
151
+ @user.email = nil
152
+ @user.valid?
574
153
 
575
- output = bootstrap_form_for(@user, layout: :inline) do |f|
576
- f.fields_for :address do |af|
577
- af.text_field(:street)
578
- end
154
+ output = bootstrap_form_for(@user, inline_errors: false) do |f|
155
+ f.text_field(:email, help: 'This is required')
579
156
  end
580
157
 
581
- expected = %{<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label" for="user_address_attributes_street">Street</label><input class="form-control" id="user_address_attributes_street" name="user[address_attributes][street]" type="text" value="123 Main Street" /></div></form>}
158
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><label class="control-label" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">This is required</span></div></form>}
582
159
  assert_equal expected, output
583
160
  end
584
161
 
@@ -588,60 +165,12 @@ class BootstrapFormTest < ActionView::TestCase
588
165
  assert_equal expected, builder.text_field(:email)
589
166
  end
590
167
 
591
- test 'collection_radio_buttons renders the form_group correctly' do
592
- collection = [Address.new(id: 1, street: 'Foobar')]
593
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">This is a radio button collection</label><label class="radio"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> Foobar</label><span class="help-block">With a help!</span></div>}
594
-
595
- assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!')
596
- end
597
-
598
- test 'collection_radio_buttons renders multiple radios correctly' do
599
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
600
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><label class="radio"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> Foo</label><label class="radio"><input id="user_misc_2" name="user[misc]" type="radio" value="2" /> Bar</label></div>}
601
-
602
- assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street)
603
- end
604
-
605
- test 'collection_radio_buttons renders inline radios correctly' do
606
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
607
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><label class="radio-inline"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> Foo</label><label class="radio-inline"><input id="user_misc_2" name="user[misc]" type="radio" value="2" /> Bar</label></div>}
608
-
609
- assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, inline: true)
610
- end
611
-
612
- test 'collection_radio_buttons renders with checked option correctly' do
613
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
614
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><label class="radio"><input checked="checked" id="user_misc_1" name="user[misc]" type="radio" value="1" /> Foo</label><label class="radio"><input id="user_misc_2" name="user[misc]" type="radio" value="2" /> Bar</label></div>}
615
-
616
- assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, checked: 1)
617
- end
618
-
619
- test 'collection_check_boxes renders the form_group correctly' do
620
- collection = [Address.new(id: 1, street: 'Foobar')]
621
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">This is a checkbox collection</label><div class="checkbox"><label for="user_misc_1"><input id="user_misc_1" name="user[misc][]" type="checkbox" value="1" /> Foobar</label></div><span class="help-block">With a help!</span></div>}
622
-
623
- assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!')
624
- end
625
-
626
- test 'collection_check_boxes renders multiple checkboxes correctly' do
627
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
628
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_1"><input id="user_misc_1" name="user[misc][]" type="checkbox" value="1" /> Foo</label></div><div class="checkbox"><label for="user_misc_2"><input id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> Bar</label></div></div>}
629
-
630
- assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street)
631
- end
632
-
633
- test 'collection_check_boxes renders inline checkboxes correctly' do
634
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
635
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><label class="checkbox-inline" for="user_misc_1"><input id="user_misc_1" name="user[misc][]" type="checkbox" value="1" /> Foo</label><label class="checkbox-inline" for="user_misc_2"><input id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> Bar</label></div>}
636
-
637
- assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
638
- end
168
+ test 'errors_on hide attribute name in message' do
169
+ @user.email = nil
170
+ @user.valid?
639
171
 
640
- test 'collection_check_boxes renders with checked option correctly' do
641
- collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
642
- expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_1"><input checked="checked" id="user_misc_1" name="user[misc][]" type="checkbox" value="1" /> Foo</label></div><div class="checkbox"><label for="user_misc_2"><input id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> Bar</label></div></div>}
172
+ expected = %{<div class="alert alert-danger">can&#39;t be blank, is too short (minimum is 5 characters)</div>}
643
173
 
644
- assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1)
174
+ assert_equal expected, @builder.errors_on(:email, hide_attribute_name: true)
645
175
  end
646
-
647
176
  end