bootstrap_form 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +207 -35
- data/app/assets/stylesheets/rails_bootstrap_forms.css +10 -0
- data/lib/bootstrap_form.rb +5 -0
- data/lib/bootstrap_form/bootstrap_helpers.rb +66 -0
- data/lib/bootstrap_form/form_builder.rb +176 -75
- data/lib/bootstrap_form/helper.rb +9 -3
- data/lib/bootstrap_form/version.rb +1 -1
- data/test/bootstrap_form_test.rb +320 -75
- data/test/dummy/app/models/user.rb +1 -0
- data/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb +5 -0
- data/test/dummy/db/schema.rb +2 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +11185 -1123
- metadata +27 -21
@@ -1,50 +1,85 @@
|
|
1
1
|
module BootstrapForm
|
2
2
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
-
|
3
|
+
include BootstrapForm::BootstrapHelpers
|
4
4
|
|
5
|
-
|
6
|
-
number_field email_field telephone_field phone_field url_field
|
7
|
-
select collection_select date_select time_select datetime_select}
|
5
|
+
attr_reader :layout, :label_col, :control_col, :has_error, :inline_errors, :acts_like_form_tag
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
FIELD_HELPERS = %w{color_field date_field datetime_field datetime_local_field
|
8
|
+
email_field month_field number_field password_field phone_field
|
9
|
+
range_field search_field telephone_field text_area text_field time_field
|
10
|
+
url_field week_field}
|
11
|
+
|
12
|
+
DATE_SELECT_HELPERS = %w{date_select time_select datetime_select}
|
13
|
+
|
14
|
+
delegate :content_tag, :capture, :concat, to: :@template
|
15
|
+
|
16
|
+
def initialize(object_name, object, template, options)
|
17
|
+
@layout = options[:layout]
|
18
|
+
@label_col = options[:label_col] || default_label_col
|
19
|
+
@control_col = options[:control_col] || default_control_col
|
20
|
+
@inline_errors = options[:inline_errors] != false
|
21
|
+
@acts_like_form_tag = options[:acts_like_form_tag]
|
11
22
|
|
12
|
-
def initialize(object_name, object, template, options, proc=nil)
|
13
|
-
@style = options[:style]
|
14
|
-
@left_class = (options[:left] || default_left_class) + " control-label"
|
15
|
-
@right_class = options[:right] || default_right_class
|
16
23
|
super
|
17
24
|
end
|
18
25
|
|
19
|
-
|
20
|
-
define_method(method_name) do |name,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
FIELD_HELPERS.each do |method_name|
|
27
|
+
define_method(method_name) do |name, options = {}|
|
28
|
+
form_group_builder(name, options) do
|
29
|
+
prepend_and_append_input(options) do
|
30
|
+
super(name, options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
prepend_and_append_input(input, options[:prepend], options[:append])
|
36
|
+
DATE_SELECT_HELPERS.each do |method_name|
|
37
|
+
define_method(method_name) do |name, options = {}, html_options = {}|
|
38
|
+
form_group_builder(name, options, html_options) do
|
39
|
+
content_tag(:div, super(name, options, html_options), class: control_specific_class(method_name))
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
37
|
-
def
|
44
|
+
def file_field(name, options = {})
|
45
|
+
form_group_builder(name, options.reverse_merge(control_class: nil)) do
|
46
|
+
super(name, options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def select(method, choices, options = {}, html_options = {})
|
51
|
+
form_group_builder(method, options, html_options) do
|
52
|
+
super(method, choices, options, html_options)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
57
|
+
form_group_builder(method, options, html_options) do
|
58
|
+
super(method, collection, value_method, text_method, options, html_options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
63
|
+
form_group_builder(method, options, html_options) do
|
64
|
+
super(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_box(name, options = {}, checked_value = "1", unchecked_value = "0", &block)
|
38
69
|
options = options.symbolize_keys!
|
39
70
|
|
40
71
|
html = super(name, options.except(:label, :help, :inline), checked_value, unchecked_value)
|
41
|
-
|
72
|
+
label_content = block_given? ? capture(&block) : options[:label]
|
73
|
+
html.concat(" ").concat(label_content || object.class.human_attribute_name(name) || name.to_s.humanize)
|
74
|
+
|
75
|
+
label_name = name
|
76
|
+
label_name = "#{name}_#{checked_value}" if options[:multiple]
|
42
77
|
|
43
78
|
if options[:inline]
|
44
|
-
label(
|
79
|
+
label(label_name, html, class: "checkbox-inline")
|
45
80
|
else
|
46
81
|
content_tag(:div, class: "checkbox") do
|
47
|
-
label(
|
82
|
+
label(label_name, html)
|
48
83
|
end
|
49
84
|
end
|
50
85
|
end
|
@@ -53,69 +88,73 @@ module BootstrapForm
|
|
53
88
|
options = args.extract_options!.symbolize_keys!
|
54
89
|
args << options.except(:label, :help, :inline)
|
55
90
|
|
56
|
-
html = super(name, value, *args) +
|
91
|
+
html = super(name, value, *args) + " " + options[:label]
|
57
92
|
|
58
|
-
css =
|
59
|
-
css <<
|
60
|
-
label(
|
93
|
+
css = "radio"
|
94
|
+
css << "-inline" if options[:inline]
|
95
|
+
label(name, html, class: css, for: nil)
|
61
96
|
end
|
62
97
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
html = content_tag(:div, html, class: right_class) if horizontal?
|
98
|
+
def collection_check_boxes(*args)
|
99
|
+
inputs_collection(*args) do |name, value, options|
|
100
|
+
options[:multiple] = true
|
101
|
+
check_box(name, options, value, nil)
|
102
|
+
end
|
103
|
+
end
|
70
104
|
|
71
|
-
|
72
|
-
|
105
|
+
def collection_radio_buttons(*args)
|
106
|
+
inputs_collection(*args) do |name, value, options|
|
107
|
+
radio_button(name, value, options)
|
73
108
|
end
|
74
109
|
end
|
75
110
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
111
|
+
def check_boxes_collection(*args)
|
112
|
+
warn "'BootstrapForm#check_boxes_collection' is deprecated, use 'BootstrapForm#collection_check_boxes' instead"
|
113
|
+
collection_check_boxes(*args)
|
79
114
|
end
|
80
115
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
116
|
+
def radio_buttons_collection(*args)
|
117
|
+
warn "'BootstrapForm#radio_buttons_collection' is deprecated, use 'BootstrapForm#collection_radio_buttons' instead"
|
118
|
+
collection_radio_buttons(*args)
|
119
|
+
end
|
84
120
|
|
85
|
-
|
86
|
-
|
121
|
+
def form_group(name = nil, options = {}, &block)
|
122
|
+
options[:class] = "form-group"
|
123
|
+
options[:class] << " #{error_class}" if has_error?(name)
|
124
|
+
|
125
|
+
content_tag(:div, options.except(:label, :help, :label_col, :control_col, :layout)) do
|
126
|
+
label = generate_label(name, options[:label], options[:label_col], options[:layout])
|
127
|
+
control_and_help = capture(&block).concat(generate_help(name, options[:help]))
|
128
|
+
if get_group_layout(options[:layout]) == :horizontal
|
129
|
+
control_and_help = content_tag(:div, control_and_help, class: (options[:control_col] || control_col))
|
130
|
+
end
|
131
|
+
concat(label).concat(control_and_help)
|
87
132
|
end
|
88
133
|
end
|
89
134
|
|
90
135
|
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
|
91
136
|
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
|
92
|
-
fields_options[:
|
93
|
-
fields_options[:
|
94
|
-
fields_options[:
|
95
|
-
super
|
137
|
+
fields_options[:layout] ||= options[:layout]
|
138
|
+
fields_options[:label_col] = (fields_options.include?(:label_col)) ? fields_options[:label_col] + " #{label_class}" : options[:label_col]
|
139
|
+
fields_options[:control_col] ||= options[:control_col]
|
140
|
+
super(record_name, record_object, fields_options, &block)
|
96
141
|
end
|
97
142
|
|
98
143
|
private
|
99
144
|
|
100
|
-
def
|
101
|
-
|
102
|
-
args << {} while args.length < 3
|
103
|
-
elsif method_name == "collection_select"
|
104
|
-
args << {} while args.length < 5
|
105
|
-
elsif method_name =~ /_select/
|
106
|
-
args << {} while args.length < 2
|
107
|
-
end
|
145
|
+
def horizontal?
|
146
|
+
layout == :horizontal
|
108
147
|
end
|
109
148
|
|
110
|
-
def
|
111
|
-
|
149
|
+
def get_group_layout(group_layout)
|
150
|
+
group_layout || layout
|
112
151
|
end
|
113
152
|
|
114
|
-
def
|
153
|
+
def default_label_col
|
115
154
|
"col-sm-2"
|
116
155
|
end
|
117
156
|
|
118
|
-
def
|
157
|
+
def default_control_col
|
119
158
|
"col-sm-10"
|
120
159
|
end
|
121
160
|
|
@@ -123,30 +162,92 @@ module BootstrapForm
|
|
123
162
|
"sr-only" # still accessible for screen readers
|
124
163
|
end
|
125
164
|
|
165
|
+
def control_class
|
166
|
+
"form-control"
|
167
|
+
end
|
168
|
+
|
169
|
+
def label_class
|
170
|
+
"control-label"
|
171
|
+
end
|
172
|
+
|
173
|
+
def error_class
|
174
|
+
"has-error"
|
175
|
+
end
|
176
|
+
|
177
|
+
def control_specific_class(method)
|
178
|
+
"rails-bootstrap-forms-#{method.gsub(/_/, "-")}"
|
179
|
+
end
|
180
|
+
|
126
181
|
def has_error?(name)
|
127
182
|
object.respond_to?(:errors) && !(name.nil? || object.errors[name].empty?)
|
128
183
|
end
|
129
184
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
185
|
+
def form_group_builder(method, options, html_options = nil)
|
186
|
+
options.symbolize_keys!
|
187
|
+
html_options.symbolize_keys! if html_options
|
188
|
+
|
189
|
+
# Add control_class; allow it to be overridden by :control_class option
|
190
|
+
css_options = html_options || options
|
191
|
+
control_classes = css_options.delete(:control_class) { control_class }
|
192
|
+
css_options[:class] = [control_classes, css_options[:class]].compact.join(" ")
|
193
|
+
|
194
|
+
options = convert_form_tag_options(method, options) if acts_like_form_tag
|
195
|
+
|
196
|
+
label = options.delete(:label)
|
197
|
+
label_class = hide_class if options.delete(:hide_label)
|
198
|
+
help = options.delete(:help)
|
199
|
+
label_col = options.delete(:label_col)
|
200
|
+
control_col = options.delete(:control_col)
|
201
|
+
layout = get_group_layout(options.delete(:layout))
|
202
|
+
|
203
|
+
form_group(method, label: { text: label, class: label_class }, help: help, label_col: label_col, control_col: control_col, layout: layout) do
|
204
|
+
yield
|
205
|
+
end
|
135
206
|
end
|
136
207
|
|
137
|
-
def
|
208
|
+
def convert_form_tag_options(method, options = {})
|
209
|
+
options[:name] ||= method
|
210
|
+
options[:id] ||= method
|
211
|
+
if options[:label]
|
212
|
+
options[:label][:for] ||= method
|
213
|
+
else
|
214
|
+
options[:label] = {for: method}
|
215
|
+
end
|
216
|
+
options
|
217
|
+
end
|
218
|
+
|
219
|
+
def generate_label(name, options, custom_label_col, group_layout)
|
138
220
|
if options
|
139
|
-
|
221
|
+
classes = [options[:class], label_class]
|
222
|
+
classes << (custom_label_col || label_col) if get_group_layout(group_layout) == :horizontal
|
223
|
+
options[:class] = classes.compact.join(" ")
|
224
|
+
|
140
225
|
label(name, options[:text], options.except(:text))
|
141
|
-
elsif horizontal
|
226
|
+
elsif get_group_layout(group_layout) == :horizontal
|
142
227
|
# no label. create an empty one to keep proper form alignment.
|
143
|
-
content_tag(:label, "", class:
|
228
|
+
content_tag(:label, "", class: "#{label_class} #{label_col}")
|
144
229
|
end
|
145
230
|
end
|
146
231
|
|
147
232
|
def generate_help(name, help_text)
|
148
|
-
help_text = object.errors[name].join(
|
149
|
-
content_tag(:span, help_text, class:
|
233
|
+
help_text = object.errors[name].join(", ") if has_error?(name) && inline_errors
|
234
|
+
content_tag(:span, help_text, class: "help-block") if help_text
|
235
|
+
end
|
236
|
+
|
237
|
+
def inputs_collection(name, collection, value, text, options = {}, &block)
|
238
|
+
form_group_builder(name, options) do
|
239
|
+
inputs = ""
|
240
|
+
|
241
|
+
collection.each do |obj|
|
242
|
+
input_options = options.merge(label: obj.send(text))
|
243
|
+
input_options[:checked] = input_options[:checked] == obj.send(value) if input_options[:checked]
|
244
|
+
|
245
|
+
input_options.delete(:class)
|
246
|
+
inputs << block.call(name, obj.send(value), input_options)
|
247
|
+
end
|
248
|
+
|
249
|
+
inputs.html_safe
|
250
|
+
end
|
150
251
|
end
|
151
252
|
end
|
152
253
|
end
|
@@ -3,16 +3,16 @@ module BootstrapForm
|
|
3
3
|
def bootstrap_form_for(object, options = {}, &block)
|
4
4
|
options[:builder] = BootstrapForm::FormBuilder
|
5
5
|
|
6
|
-
|
6
|
+
layout = case options[:layout]
|
7
7
|
when :inline
|
8
8
|
"form-inline"
|
9
9
|
when :horizontal
|
10
10
|
"form-horizontal"
|
11
11
|
end
|
12
12
|
|
13
|
-
if
|
13
|
+
if layout
|
14
14
|
options[:html] ||= {}
|
15
|
-
options[:html][:class] =
|
15
|
+
options[:html][:class] = [options[:html][:class], layout].compact.join(" ")
|
16
16
|
end
|
17
17
|
|
18
18
|
temporarily_disable_field_error_proc do
|
@@ -20,6 +20,12 @@ module BootstrapForm
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def bootstrap_form_tag(options = {}, &block)
|
24
|
+
options[:acts_like_form_tag] = true
|
25
|
+
|
26
|
+
bootstrap_form_for("", options, &block)
|
27
|
+
end
|
28
|
+
|
23
29
|
def temporarily_disable_field_error_proc
|
24
30
|
original_proc = ActionView::Base.field_error_proc
|
25
31
|
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
data/test/bootstrap_form_test.rb
CHANGED
@@ -5,8 +5,8 @@ class BootstrapFormTest < ActionView::TestCase
|
|
5
5
|
|
6
6
|
def setup
|
7
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, {
|
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" })
|
10
10
|
end
|
11
11
|
|
12
12
|
test "default-style forms" do
|
@@ -16,229 +16,379 @@ class BootstrapFormTest < ActionView::TestCase
|
|
16
16
|
|
17
17
|
test "inline-style forms" do
|
18
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="✓" /></div></form>}
|
19
|
-
assert_equal expected, bootstrap_form_for(@user,
|
19
|
+
assert_equal expected, bootstrap_form_for(@user, layout: :inline) { |f| nil }
|
20
20
|
end
|
21
21
|
|
22
22
|
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="✓" /></div><div class="form-group"><label class="col-sm-2
|
24
|
-
assert_equal expected, bootstrap_form_for(@user,
|
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="✓" /></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
|
+
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email }
|
25
25
|
end
|
26
26
|
|
27
27
|
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="✓" /></div><div class="form-group"><label class="col-sm-2
|
29
|
-
assert_equal expected, bootstrap_form_for(@user,
|
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="✓" /></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
|
+
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email }
|
30
|
+
end
|
31
|
+
|
32
|
+
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="✓" /></div><div class="form-group"><label class="control-label" for="email">Email</label><input class="form-control" id="email" name="email" type="text" /></div></form>}
|
34
|
+
assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email }
|
35
|
+
end
|
36
|
+
|
37
|
+
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="✓" /></div><div class="form-group"><label class="control-label" for="FOR">Email</label><input class="form-control" id="ID" name="NAME" type="text" /></div></form>}
|
39
|
+
assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, label: {for: 'FOR'}, name: 'NAME', id: "ID" }
|
30
40
|
end
|
31
41
|
|
32
42
|
test "alert message is wrapped correctly" do
|
33
43
|
@user.email = nil
|
34
44
|
@user.valid?
|
35
|
-
expected = %{<div class="alert alert-danger">Please fix the following errors:</div>}
|
45
|
+
expected = %{<div class="alert alert-danger"><p>Please fix the following errors:</p></div>}
|
36
46
|
assert_equal expected, @builder.alert_message('Please fix the following errors:')
|
37
47
|
end
|
38
48
|
|
39
49
|
test "changing the class name for the alert message" do
|
40
50
|
@user.email = nil
|
41
51
|
@user.valid?
|
42
|
-
expected = %{<div class="my-css-class">Please fix the following errors:</div>}
|
52
|
+
expected = %{<div class="my-css-class"><p>Please fix the following errors:</p></div>}
|
43
53
|
assert_equal expected, @builder.alert_message('Please fix the following errors:', class: 'my-css-class')
|
44
54
|
end
|
45
55
|
|
46
|
-
test "
|
47
|
-
|
48
|
-
|
56
|
+
test "alert_message contains the error summary when inline_errors are turned off" do
|
57
|
+
@user.email = nil
|
58
|
+
@user.valid?
|
59
|
+
|
60
|
+
output = bootstrap_form_for(@user, inline_errors: false) do |f|
|
61
|
+
f.alert_message('Please fix the following errors:')
|
62
|
+
end
|
63
|
+
|
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="✓" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p><ul class="rails-bootstrap-forms-error-summary"><li>Email can't be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul></div></form>}
|
65
|
+
assert_equal expected, output
|
49
66
|
end
|
50
67
|
|
51
|
-
test "
|
52
|
-
|
53
|
-
|
68
|
+
test "alert_message allows the error_summary to be turned off" do
|
69
|
+
@user.email = nil
|
70
|
+
@user.valid?
|
71
|
+
|
72
|
+
output = bootstrap_form_for(@user, inline_errors: false) do |f|
|
73
|
+
f.alert_message('Please fix the following errors:', error_summary: false)
|
74
|
+
end
|
75
|
+
|
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="✓" /></div><div class="alert alert-danger"><p>Please fix the following errors:</p></div></form>}
|
77
|
+
assert_equal expected, output
|
54
78
|
end
|
55
79
|
|
56
|
-
test "
|
57
|
-
|
58
|
-
|
80
|
+
test "error_summary returns an unordered list of errors" do
|
81
|
+
@user.email = nil
|
82
|
+
@user.valid?
|
83
|
+
|
84
|
+
expected = %{<ul class="rails-bootstrap-forms-error-summary"><li>Email can't be blank</li><li>Email is too short (minimum is 5 characters)</li><li>Terms must be accepted</li></ul>}
|
85
|
+
assert_equal expected, @builder.error_summary
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'errors_on renders the errors for a specific attribute when invalid' do
|
89
|
+
@user.email = nil
|
90
|
+
@user.valid?
|
91
|
+
|
92
|
+
expected = %{<div class="alert alert-danger">Email can't be blank, Email is too short (minimum is 5 characters)</div>}
|
93
|
+
assert_equal expected, @builder.errors_on(:email)
|
94
|
+
end
|
95
|
+
|
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)
|
59
119
|
end
|
60
120
|
|
61
121
|
test "file fields are wrapped correctly" do
|
62
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><input
|
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>}
|
63
123
|
assert_equal expected, @builder.file_field(:misc)
|
64
124
|
end
|
65
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
|
+
|
66
136
|
test "number fields are wrapped correctly" do
|
67
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="number" /></div>}
|
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>}
|
68
138
|
assert_equal expected, @builder.number_field(:misc)
|
69
139
|
end
|
70
140
|
|
71
|
-
test "
|
72
|
-
expected = %{<div class="form-group"><label for="
|
73
|
-
assert_equal expected, @builder.
|
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)
|
74
144
|
end
|
75
145
|
|
76
|
-
test "telephone
|
77
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="tel" /></div>}
|
78
|
-
assert_equal expected, @builder.telephone_field(:misc)
|
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>}
|
79
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)
|
80
175
|
end
|
81
176
|
|
82
177
|
test "url fields are wrapped correctly" do
|
83
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="url" /></div>}
|
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>}
|
84
179
|
assert_equal expected, @builder.url_field(:misc)
|
85
180
|
end
|
86
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
|
+
|
87
187
|
test "selects are wrapped correctly" do
|
88
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
89
189
|
assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]])
|
90
190
|
end
|
91
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
|
+
|
92
197
|
test "selects with options are wrapped correctly" do
|
93
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
94
199
|
assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prompt: "Please Select")
|
95
200
|
end
|
96
201
|
|
97
202
|
test "selects with both options and html_options are wrapped correctly" do
|
98
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
99
204
|
assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select")
|
100
205
|
end
|
101
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
|
+
|
102
212
|
test "collection_selects are wrapped correctly" do
|
103
|
-
expected = %{<div class="form-group"><label for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"></select></div>}
|
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>}
|
104
214
|
assert_equal expected, @builder.collection_select(:status, [], :id, :name)
|
105
215
|
end
|
106
216
|
|
107
217
|
test "collection_selects with options are wrapped correctly" do
|
108
|
-
expected = %{<div class="form-group"><label for="user_status">Status</label><select class="form-control" id="user_status" name="user[status]"><option value="">Please Select</option>\n</select></div>}
|
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>}
|
109
219
|
assert_equal expected, @builder.collection_select(:status, [], :id, :name, prompt: "Please Select")
|
110
220
|
end
|
111
221
|
|
112
222
|
test "collection_selects with options and html_options are wrapped correctly" do
|
113
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
114
224
|
assert_equal expected, @builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select")
|
115
225
|
end
|
116
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
|
+
|
117
242
|
test "date selects are wrapped correctly" do
|
118
243
|
Timecop.freeze(Time.utc(2012, 2, 3)) do
|
119
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
120
245
|
assert_equal expected, @builder.date_select(:misc)
|
121
246
|
end
|
122
247
|
end
|
123
248
|
|
124
249
|
test "date selects with options are wrapped correctly" do
|
125
250
|
Timecop.freeze(Time.utc(2012, 2, 3)) do
|
126
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
127
252
|
assert_equal expected, @builder.date_select(:misc, include_blank: true)
|
128
253
|
end
|
129
254
|
end
|
130
255
|
|
131
256
|
test "date selects with options and html_options are wrapped correctly" do
|
132
257
|
Timecop.freeze(Time.utc(2012, 2, 3)) do
|
133
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
134
259
|
assert_equal expected, @builder.date_select(:misc, { include_blank: true }, class: "my-date-select")
|
135
260
|
end
|
136
261
|
end
|
137
262
|
|
138
263
|
test "time selects are wrapped correctly" do
|
139
264
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
140
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
141
266
|
assert_equal expected, @builder.time_select(:misc)
|
142
267
|
end
|
143
268
|
end
|
144
269
|
|
145
270
|
test "time selects with options are wrapped correctly" do
|
146
271
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
147
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
148
273
|
assert_equal expected, @builder.time_select(:misc, include_blank: true)
|
149
274
|
end
|
150
275
|
end
|
151
276
|
|
152
277
|
test "time selects with options and html_options are wrapped correctly" do
|
153
278
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
154
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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>}
|
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>}
|
155
280
|
assert_equal expected, @builder.time_select(:misc, { include_blank: true }, class: "my-time-select")
|
156
281
|
end
|
157
282
|
end
|
158
283
|
|
159
284
|
test "datetime selects are wrapped correctly" do
|
160
285
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
161
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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 — <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>}
|
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 — <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>}
|
162
287
|
assert_equal expected, @builder.datetime_select(:misc)
|
163
288
|
end
|
164
289
|
end
|
165
290
|
|
166
291
|
test "datetime selects with options are wrapped correctly" do
|
167
292
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
168
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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 — <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>}
|
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 — <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>}
|
169
294
|
assert_equal expected, @builder.datetime_select(:misc, include_blank: true)
|
170
295
|
end
|
171
296
|
end
|
172
297
|
|
173
298
|
test "datetime selects with options and html_options are wrapped correctly" do
|
174
299
|
Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
|
175
|
-
expected = %{<div class="form-group"><label for="user_misc">Misc</label><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 — <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>}
|
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 — <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>}
|
176
301
|
assert_equal expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select")
|
177
302
|
end
|
178
303
|
end
|
179
304
|
|
180
305
|
test "check_box is wrapped correctly" do
|
181
|
-
expected = %{<div class="checkbox"><label for="
|
182
|
-
assert_equal expected, @builder.check_box(:
|
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" }
|
183
318
|
end
|
184
319
|
|
185
320
|
test "check_box responds to checked_value and unchecked_value arguments" do
|
186
|
-
expected = %{<div class="checkbox"><label for="
|
187
|
-
assert_equal expected, @builder.check_box(:
|
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')
|
188
323
|
end
|
189
324
|
|
190
325
|
test "inline checkboxes" do
|
191
|
-
expected = %{<label class="checkbox-inline" for="
|
192
|
-
assert_equal expected, @builder.check_box(:
|
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)
|
193
328
|
end
|
194
329
|
|
195
330
|
test "radio_button is wrapped correctly" do
|
196
|
-
expected = %{<label class="radio"
|
331
|
+
expected = %{<label class="radio"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
|
197
332
|
assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button')
|
198
333
|
end
|
199
334
|
|
200
|
-
test "radio_button inline label is
|
201
|
-
expected = %{<label class="radio-inline"
|
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>}
|
202
337
|
assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true)
|
203
338
|
end
|
204
339
|
|
205
340
|
test "changing the label text" do
|
206
|
-
expected = %{<div class="form-group"><label for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
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>}
|
207
342
|
assert_equal expected, @builder.text_field(:email, label: 'Email Address')
|
208
343
|
end
|
209
344
|
|
210
345
|
test "hiding a label" do
|
211
|
-
expected = %{<div class="form-group"><label class="sr-only" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
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>}
|
212
347
|
assert_equal expected, @builder.text_field(:email, hide_label: true)
|
213
348
|
end
|
214
349
|
|
215
350
|
test "adding prepend text" do
|
216
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
217
352
|
assert_equal expected, @builder.text_field(:email, prepend: '@')
|
218
353
|
end
|
219
354
|
|
220
355
|
test "adding append text" do
|
221
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
222
357
|
assert_equal expected, @builder.text_field(:email, append: '.00')
|
223
358
|
end
|
224
359
|
|
225
360
|
test "adding both prepend and append text" do
|
226
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
227
362
|
assert_equal expected, @builder.text_field(:email, prepend: '$', append: '.00')
|
228
363
|
end
|
229
364
|
|
230
365
|
test "help messages for default forms" do
|
231
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
232
367
|
assert_equal expected, @builder.text_field(:email, help: 'This is required')
|
233
368
|
end
|
234
369
|
|
235
370
|
test "help messages for horizontal forms" do
|
236
|
-
expected = %{<div class="form-group"><label class="col-sm-2
|
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>}
|
237
372
|
assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required")
|
238
373
|
end
|
239
374
|
|
375
|
+
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="✓" /></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
|
+
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' }
|
378
|
+
end
|
379
|
+
|
380
|
+
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="✓" /></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
|
+
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' }
|
383
|
+
end
|
384
|
+
|
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="✓" /></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
|
+
|
240
390
|
test "passing options to a form control get passed through" do
|
241
|
-
expected = %{<div class="form-group"><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>}
|
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>}
|
242
392
|
assert_equal expected, @builder.text_field(:email, autofocus: true)
|
243
393
|
end
|
244
394
|
|
@@ -247,7 +397,7 @@ class BootstrapFormTest < ActionView::TestCase
|
|
247
397
|
%{<p class="form-control-static">Bar</p>}.html_safe
|
248
398
|
end
|
249
399
|
|
250
|
-
expected = %{<div class="form-group"><label class="col-sm-2
|
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>}
|
251
401
|
assert_equal expected, output
|
252
402
|
end
|
253
403
|
|
@@ -256,7 +406,7 @@ class BootstrapFormTest < ActionView::TestCase
|
|
256
406
|
%{<p class="form-control-static">Bar</p>}.html_safe
|
257
407
|
end
|
258
408
|
|
259
|
-
expected = %{<div class="form-group"><label class="col-sm-2
|
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>}
|
260
410
|
assert_equal expected, output
|
261
411
|
end
|
262
412
|
|
@@ -265,7 +415,23 @@ class BootstrapFormTest < ActionView::TestCase
|
|
265
415
|
%{<p class="form-control-static">Bar</p>}.html_safe
|
266
416
|
end
|
267
417
|
|
268
|
-
expected = %{<div class="form-group"><label class="col-sm-2
|
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 "static control" do
|
423
|
+
output = @horizontal_builder.static_control :email
|
424
|
+
|
425
|
+
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>}
|
426
|
+
assert_equal expected, output
|
427
|
+
end
|
428
|
+
|
429
|
+
test "static control doesn't require an actual attribute" do
|
430
|
+
output = @horizontal_builder.static_control nil, label: "My Label" do
|
431
|
+
"this is a test"
|
432
|
+
end
|
433
|
+
|
434
|
+
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>}
|
269
435
|
assert_equal expected, output
|
270
436
|
end
|
271
437
|
|
@@ -274,7 +440,7 @@ class BootstrapFormTest < ActionView::TestCase
|
|
274
440
|
%{<p class="form-control-static">Bar</p>}.html_safe
|
275
441
|
end
|
276
442
|
|
277
|
-
expected = %{<div class="form-group"><label class="foo col-sm-2
|
443
|
+
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>}
|
278
444
|
assert_equal expected, output
|
279
445
|
end
|
280
446
|
|
@@ -290,6 +456,11 @@ class BootstrapFormTest < ActionView::TestCase
|
|
290
456
|
assert_equal expected, output
|
291
457
|
end
|
292
458
|
|
459
|
+
test "submit button defaults to rails action name" do
|
460
|
+
expected = %{<input class="btn btn-default" name="commit" type="submit" value="Create User" />}
|
461
|
+
assert_equal expected, @builder.submit
|
462
|
+
end
|
463
|
+
|
293
464
|
test "submit button uses default button classes" do
|
294
465
|
expected = %{<input class="btn btn-default" name="commit" type="submit" value="Submit Form" />}
|
295
466
|
assert_equal expected, @builder.submit("Submit Form")
|
@@ -300,15 +471,32 @@ class BootstrapFormTest < ActionView::TestCase
|
|
300
471
|
assert_equal expected, @builder.submit("Submit Form", class: "btn btn-primary")
|
301
472
|
end
|
302
473
|
|
474
|
+
test "primary button uses proper css classes" do
|
475
|
+
expected = %{<input class="btn btn-primary" name="commit" type="submit" value="Submit Form" />}
|
476
|
+
assert_equal expected, @builder.primary("Submit Form")
|
477
|
+
end
|
478
|
+
|
303
479
|
test "the field contains the error and is not wrapped in div.field_with_errors when bootstrap_form_for is used" do
|
304
480
|
@user.email = nil
|
305
481
|
@user.valid?
|
306
482
|
|
307
|
-
output = bootstrap_form_for(@user
|
483
|
+
output = bootstrap_form_for(@user) do |f|
|
308
484
|
f.text_field(:email, help: 'This is required')
|
309
485
|
end
|
310
486
|
|
311
|
-
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="✓" /></div><div class="form-group has-error"><label for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">can't be blank, is too short (minimum is 5 characters)</span></div></form>}
|
487
|
+
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="✓" /></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't be blank, is too short (minimum is 5 characters)</span></div></form>}
|
488
|
+
assert_equal expected, output
|
489
|
+
end
|
490
|
+
|
491
|
+
test "help is preserved when inline_errors: false is passed to bootstrap_form_for" do
|
492
|
+
@user.email = nil
|
493
|
+
@user.valid?
|
494
|
+
|
495
|
+
output = bootstrap_form_for(@user, inline_errors: false) do |f|
|
496
|
+
f.text_field(:email, help: 'This is required')
|
497
|
+
end
|
498
|
+
|
499
|
+
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="✓" /></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>}
|
312
500
|
assert_equal expected, output
|
313
501
|
end
|
314
502
|
|
@@ -316,11 +504,11 @@ class BootstrapFormTest < ActionView::TestCase
|
|
316
504
|
@user.email = nil
|
317
505
|
@user.valid?
|
318
506
|
|
319
|
-
output = form_for(@user, builder: BootstrapForm::FormBuilder
|
507
|
+
output = form_for(@user, builder: BootstrapForm::FormBuilder) do |f|
|
320
508
|
f.text_field(:email, help: 'This is required')
|
321
509
|
end
|
322
510
|
|
323
|
-
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="✓" /></div><div class="form-group has-error"><div class="field_with_errors"><label for="user_email">Email</label></div><div class="field_with_errors"><input class="form-control" id="user_email" name="user[email]" type="text" /></div><span class="help-block">can't be blank, is too short (minimum is 5 characters)</span></div></form>}
|
511
|
+
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="✓" /></div><div class="form-group 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="text" /></div><span class="help-block">can't be blank, is too short (minimum is 5 characters)</span></div></form>}
|
324
512
|
assert_equal expected, output
|
325
513
|
end
|
326
514
|
|
@@ -333,7 +521,7 @@ class BootstrapFormTest < ActionView::TestCase
|
|
333
521
|
end
|
334
522
|
end
|
335
523
|
|
336
|
-
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="✓" /></div><div class="form-group"><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>}
|
524
|
+
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="✓" /></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>}
|
337
525
|
assert_equal expected, output
|
338
526
|
end
|
339
527
|
|
@@ -346,39 +534,96 @@ class BootstrapFormTest < ActionView::TestCase
|
|
346
534
|
end
|
347
535
|
end
|
348
536
|
|
349
|
-
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="✓" /></div><div class="form-group"><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>}
|
537
|
+
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="✓" /></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>}
|
350
538
|
assert_equal expected, output
|
351
539
|
end
|
352
540
|
|
353
541
|
test "fields_for correctly passes horizontal style from parent builder" do
|
354
542
|
@user.address = Address.new(street: '123 Main Street')
|
355
543
|
|
356
|
-
output = bootstrap_form_for(@user,
|
544
|
+
output = bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-sm-2', control_col: 'col-sm-10') do |f|
|
357
545
|
f.fields_for :address do |af|
|
358
546
|
af.text_field(:street)
|
359
547
|
end
|
360
548
|
end
|
361
549
|
|
362
|
-
expected = %{<form accept-charset
|
550
|
+
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="✓" /></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>}
|
363
551
|
assert_equal expected, output
|
364
552
|
end
|
365
553
|
|
366
554
|
test "fields_for correctly passes inline style from parent builder" do
|
367
555
|
@user.address = Address.new(street: '123 Main Street')
|
368
556
|
|
369
|
-
output = bootstrap_form_for(@user,
|
557
|
+
output = bootstrap_form_for(@user, layout: :inline) do |f|
|
370
558
|
f.fields_for :address do |af|
|
371
559
|
af.text_field(:street)
|
372
560
|
end
|
373
561
|
end
|
374
562
|
|
375
|
-
expected = %{<form accept-charset
|
563
|
+
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="✓" /></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>}
|
376
564
|
assert_equal expected, output
|
377
565
|
end
|
378
566
|
|
379
567
|
test "allows the form object to be nil" do
|
380
|
-
builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {}
|
381
|
-
expected = %{<div class="form-group"><label for="other_model_email">Email</label><input class="form-control" id="other_model_email" name="other_model[email]" type="text" /></div>}
|
568
|
+
builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {}
|
569
|
+
expected = %{<div class="form-group"><label class="control-label" for="other_model_email">Email</label><input class="form-control" id="other_model_email" name="other_model[email]" type="text" /></div>}
|
382
570
|
assert_equal expected, builder.text_field(:email)
|
383
571
|
end
|
572
|
+
|
573
|
+
test 'collection_radio_buttons renders the form_group correctly' do
|
574
|
+
collection = [Address.new(id: 1, street: 'Foobar')]
|
575
|
+
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>}
|
576
|
+
|
577
|
+
assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!')
|
578
|
+
end
|
579
|
+
|
580
|
+
test 'collection_radio_buttons renders multiple radios correctly' do
|
581
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
582
|
+
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>}
|
583
|
+
|
584
|
+
assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street)
|
585
|
+
end
|
586
|
+
|
587
|
+
test 'collection_radio_buttons renders inline radios correctly' do
|
588
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
589
|
+
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>}
|
590
|
+
|
591
|
+
assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, inline: true)
|
592
|
+
end
|
593
|
+
|
594
|
+
test 'collection_radio_buttons renders with checked option correctly' do
|
595
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
596
|
+
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>}
|
597
|
+
|
598
|
+
assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, checked: 1)
|
599
|
+
end
|
600
|
+
|
601
|
+
test 'collection_check_boxes renders the form_group correctly' do
|
602
|
+
collection = [Address.new(id: 1, street: 'Foobar')]
|
603
|
+
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>}
|
604
|
+
|
605
|
+
assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!')
|
606
|
+
end
|
607
|
+
|
608
|
+
test 'collection_check_boxes renders multiple checkboxes correctly' do
|
609
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
610
|
+
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>}
|
611
|
+
|
612
|
+
assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street)
|
613
|
+
end
|
614
|
+
|
615
|
+
test 'collection_check_boxes renders inline checkboxes correctly' do
|
616
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
617
|
+
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>}
|
618
|
+
|
619
|
+
assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
|
620
|
+
end
|
621
|
+
|
622
|
+
test 'collection_check_boxes renders with checked option correctly' do
|
623
|
+
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
624
|
+
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>}
|
625
|
+
|
626
|
+
assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1)
|
627
|
+
end
|
628
|
+
|
384
629
|
end
|