bootstrap_form 2.7.0 → 4.0.0.alpha1
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 +5 -5
- data/.gitignore +14 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +227 -0
- data/CONTRIBUTING.md +57 -0
- data/Dangerfile +54 -0
- data/Gemfile +21 -0
- data/{MIT-LICENSE → LICENSE.txt} +1 -1
- data/README.md +154 -87
- data/Rakefile +5 -15
- data/UPGRADE-4.0.md +79 -0
- data/bootstrap_form.gemspec +28 -0
- data/demo/README.md +17 -0
- data/demo/Rakefile +6 -0
- data/demo/app/controllers/application_controller.rb +2 -0
- data/demo/app/controllers/bootstrap_controller.rb +16 -0
- data/demo/app/helpers/bootstrap_helper.rb +23 -0
- data/{test/dummy → demo}/app/models/address.rb +0 -0
- data/demo/app/models/application_record.rb +3 -0
- data/{test/dummy → demo}/app/models/faux_user.rb +0 -0
- data/{test/dummy → demo}/app/models/super_user.rb +0 -0
- data/{test/dummy → demo}/app/models/user.rb +0 -0
- data/demo/app/views/bootstrap/form.html.erb +53 -0
- data/demo/app/views/layouts/application.html.erb +65 -0
- data/demo/bin/bundle +3 -0
- data/{test/dummy → demo}/bin/rails +1 -1
- data/{test/dummy → demo}/bin/rake +0 -0
- data/demo/bin/setup +36 -0
- data/demo/bin/update +31 -0
- data/demo/bin/yarn +11 -0
- data/{test/dummy → demo}/config.ru +2 -1
- data/demo/config/application.rb +24 -0
- data/demo/config/boot.rb +5 -0
- data/{test/dummy → demo}/config/database.yml +8 -12
- data/demo/config/environment.rb +5 -0
- data/demo/config/environments/development.rb +60 -0
- data/{test/dummy → demo}/config/environments/test.rb +15 -20
- data/demo/config/initializers/application_controller_renderer.rb +8 -0
- data/demo/config/initializers/assets.rb +14 -0
- data/{test/dummy → demo}/config/initializers/backtrace_silencers.rb +0 -0
- data/demo/config/initializers/cookies_serializer.rb +5 -0
- data/{test/dummy → demo}/config/initializers/filter_parameter_logging.rb +0 -0
- data/{test/dummy → demo}/config/initializers/inflections.rb +0 -0
- data/{test/dummy → demo}/config/initializers/mime_types.rb +0 -1
- data/{test/dummy → demo}/config/initializers/wrap_parameters.rb +2 -2
- data/{test/dummy → demo}/config/locales/en.yml +10 -0
- data/demo/config/puma.rb +56 -0
- data/{test/dummy → demo}/config/routes.rb +2 -0
- data/demo/config/spring.rb +6 -0
- data/demo/config/storage.yml +35 -0
- data/demo/db/schema.rb +24 -0
- data/{test/dummy/public/favicon.ico → demo/log/.keep} +0 -0
- data/demo/package.json +5 -0
- data/demo/public/favicon.ico +0 -0
- data/lib/bootstrap_form/form_builder.rb +221 -96
- data/lib/bootstrap_form/helper.rb +26 -16
- data/lib/bootstrap_form/helpers/bootstrap.rb +37 -24
- data/lib/bootstrap_form/version.rb +1 -1
- metadata +67 -252
- data/lib/bootstrap_form/helpers/nested_form.rb +0 -33
- data/test/bootstrap_checkbox_test.rb +0 -144
- data/test/bootstrap_fields_test.rb +0 -152
- data/test/bootstrap_form_group_test.rb +0 -289
- data/test/bootstrap_form_test.rb +0 -209
- data/test/bootstrap_other_components_test.rb +0 -86
- data/test/bootstrap_radio_button_test.rb +0 -124
- data/test/bootstrap_selects_test.rb +0 -160
- data/test/dummy/Gemfile +0 -45
- data/test/dummy/Gemfile.lock +0 -120
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -10
- data/test/dummy/app/assets/javascripts/application.js +0 -16
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/config/application.rb +0 -23
- data/test/dummy/config/boot.rb +0 -4
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -29
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/initializers/secret_token.rb +0 -12
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/db/migrate/20130703191909_create_users.rb +0 -13
- data/test/dummy/db/migrate/20130703191937_create_addresses.rb +0 -13
- data/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb +0 -5
- data/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb +0 -5
- data/test/dummy/db/migrate/20140922133133_add_type_to_users.rb +0 -5
- data/test/dummy/db/schema.rb +0 -39
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +0 -38160
- data/test/dummy/public/404.html +0 -58
- data/test/dummy/public/422.html +0 -58
- data/test/dummy/public/500.html +0 -57
- data/test/dummy/public/robots.txt +0 -5
- data/test/dummy/test/fixtures/addresses.yml +0 -15
- data/test/dummy/test/fixtures/users.yml +0 -15
- data/test/dummy/test/models/address_test.rb +0 -7
- data/test/dummy/test/models/user_test.rb +0 -7
- data/test/dummy/test/test_helper.rb +0 -15
- data/test/special_form_class_models_test.rb +0 -43
- data/test/test_helper.rb +0 -86
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
begin
|
|
2
|
-
require 'nested_form/builder_mixin'
|
|
3
|
-
|
|
4
|
-
module BootstrapForm
|
|
5
|
-
class NestedFormBuilder < ::BootstrapForm::FormBuilder
|
|
6
|
-
include ::NestedForm::BuilderMixin
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
module BootstrapForm
|
|
11
|
-
module Helpers
|
|
12
|
-
module NestedForm
|
|
13
|
-
def bootstrap_nested_form_for(object, options = {}, &block)
|
|
14
|
-
options.reverse_merge!({builder: BootstrapForm::NestedFormBuilder})
|
|
15
|
-
bootstrap_form_for(object, options) do |f|
|
|
16
|
-
capture(f, &block).to_s << after_nested_form_callbacks
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
rescue LoadError
|
|
24
|
-
module BootstrapForm
|
|
25
|
-
module Helpers
|
|
26
|
-
module NestedForm
|
|
27
|
-
def bootstrap_nested_form_for(object, options = {}, &block)
|
|
28
|
-
raise 'nested_forms was not found. Is it in your Gemfile?'
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class BootstrapCheckboxTest < ActionView::TestCase
|
|
4
|
-
include BootstrapForm::Helper
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
setup_test_fixture
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
test "check_box is wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "disabled check_box has proper wrapper classes" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test "check_box label allows html" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label: %{I agree to the <a href="#">terms</a>}.html_safe)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
test "check_box accepts a block to define the label" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms) { "I agree to the terms" }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "check_box accepts a custom label class" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label_class: 'btn')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "check_box responds to checked_value and unchecked_value arguments" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "inline checkboxes" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
test "disabled inline check_box" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "inline checkboxes with custom label class" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.check_box(:terms, inline: true, label_class: 'btn')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test 'collection_check_boxes renders the form_group correctly' do
|
|
56
|
-
collection = [Address.new(id: 1, street: 'Foobar')]
|
|
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
|
-
|
|
59
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!')
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
test 'collection_check_boxes renders multiple checkboxes correctly' do
|
|
63
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
66
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
test 'collection_check_boxes renders inline checkboxes correctly' do
|
|
70
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
73
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test 'collection_check_boxes renders with checked option correctly' do
|
|
77
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
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
|
-
end
|
|
83
|
-
|
|
84
|
-
test 'collection_check_boxes renders with multiple checked options correctly' do
|
|
85
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
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
|
-
end
|
|
91
|
-
|
|
92
|
-
test 'collection_check_boxes sanitizes values when generating label `for`' do
|
|
93
|
-
collection = [Address.new(id: 1, street: 'Foo St')]
|
|
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
|
-
|
|
96
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :street, :street)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do
|
|
100
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
103
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse })
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do
|
|
107
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
110
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do
|
|
114
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
117
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse })
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do
|
|
121
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
124
|
-
assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do
|
|
128
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
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
|
-
end
|
|
134
|
-
|
|
135
|
-
test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do
|
|
136
|
-
collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')]
|
|
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
|
-
|
|
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
|
-
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
end
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class BootstrapFieldsTest < ActionView::TestCase
|
|
4
|
-
include BootstrapForm::Helper
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
setup_test_fixture
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
test "color fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.color_field(:misc)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "date fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.date_field(:misc)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test "date time fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.datetime_field(:misc)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
test "date time local fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.datetime_local_field(:misc)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "email fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.email_field(:misc)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "file fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.file_field(:misc)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "hidden fields are supported" do
|
|
41
|
-
expected = %{<input id="user_misc" name="user[misc]" type="hidden" />}
|
|
42
|
-
assert_equivalent_xml expected, @builder.hidden_field(:misc)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
test "month local fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.month_field(:misc)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "number fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.number_field(:misc)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test "password fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.password_field(:password)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "phone/telephone fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.phone_field(:misc)
|
|
63
|
-
assert_equivalent_xml expected, @builder.telephone_field(:misc)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test "range fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.range_field(:misc)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
test "search fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.search_field(:misc)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test "text areas are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_area(:comments)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test "text fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
test "time fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.time_field(:misc)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
test "url fields are wrapped correctly" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.url_field(:misc)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
test "week 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="week" /></div>}
|
|
98
|
-
assert_equivalent_xml expected, @builder.week_field(:misc)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
test "bootstrap_form_for helper works for associations" do
|
|
102
|
-
@user.address = Address.new(street: '123 Main Street')
|
|
103
|
-
|
|
104
|
-
output = bootstrap_form_for(@user) do |f|
|
|
105
|
-
f.fields_for :address do |af|
|
|
106
|
-
af.text_field(:street)
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test "bootstrap_form_for helper works for serialized hash attributes" do
|
|
115
|
-
@user.preferences = { favorite_color: "cerulean" }
|
|
116
|
-
|
|
117
|
-
output = bootstrap_form_for(@user) do |f|
|
|
118
|
-
f.fields_for :preferences do |builder|
|
|
119
|
-
builder.text_field :favorite_color, value: @user.preferences[:favorite_color]
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test "fields_for correctly passes horizontal style from parent builder" do
|
|
128
|
-
@user.address = Address.new(street: '123 Main Street')
|
|
129
|
-
|
|
130
|
-
output = bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-sm-2', control_col: 'col-sm-10') do |f|
|
|
131
|
-
f.fields_for :address do |af|
|
|
132
|
-
af.text_field(:street)
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
test "fields_for correctly passes inline style from parent builder" do
|
|
141
|
-
@user.address = Address.new(street: '123 Main Street')
|
|
142
|
-
|
|
143
|
-
output = bootstrap_form_for(@user, layout: :inline) do |f|
|
|
144
|
-
f.fields_for :address do |af|
|
|
145
|
-
af.text_field(:street)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
151
|
-
end
|
|
152
|
-
end
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class BootstrapFormGroupTest < ActionView::TestCase
|
|
4
|
-
include BootstrapForm::Helper
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
setup_test_fixture
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
test "changing the label text via the label option parameter" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, label: 'Email Address')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "changing the label text via the html_options label hash" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, label: {text: 'Email Address'})
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test "hiding a label" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, hide_label: true)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
test "adding a custom label class via the label_class parameter" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, label_class: 'btn')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "adding a custom label class via the html_options label hash" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn'})
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test "adding a custom label and changing the label text via the html_options label hash" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"})
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "skipping a label" do
|
|
41
|
-
expected = %{<div class="form-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
|
|
42
|
-
assert_equivalent_xml expected, @builder.text_field(:email, skip_label: true)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
test "preventing a label from having the required class" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, skip_required: true)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
test "adding prepend text" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, prepend: '@')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test "adding append text" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, append: '.00')
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "append and prepend button" do
|
|
61
|
-
prefix = %{<div class="form-group"><label class="control-label required" for="user_email">Email</label><div class="input-group">}
|
|
62
|
-
field = %{<input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" />}
|
|
63
|
-
button = %{<span class="input-group-btn"><a class="btn btn-default" href="#">Click</a></span>}
|
|
64
|
-
suffix = %{</div></div>}
|
|
65
|
-
after_button = prefix + field + button + suffix
|
|
66
|
-
before_button = prefix + button + field + suffix
|
|
67
|
-
both_button = prefix + button + field + button + suffix
|
|
68
|
-
button_src = link_to("Click", "#", class: "btn btn-default")
|
|
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
|
-
end
|
|
73
|
-
|
|
74
|
-
test "adding both prepend and append text" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00')
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
test "help messages for default forms" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required')
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test "help messages for horizontal forms" do
|
|
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
|
-
assert_equivalent_xml expected, @horizontal_builder.text_field(:email, help: "This is required")
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
test "help messages to look up I18n automatically" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:password)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test "help messages to warn about deprecated I18n key" do
|
|
95
|
-
super_user = SuperUser.new(@user.attributes)
|
|
96
|
-
builder = BootstrapForm::FormBuilder.new(:super_user, super_user, self, {})
|
|
97
|
-
|
|
98
|
-
I18n.backend.store_translations(:en, activerecord: {
|
|
99
|
-
help: {
|
|
100
|
-
superuser: {
|
|
101
|
-
password: 'A good password should be at least six characters long'
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
builder.stubs(:warn).returns(true)
|
|
107
|
-
builder.expects(:warn).at_least_once
|
|
108
|
-
|
|
109
|
-
builder.password_field(:password)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
test "help messages to ignore translation when user disables help" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:password, help: false)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
test "form_group creates a valid structure and allows arbitrary html to be added via a block" do
|
|
118
|
-
output = @horizontal_builder.form_group :nil, label: { text: 'Foo' } do
|
|
119
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
120
|
-
end
|
|
121
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
test "form_group adds a spacer when no label exists for a horizontal form" do
|
|
127
|
-
output = @horizontal_builder.form_group do
|
|
128
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
129
|
-
end
|
|
130
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
test "form_group renders the label correctly" do
|
|
136
|
-
output = @horizontal_builder.form_group :email, label: { text: 'Custom Control' } do
|
|
137
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
138
|
-
end
|
|
139
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
test "form_group accepts class thorugh options hash" do
|
|
145
|
-
output = @horizontal_builder.form_group :email, class: "foo" do
|
|
146
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
147
|
-
end
|
|
148
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
test "form_group accepts class thorugh options hash without needing a name" do
|
|
154
|
-
output = @horizontal_builder.form_group class: "foo" do
|
|
155
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
156
|
-
end
|
|
157
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do
|
|
163
|
-
output = @horizontal_builder.form_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
|
|
164
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
165
|
-
end
|
|
166
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
test 'form_group renders the "error" class and message corrrectly when object is invalid' do
|
|
172
|
-
@user.email = nil
|
|
173
|
-
@user.valid?
|
|
174
|
-
|
|
175
|
-
output = @builder.form_group :email do
|
|
176
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
177
|
-
end
|
|
178
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
test "adds class to wrapped form_group by a field" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.search_field(:misc, wrapper_class: 'none-margin')
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
test "adds class to wrapped form_group by a field with errors" do
|
|
189
|
-
@user.email = nil
|
|
190
|
-
@user.valid?
|
|
191
|
-
|
|
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
|
-
assert_equivalent_xml expected, @builder.email_field(:email, wrapper_class: 'none-margin')
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
test "adds class to wrapped form_group by a field with errors when bootstrap_form_for is used" do
|
|
197
|
-
@user.email = nil
|
|
198
|
-
@user.valid?
|
|
199
|
-
|
|
200
|
-
output = bootstrap_form_for(@user) do |f|
|
|
201
|
-
f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin')
|
|
202
|
-
end
|
|
203
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
test "adds offset for form_group without label" do
|
|
209
|
-
output = @horizontal_builder.form_group do
|
|
210
|
-
@horizontal_builder.submit
|
|
211
|
-
end
|
|
212
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
test "adds offset for form_group without label but specific label_col" do
|
|
218
|
-
output = @horizontal_builder.form_group label_col: 'col-sm-5', control_col: 'col-sm-8' do
|
|
219
|
-
@horizontal_builder.submit
|
|
220
|
-
end
|
|
221
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
test "adding an icon to a field" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.email_field(:misc, icon: 'ok')
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
test "single form_group call in horizontal form should not be smash design" do
|
|
232
|
-
output = ''
|
|
233
|
-
output = @horizontal_builder.form_group do
|
|
234
|
-
"Hallo"
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
output = output + @horizontal_builder.text_field(:email)
|
|
238
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
test "adds data-attributes (or any other options) to wrapper" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } })
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
test "passing options to a form control get passed through" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.text_field(:email, autofocus: true)
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
test "doesn't throw undefined method error when the content block returns nil" do
|
|
254
|
-
output = @builder.form_group :nil, label: { text: 'Foo' } do
|
|
255
|
-
nil
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
expected = %{<div class="form-group"><label class="control-label" for="user_nil">Foo</label></div>}
|
|
259
|
-
assert_equivalent_xml expected, output
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
test "custom form group layout option" do
|
|
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
|
-
assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline }
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
test "non-default column span on form is reflected in form_group" do
|
|
268
|
-
non_default_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3", control_col: "col-sm-9" })
|
|
269
|
-
output = non_default_horizontal_builder.form_group do
|
|
270
|
-
%{<p class="form-control-static">Bar</p>}.html_safe
|
|
271
|
-
end
|
|
272
|
-
|
|
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
|
-
assert_equivalent_xml expected, output
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
test "non-default column span on form isn't mutated" do
|
|
278
|
-
frozen_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3".freeze, control_col: "col-sm-9".freeze })
|
|
279
|
-
output = frozen_horizontal_builder.form_group { 'test' }
|
|
280
|
-
|
|
281
|
-
expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3">test</div></div>}
|
|
282
|
-
assert_equivalent_xml expected, output
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
test ":input_group_class should apply to input-group" do
|
|
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
|
-
assert_equivalent_xml expected, @builder.email_field(:email, append: @builder.primary('Subscribe'), input_group_class: 'input-group-lg')
|
|
288
|
-
end
|
|
289
|
-
end
|