bootstrap_form 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -7
- data/lib/bootstrap_form/version.rb +1 -1
- data/test/bootstrap_checkbox_test.rb +25 -25
- data/test/bootstrap_fields_test.rb +23 -23
- data/test/bootstrap_form_group_test.rb +39 -39
- data/test/bootstrap_form_test.rb +26 -26
- data/test/bootstrap_other_components_test.rb +8 -8
- data/test/bootstrap_radio_button_test.rb +18 -18
- data/test/bootstrap_selects_test.rb +22 -22
- data/test/dummy/Rakefile +4 -0
- data/test/dummy/config/environments/test.rb +19 -2
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +3172 -0
- data/test/special_form_class_models_test.rb +3 -3
- data/test/test_helper.rb +67 -1
- metadata +61 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d47ab6dce9854ae7580743006e9219430dcdc9
|
4
|
+
data.tar.gz: 39317c24d8571eb757babf24bb848d6a9bf67620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6cb05043d3866232ca763684370e46ecd2bfc181a682aef0f9785cd8548db050fec163e4523a5b349b639422d1ce406d1d2ff55e524914d13d76ba3f2d7b0c
|
7
|
+
data.tar.gz: bf12eadf490cb9fb286e8d67956881d544699acfa7766c025144c3b7825395d064ce02bafe19a6b966aeaadcdbfef73b54add03925abdb2662c67100d8f0b3b2
|
data/README.md
CHANGED
@@ -586,24 +586,31 @@ We love pull requests! Here's a quick guide for contributing:
|
|
586
586
|
|
587
587
|
1. Fork the repo.
|
588
588
|
|
589
|
-
2.
|
589
|
+
2. Install the required dependencies.
|
590
|
+
|
591
|
+
```
|
592
|
+
bundle install
|
593
|
+
bundle exec appraisal install
|
594
|
+
```
|
595
|
+
|
596
|
+
3. Run the existing test suite:
|
590
597
|
|
591
598
|
```
|
592
599
|
$ bundle exec rake -f test/dummy/Rakefile db:create db:migrate RAILS_ENV=test
|
593
|
-
$ bundle exec rake
|
600
|
+
$ bundle exec appraisal rake test
|
594
601
|
```
|
595
602
|
|
596
|
-
|
603
|
+
4. Add tests for your change.
|
597
604
|
|
598
|
-
|
605
|
+
5. Add your changes and make your test(s) pass. Following the conventions you
|
599
606
|
see used in the source will increase the chance that your pull request is
|
600
607
|
accepted right away.
|
601
608
|
|
602
|
-
|
609
|
+
6. Update the README if necessary.
|
603
610
|
|
604
|
-
|
611
|
+
7. Add a line to the CHANGELOG for your bug fix or feature.
|
605
612
|
|
606
|
-
|
613
|
+
8. Push to your fork and submit a pull request.
|
607
614
|
|
608
615
|
## Contributors
|
609
616
|
|
@@ -9,135 +9,135 @@ class BootstrapCheckboxTest < ActionView::TestCase
|
|
9
9
|
|
10
10
|
test "check_box is wrapped correctly" do
|
11
11
|
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>}
|
12
|
-
|
12
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms')
|
13
13
|
end
|
14
14
|
|
15
15
|
test "disabled check_box has proper wrapper classes" do
|
16
16
|
expected = %{<div class="checkbox disabled"><label for="user_terms"><input disabled="disabled" name="user[terms]" type="hidden" value="0" /><input disabled="disabled" id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label></div>}
|
17
|
-
|
17
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true)
|
18
18
|
end
|
19
19
|
|
20
20
|
test "check_box label allows html" do
|
21
21
|
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>}
|
22
|
-
|
22
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label: %{I agree to the <a href="#">terms</a>}.html_safe)
|
23
23
|
end
|
24
24
|
|
25
25
|
test "check_box accepts a block to define the label" do
|
26
26
|
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>}
|
27
|
-
|
27
|
+
assert_equivalent_xml expected, @builder.check_box(:terms) { "I agree to the terms" }
|
28
28
|
end
|
29
29
|
|
30
30
|
test "check_box accepts a custom label class" do
|
31
31
|
expected = %{<div class="checkbox"><label class="btn" for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> Terms</label></div>}
|
32
|
-
|
32
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label_class: 'btn')
|
33
33
|
end
|
34
34
|
|
35
35
|
test "check_box responds to checked_value and unchecked_value arguments" do
|
36
36
|
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>}
|
37
|
-
|
37
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no')
|
38
38
|
end
|
39
39
|
|
40
40
|
test "inline checkboxes" do
|
41
41
|
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>}
|
42
|
-
|
42
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true)
|
43
43
|
end
|
44
44
|
|
45
45
|
test "disabled inline check_box" do
|
46
46
|
expected = %{<label class="checkbox-inline disabled" for="user_terms"><input disabled="disabled" name="user[terms]" type="hidden" value="0" /><input disabled="disabled" id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label>}
|
47
|
-
|
47
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true)
|
48
48
|
end
|
49
49
|
|
50
50
|
test "inline checkboxes with custom label class" do
|
51
51
|
expected = %{<label class="checkbox-inline btn" for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> Terms</label>}
|
52
|
-
|
52
|
+
assert_equivalent_xml expected, @builder.check_box(:terms, inline: true, label_class: 'btn')
|
53
53
|
end
|
54
54
|
|
55
55
|
test 'collection_check_boxes renders the form_group correctly' do
|
56
56
|
collection = [Address.new(id: 1, street: 'Foobar')]
|
57
57
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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>}
|
58
58
|
|
59
|
-
|
59
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!')
|
60
60
|
end
|
61
61
|
|
62
62
|
test 'collection_check_boxes renders multiple checkboxes correctly' do
|
63
63
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
64
64
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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>}
|
65
65
|
|
66
|
-
|
66
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street)
|
67
67
|
end
|
68
68
|
|
69
69
|
test 'collection_check_boxes renders inline checkboxes correctly' do
|
70
70
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
71
71
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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>}
|
72
72
|
|
73
|
-
|
73
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
|
74
74
|
end
|
75
75
|
|
76
76
|
test 'collection_check_boxes renders with checked option correctly' do
|
77
77
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
78
78
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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>}
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1)
|
81
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first)
|
82
82
|
end
|
83
83
|
|
84
84
|
test 'collection_check_boxes renders with multiple checked options correctly' do
|
85
85
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
86
86
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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 checked="checked" id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> Bar</label></div></div>}
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2])
|
89
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection)
|
90
90
|
end
|
91
91
|
|
92
92
|
test 'collection_check_boxes sanitizes values when generating label `for`' do
|
93
93
|
collection = [Address.new(id: 1, street: 'Foo St')]
|
94
94
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_foo_st"><input id="user_misc_foo_st" name="user[misc][]" type="checkbox" value="Foo St" /> Foo St</label></div></div>}
|
95
95
|
|
96
|
-
|
96
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :street, :street)
|
97
97
|
end
|
98
98
|
|
99
99
|
test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do
|
100
100
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
101
101
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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" /> ooF</label></div><div class="checkbox"><label for="user_misc_2"><input id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> raB</label></div></div>}
|
102
102
|
|
103
|
-
|
103
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse })
|
104
104
|
end
|
105
105
|
|
106
106
|
test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do
|
107
107
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
108
108
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_address_1"><input id="user_misc_address_1" name="user[misc][]" type="checkbox" value="address_1" /> Foo</label></div><div class="checkbox"><label for="user_misc_address_2"><input id="user_misc_address_2" name="user[misc][]" type="checkbox" value="address_2" /> Bar</label></div></div>}
|
109
109
|
|
110
|
-
|
110
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street)
|
111
111
|
end
|
112
112
|
|
113
113
|
test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do
|
114
114
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
115
115
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><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" /> ooF</label></div><div class="checkbox"><label for="user_misc_2"><input id="user_misc_2" name="user[misc][]" type="checkbox" value="2" /> raB</label></div></div>}
|
116
116
|
|
117
|
-
|
117
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse })
|
118
118
|
end
|
119
119
|
|
120
120
|
test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do
|
121
121
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
122
122
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_address_1"><input id="user_misc_address_1" name="user[misc][]" type="checkbox" value="address_1" /> Foo</label></div><div class="checkbox"><label for="user_misc_address_2"><input id="user_misc_address_2" name="user[misc][]" type="checkbox" value="address_2" /> Bar</label></div></div>}
|
123
123
|
|
124
|
-
|
124
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street)
|
125
125
|
end
|
126
126
|
|
127
127
|
test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do
|
128
128
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
129
129
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_address_1"><input checked="checked" id="user_misc_address_1" name="user[misc][]" type="checkbox" value="address_1" /> Foo</label></div><div class="checkbox"><label for="user_misc_address_2"><input id="user_misc_address_2" name="user[misc][]" type="checkbox" value="address_2" /> Bar</label></div></div>}
|
130
130
|
|
131
|
-
|
132
|
-
|
131
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1")
|
132
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first)
|
133
133
|
end
|
134
134
|
|
135
135
|
test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do
|
136
136
|
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
137
137
|
expected = %{<input id="user_misc" multiple="multiple" name="user[misc][]" type="hidden" value="" /><div class="form-group"><label class="control-label" for="user_misc">Misc</label><div class="checkbox"><label for="user_misc_address_1"><input checked="checked" id="user_misc_address_1" name="user[misc][]" type="checkbox" value="address_1" /> Foo</label></div><div class="checkbox"><label for="user_misc_address_2"><input checked="checked" id="user_misc_address_2" name="user[misc][]" type="checkbox" value="address_2" /> Bar</label></div></div>}
|
138
138
|
|
139
|
-
|
140
|
-
|
139
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"])
|
140
|
+
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection)
|
141
141
|
end
|
142
142
|
|
143
143
|
|
@@ -9,93 +9,93 @@ class BootstrapFieldsTest < ActionView::TestCase
|
|
9
9
|
|
10
10
|
test "color fields are wrapped correctly" do
|
11
11
|
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>}
|
12
|
-
|
12
|
+
assert_equivalent_xml expected, @builder.color_field(:misc)
|
13
13
|
end
|
14
14
|
|
15
15
|
test "date fields are wrapped correctly" do
|
16
16
|
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>}
|
17
|
-
|
17
|
+
assert_equivalent_xml expected, @builder.date_field(:misc)
|
18
18
|
end
|
19
19
|
|
20
20
|
test "date time fields are wrapped correctly" do
|
21
21
|
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>}
|
22
|
-
|
22
|
+
assert_equivalent_xml expected, @builder.datetime_field(:misc)
|
23
23
|
end
|
24
24
|
|
25
25
|
test "date time local fields are wrapped correctly" do
|
26
26
|
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>}
|
27
|
-
|
27
|
+
assert_equivalent_xml expected, @builder.datetime_local_field(:misc)
|
28
28
|
end
|
29
29
|
|
30
30
|
test "email fields are wrapped correctly" do
|
31
31
|
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>}
|
32
|
-
|
32
|
+
assert_equivalent_xml expected, @builder.email_field(:misc)
|
33
33
|
end
|
34
34
|
|
35
35
|
test "file fields are wrapped correctly" do
|
36
36
|
expected = %{<div class="form-group"><label class="control-label" for="user_misc">Misc</label><input id="user_misc" name="user[misc]" type="file" /></div>}
|
37
|
-
|
37
|
+
assert_equivalent_xml expected, @builder.file_field(:misc)
|
38
38
|
end
|
39
39
|
|
40
40
|
test "hidden fields are supported" do
|
41
41
|
expected = %{<input id="user_misc" name="user[misc]" type="hidden" />}
|
42
|
-
|
42
|
+
assert_equivalent_xml expected, @builder.hidden_field(:misc)
|
43
43
|
end
|
44
44
|
|
45
45
|
test "month local fields are wrapped correctly" do
|
46
46
|
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>}
|
47
|
-
|
47
|
+
assert_equivalent_xml expected, @builder.month_field(:misc)
|
48
48
|
end
|
49
49
|
|
50
50
|
test "number fields are wrapped correctly" do
|
51
51
|
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>}
|
52
|
-
|
52
|
+
assert_equivalent_xml expected, @builder.number_field(:misc)
|
53
53
|
end
|
54
54
|
|
55
55
|
test "password fields are wrapped correctly" do
|
56
56
|
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" /><span class="help-block">A good password should be at least six characters long</span></div>}
|
57
|
-
|
57
|
+
assert_equivalent_xml expected, @builder.password_field(:password)
|
58
58
|
end
|
59
59
|
|
60
60
|
test "phone/telephone fields are wrapped correctly" do
|
61
61
|
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>}
|
62
|
-
|
63
|
-
|
62
|
+
assert_equivalent_xml expected, @builder.phone_field(:misc)
|
63
|
+
assert_equivalent_xml expected, @builder.telephone_field(:misc)
|
64
64
|
end
|
65
65
|
|
66
66
|
test "range fields are wrapped correctly" do
|
67
67
|
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>}
|
68
|
-
|
68
|
+
assert_equivalent_xml expected, @builder.range_field(:misc)
|
69
69
|
end
|
70
70
|
|
71
71
|
test "search fields are wrapped correctly" do
|
72
72
|
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>}
|
73
|
-
|
73
|
+
assert_equivalent_xml expected, @builder.search_field(:misc)
|
74
74
|
end
|
75
75
|
|
76
76
|
test "text areas are wrapped correctly" do
|
77
77
|
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>}
|
78
|
-
|
78
|
+
assert_equivalent_xml expected, @builder.text_area(:comments)
|
79
79
|
end
|
80
80
|
|
81
81
|
test "text fields are wrapped correctly" do
|
82
82
|
expected = %{<div class="form-group"><label class="control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
83
|
-
|
83
|
+
assert_equivalent_xml expected, @builder.text_field(:email)
|
84
84
|
end
|
85
85
|
|
86
86
|
test "time fields are wrapped correctly" do
|
87
87
|
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>}
|
88
|
-
|
88
|
+
assert_equivalent_xml expected, @builder.time_field(:misc)
|
89
89
|
end
|
90
90
|
|
91
91
|
test "url fields are wrapped correctly" do
|
92
92
|
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>}
|
93
|
-
|
93
|
+
assert_equivalent_xml expected, @builder.url_field(:misc)
|
94
94
|
end
|
95
95
|
|
96
96
|
test "week fields are wrapped correctly" do
|
97
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="week" /></div>}
|
98
|
-
|
98
|
+
assert_equivalent_xml expected, @builder.week_field(:misc)
|
99
99
|
end
|
100
100
|
|
101
101
|
test "bootstrap_form_for helper works for associations" do
|
@@ -108,7 +108,7 @@ class BootstrapFieldsTest < ActionView::TestCase
|
|
108
108
|
end
|
109
109
|
|
110
110
|
expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></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>}
|
111
|
-
|
111
|
+
assert_equivalent_xml expected, output
|
112
112
|
end
|
113
113
|
|
114
114
|
test "bootstrap_form_for helper works for serialized hash attributes" do
|
@@ -121,7 +121,7 @@ class BootstrapFieldsTest < ActionView::TestCase
|
|
121
121
|
end
|
122
122
|
|
123
123
|
expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></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>}
|
124
|
-
|
124
|
+
assert_equivalent_xml expected, output
|
125
125
|
end
|
126
126
|
|
127
127
|
test "fields_for correctly passes horizontal style from parent builder" do
|
@@ -134,7 +134,7 @@ class BootstrapFieldsTest < ActionView::TestCase
|
|
134
134
|
end
|
135
135
|
|
136
136
|
expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></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>}
|
137
|
-
|
137
|
+
assert_equivalent_xml expected, output
|
138
138
|
end
|
139
139
|
|
140
140
|
test "fields_for correctly passes inline style from parent builder" do
|
@@ -147,6 +147,6 @@ class BootstrapFieldsTest < ActionView::TestCase
|
|
147
147
|
end
|
148
148
|
|
149
149
|
expected = %{<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></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>}
|
150
|
-
|
150
|
+
assert_equivalent_xml expected, output
|
151
151
|
end
|
152
152
|
end
|
@@ -9,52 +9,52 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
9
9
|
|
10
10
|
test "changing the label text via the label option parameter" do
|
11
11
|
expected = %{<div class="form-group"><label class="control-label required" for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
12
|
-
|
12
|
+
assert_equivalent_xml expected, @builder.text_field(:email, label: 'Email Address')
|
13
13
|
end
|
14
14
|
|
15
15
|
test "changing the label text via the html_options label hash" do
|
16
16
|
expected = %{<div class="form-group"><label class="control-label required" for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
17
|
-
|
17
|
+
assert_equivalent_xml expected, @builder.text_field(:email, label: {text: 'Email Address'})
|
18
18
|
end
|
19
19
|
|
20
20
|
test "hiding a label" do
|
21
21
|
expected = %{<div class="form-group"><label class="sr-only control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
22
|
-
|
22
|
+
assert_equivalent_xml expected, @builder.text_field(:email, hide_label: true)
|
23
23
|
end
|
24
24
|
|
25
25
|
test "adding a custom label class via the label_class parameter" do
|
26
26
|
expected = %{<div class="form-group"><label class="btn control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
27
|
-
|
27
|
+
assert_equivalent_xml expected, @builder.text_field(:email, label_class: 'btn')
|
28
28
|
end
|
29
29
|
|
30
30
|
test "adding a custom label class via the html_options label hash" do
|
31
31
|
expected = %{<div class="form-group"><label class="btn control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
32
|
-
|
32
|
+
assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn'})
|
33
33
|
end
|
34
34
|
|
35
35
|
test "adding a custom label and changing the label text via the html_options label hash" do
|
36
36
|
expected = %{<div class="form-group"><label class="btn control-label required" for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
37
|
-
|
37
|
+
assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"})
|
38
38
|
end
|
39
39
|
|
40
40
|
test "skipping a label" do
|
41
41
|
expected = %{<div class="form-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
42
|
-
|
42
|
+
assert_equivalent_xml expected, @builder.text_field(:email, skip_label: true)
|
43
43
|
end
|
44
44
|
|
45
45
|
test "preventing a label from having the required class" do
|
46
46
|
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>}
|
47
|
-
|
47
|
+
assert_equivalent_xml expected, @builder.text_field(:email, skip_required: true)
|
48
48
|
end
|
49
49
|
|
50
50
|
test "adding prepend text" do
|
51
51
|
expected = %{<div class="form-group"><label class="control-label required" 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>}
|
52
|
-
|
52
|
+
assert_equivalent_xml expected, @builder.text_field(:email, prepend: '@')
|
53
53
|
end
|
54
54
|
|
55
55
|
test "adding append text" do
|
56
56
|
expected = %{<div class="form-group"><label class="control-label required" 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>}
|
57
|
-
|
57
|
+
assert_equivalent_xml expected, @builder.text_field(:email, append: '.00')
|
58
58
|
end
|
59
59
|
|
60
60
|
test "append and prepend button" do
|
@@ -66,29 +66,29 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
66
66
|
before_button = prefix + button + field + suffix
|
67
67
|
both_button = prefix + button + field + button + suffix
|
68
68
|
button_src = link_to("Click", "#", class: "btn btn-default")
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
assert_equivalent_xml after_button, @builder.text_field(:email, append: button_src)
|
70
|
+
assert_equivalent_xml before_button, @builder.text_field(:email, prepend: button_src)
|
71
|
+
assert_equivalent_xml both_button, @builder.text_field(:email, append: button_src, prepend: button_src)
|
72
72
|
end
|
73
73
|
|
74
74
|
test "adding both prepend and append text" do
|
75
75
|
expected = %{<div class="form-group"><label class="control-label required" 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>}
|
76
|
-
|
76
|
+
assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00')
|
77
77
|
end
|
78
78
|
|
79
79
|
test "help messages for default forms" do
|
80
80
|
expected = %{<div class="form-group"><label class="control-label required" 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>}
|
81
|
-
|
81
|
+
assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required')
|
82
82
|
end
|
83
83
|
|
84
84
|
test "help messages for horizontal forms" do
|
85
85
|
expected = %{<div class="form-group"><label class="control-label col-sm-2 required" 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>}
|
86
|
-
|
86
|
+
assert_equivalent_xml expected, @horizontal_builder.text_field(:email, help: "This is required")
|
87
87
|
end
|
88
88
|
|
89
89
|
test "help messages to look up I18n automatically" do
|
90
90
|
expected = %{<div class="form-group"><label class="control-label" for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="text" value="secret" /><span class="help-block">A good password should be at least six characters long</span></div>}
|
91
|
-
|
91
|
+
assert_equivalent_xml expected, @builder.text_field(:password)
|
92
92
|
end
|
93
93
|
|
94
94
|
test "help messages to warn about deprecated I18n key" do
|
@@ -111,7 +111,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
111
111
|
|
112
112
|
test "help messages to ignore translation when user disables help" do
|
113
113
|
expected = %{<div class="form-group"><label class="control-label" for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="text" value="secret" /></div>}
|
114
|
-
|
114
|
+
assert_equivalent_xml expected, @builder.text_field(:password, help: false)
|
115
115
|
end
|
116
116
|
|
117
117
|
test "form_group creates a valid structure and allows arbitrary html to be added via a block" do
|
@@ -120,7 +120,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
120
120
|
end
|
121
121
|
|
122
122
|
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>}
|
123
|
-
|
123
|
+
assert_equivalent_xml expected, output
|
124
124
|
end
|
125
125
|
|
126
126
|
test "form_group adds a spacer when no label exists for a horizontal form" do
|
@@ -129,7 +129,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
129
129
|
end
|
130
130
|
|
131
131
|
expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
|
132
|
-
|
132
|
+
assert_equivalent_xml expected, output
|
133
133
|
end
|
134
134
|
|
135
135
|
test "form_group renders the label correctly" do
|
@@ -138,7 +138,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
138
138
|
end
|
139
139
|
|
140
140
|
expected = %{<div class="form-group"><label class="control-label col-sm-2 required" for="user_email">Custom Control</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
|
141
|
-
|
141
|
+
assert_equivalent_xml expected, output
|
142
142
|
end
|
143
143
|
|
144
144
|
test "form_group accepts class thorugh options hash" do
|
@@ -147,7 +147,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
147
147
|
end
|
148
148
|
|
149
149
|
expected = %{<div class="form-group foo"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
|
150
|
-
|
150
|
+
assert_equivalent_xml expected, output
|
151
151
|
end
|
152
152
|
|
153
153
|
test "form_group accepts class thorugh options hash without needing a name" do
|
@@ -156,7 +156,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
156
156
|
end
|
157
157
|
|
158
158
|
expected = %{<div class="form-group foo"><div class="col-sm-10 col-sm-offset-2"><p class="form-control-static">Bar</p></div></div>}
|
159
|
-
|
159
|
+
assert_equivalent_xml expected, output
|
160
160
|
end
|
161
161
|
|
162
162
|
test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do
|
@@ -165,7 +165,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
165
165
|
end
|
166
166
|
|
167
167
|
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>}
|
168
|
-
|
168
|
+
assert_equivalent_xml expected, output
|
169
169
|
end
|
170
170
|
|
171
171
|
test 'form_group renders the "error" class and message corrrectly when object is invalid' do
|
@@ -177,12 +177,12 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
177
177
|
end
|
178
178
|
|
179
179
|
expected = %{<div class="form-group has-error"><p class="form-control-static">Bar</p><span class="help-block">can't be blank, is too short (minimum is 5 characters)</span></div>}
|
180
|
-
|
180
|
+
assert_equivalent_xml expected, output
|
181
181
|
end
|
182
182
|
|
183
183
|
test "adds class to wrapped form_group by a field" do
|
184
184
|
expected = %{<div class="form-group none-margin"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="search" /></div>}
|
185
|
-
|
185
|
+
assert_equivalent_xml expected, @builder.search_field(:misc, wrapper_class: 'none-margin')
|
186
186
|
end
|
187
187
|
|
188
188
|
test "adds class to wrapped form_group by a field with errors" do
|
@@ -190,7 +190,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
190
190
|
@user.valid?
|
191
191
|
|
192
192
|
expected = %{<div class="form-group none-margin has-error"><div class="field_with_errors"><label class="control-label required" for="user_email">Email</label></div><div class="field_with_errors"><input class="form-control" id="user_email" name="user[email]" type="email" /></div><span class="help-block">can't be blank, is too short (minimum is 5 characters)</span></div>}
|
193
|
-
|
193
|
+
assert_equivalent_xml expected, @builder.email_field(:email, wrapper_class: 'none-margin')
|
194
194
|
end
|
195
195
|
|
196
196
|
test "adds class to wrapped form_group by a field with errors when bootstrap_form_for is used" do
|
@@ -202,7 +202,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
202
202
|
end
|
203
203
|
|
204
204
|
expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><div class="form-group none-margin has-error"><label class="control-label required" 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>}
|
205
|
-
|
205
|
+
assert_equivalent_xml expected, output
|
206
206
|
end
|
207
207
|
|
208
208
|
test "adds offset for form_group without label" do
|
@@ -211,7 +211,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
211
211
|
end
|
212
212
|
|
213
213
|
expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2"><input class="btn btn-default" name="commit" type="submit" value="Create User" /></div></div>}
|
214
|
-
|
214
|
+
assert_equivalent_xml expected, output
|
215
215
|
end
|
216
216
|
|
217
217
|
test "adds offset for form_group without label but specific label_col" do
|
@@ -220,12 +220,12 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
220
220
|
end
|
221
221
|
|
222
222
|
expected = %{<div class="form-group"><div class="col-sm-8 col-sm-offset-5"><input class="btn btn-default" name="commit" type="submit" value="Create User" /></div></div>}
|
223
|
-
|
223
|
+
assert_equivalent_xml expected, output
|
224
224
|
end
|
225
225
|
|
226
226
|
test "adding an icon to a field" do
|
227
227
|
expected = %{<div class="form-group has-feedback"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="email" /><span class="glyphicon glyphicon-ok form-control-feedback"></span></div>}
|
228
|
-
|
228
|
+
assert_equivalent_xml expected, @builder.email_field(:misc, icon: 'ok')
|
229
229
|
end
|
230
230
|
|
231
231
|
test "single form_group call in horizontal form should not be smash design" do
|
@@ -237,17 +237,17 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
237
237
|
output = output + @horizontal_builder.text_field(:email)
|
238
238
|
|
239
239
|
expected = %{<div class="form-group"><div class="col-sm-10 col-sm-offset-2">Hallo</div></div><div class="form-group"><label class="control-label col-sm-2 required" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
|
240
|
-
|
240
|
+
assert_equivalent_xml expected, output
|
241
241
|
end
|
242
242
|
|
243
243
|
test "adds data-attributes (or any other options) to wrapper" do
|
244
244
|
expected = %{<div class="form-group" data-foo="bar"><label class="control-label" for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="search" /></div>}
|
245
|
-
|
245
|
+
assert_equivalent_xml expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } })
|
246
246
|
end
|
247
247
|
|
248
248
|
test "passing options to a form control get passed through" do
|
249
249
|
expected = %{<div class="form-group"><label class="control-label required" for="user_email">Email</label><input autofocus="autofocus" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
250
|
-
|
250
|
+
assert_equivalent_xml expected, @builder.text_field(:email, autofocus: true)
|
251
251
|
end
|
252
252
|
|
253
253
|
test "doesn't throw undefined method error when the content block returns nil" do
|
@@ -256,12 +256,12 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
256
256
|
end
|
257
257
|
|
258
258
|
expected = %{<div class="form-group"><label class="control-label" for="user_nil">Foo</label></div>}
|
259
|
-
|
259
|
+
assert_equivalent_xml expected, output
|
260
260
|
end
|
261
261
|
|
262
262
|
test "custom form group layout option" do
|
263
263
|
expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><div class="form-group"><label class="control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></form>}
|
264
|
-
|
264
|
+
assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline }
|
265
265
|
end
|
266
266
|
|
267
267
|
test "non-default column span on form is reflected in form_group" do
|
@@ -271,7 +271,7 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
271
271
|
end
|
272
272
|
|
273
273
|
expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3"><p class="form-control-static">Bar</p></div></div>}
|
274
|
-
|
274
|
+
assert_equivalent_xml expected, output
|
275
275
|
end
|
276
276
|
|
277
277
|
test "non-default column span on form isn't mutated" do
|
@@ -279,11 +279,11 @@ class BootstrapFormGroupTest < ActionView::TestCase
|
|
279
279
|
output = frozen_horizontal_builder.form_group { 'test' }
|
280
280
|
|
281
281
|
expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3">test</div></div>}
|
282
|
-
|
282
|
+
assert_equivalent_xml expected, output
|
283
283
|
end
|
284
284
|
|
285
285
|
test ":input_group_class should apply to input-group" do
|
286
286
|
expected = %{<div class="form-group"><label class="control-label required" for="user_email">Email</label><div class="input-group input-group-lg"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /><span class="input-group-btn"><input class="btn btn-primary" name="commit" type="submit" value="Subscribe" /></span></div></div>}
|
287
|
-
|
287
|
+
assert_equivalent_xml expected, @builder.email_field(:email, append: @builder.primary('Subscribe'), input_group_class: 'input-group-lg')
|
288
288
|
end
|
289
289
|
end
|