comfy_bootstrap_form 4.0.0.beta1 → 4.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +12 -0
  3. data/.travis.yml +14 -0
  4. data/CONTRIBUTING.md +40 -0
  5. data/Gemfile +14 -0
  6. data/{MIT-LICENSE → LICENSE.md} +1 -1
  7. data/README.md +130 -495
  8. data/Rakefile +5 -15
  9. data/bootstrap_form.gemspec +25 -0
  10. data/demo/README.md +18 -0
  11. data/demo/Rakefile +6 -0
  12. data/demo/app/controllers/application_controller.rb +2 -0
  13. data/demo/app/controllers/bootstrap_controller.rb +12 -0
  14. data/demo/app/models/application_record.rb +3 -0
  15. data/demo/app/models/user.rb +3 -0
  16. data/demo/app/views/bootstrap/form.html.erb +82 -0
  17. data/demo/app/views/layouts/application.html.erb +43 -0
  18. data/demo/bin/bundle +3 -0
  19. data/{test/dummy → demo}/bin/rails +1 -1
  20. data/{test/dummy → demo}/bin/rake +0 -0
  21. data/demo/bin/setup +36 -0
  22. data/demo/bin/update +31 -0
  23. data/demo/bin/yarn +11 -0
  24. data/{test/dummy → demo}/config.ru +2 -1
  25. data/demo/config/application.rb +24 -0
  26. data/demo/config/boot.rb +5 -0
  27. data/{test/dummy → demo}/config/database.yml +8 -12
  28. data/demo/config/environment.rb +5 -0
  29. data/demo/config/environments/development.rb +60 -0
  30. data/{test/dummy → demo}/config/environments/test.rb +15 -20
  31. data/demo/config/initializers/application_controller_renderer.rb +8 -0
  32. data/demo/config/initializers/assets.rb +14 -0
  33. data/{test/dummy → demo}/config/initializers/backtrace_silencers.rb +0 -0
  34. data/demo/config/initializers/cookies_serializer.rb +5 -0
  35. data/{test/dummy → demo}/config/initializers/filter_parameter_logging.rb +0 -0
  36. data/{test/dummy → demo}/config/initializers/inflections.rb +0 -0
  37. data/{test/dummy → demo}/config/initializers/mime_types.rb +0 -1
  38. data/{test/dummy → demo}/config/initializers/wrap_parameters.rb +2 -2
  39. data/{test/dummy → demo}/config/locales/en.yml +10 -0
  40. data/demo/config/puma.rb +56 -0
  41. data/{test/dummy → demo}/config/routes.rb +2 -0
  42. data/demo/config/spring.rb +6 -0
  43. data/demo/config/storage.yml +35 -0
  44. data/demo/db/schema.rb +11 -0
  45. data/{test/dummy/public/favicon.ico → demo/log/.keep} +0 -0
  46. data/demo/package.json +5 -0
  47. data/demo/public/favicon.ico +0 -0
  48. data/lib/bootstrap_form.rb +2 -2
  49. data/lib/bootstrap_form/form_builder.rb +367 -346
  50. data/lib/bootstrap_form/version.rb +1 -1
  51. data/lib/bootstrap_form/view_helper.rb +33 -0
  52. data/lib/comfy_bootstrap_form.rb +1 -1
  53. data/test/bootstrap_form/fields_test.rb +304 -0
  54. data/test/bootstrap_form/fields_with_errors_test.rb +109 -0
  55. data/test/bootstrap_form/form_builder_test.rb +49 -0
  56. data/test/bootstrap_form/horizontal_form_test.rb +159 -0
  57. data/test/bootstrap_form/inline_form_test.rb +68 -0
  58. data/test/bootstrap_form/input_group_test.rb +53 -0
  59. data/test/bootstrap_form/radios_and_checkboxes_test.rb +208 -0
  60. data/test/bootstrap_form/submit_test.rb +59 -0
  61. data/test/bootstrap_form/view_helpers_test.rb +99 -0
  62. data/test/gemfiles/5.2.gemfile +13 -0
  63. data/test/test_helper.rb +31 -69
  64. metadata +71 -258
  65. data/app/assets/stylesheets/rails_bootstrap_forms.css +0 -10
  66. data/lib/bootstrap_form/aliasing.rb +0 -35
  67. data/lib/bootstrap_form/helper.rb +0 -36
  68. data/lib/bootstrap_form/helpers/bootstrap.rb +0 -94
  69. data/lib/bootstrap_form/helpers/nested_form.rb +0 -33
  70. data/test/bootstrap_checkbox_test.rb +0 -144
  71. data/test/bootstrap_fields_test.rb +0 -152
  72. data/test/bootstrap_form_group_test.rb +0 -313
  73. data/test/bootstrap_form_test.rb +0 -276
  74. data/test/bootstrap_other_components_test.rb +0 -86
  75. data/test/bootstrap_radio_button_test.rb +0 -124
  76. data/test/bootstrap_selects_test.rb +0 -160
  77. data/test/dummy/Gemfile +0 -45
  78. data/test/dummy/Gemfile.lock +0 -120
  79. data/test/dummy/README.rdoc +0 -28
  80. data/test/dummy/Rakefile +0 -10
  81. data/test/dummy/app/assets/javascripts/application.js +0 -16
  82. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  83. data/test/dummy/app/controllers/application_controller.rb +0 -5
  84. data/test/dummy/app/helpers/application_helper.rb +0 -2
  85. data/test/dummy/app/models/address.rb +0 -3
  86. data/test/dummy/app/models/faux_user.rb +0 -9
  87. data/test/dummy/app/models/super_user.rb +0 -2
  88. data/test/dummy/app/models/user.rb +0 -9
  89. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  90. data/test/dummy/bin/bundle +0 -3
  91. data/test/dummy/config/application.rb +0 -23
  92. data/test/dummy/config/boot.rb +0 -4
  93. data/test/dummy/config/environment.rb +0 -5
  94. data/test/dummy/config/environments/development.rb +0 -29
  95. data/test/dummy/config/environments/production.rb +0 -80
  96. data/test/dummy/config/initializers/generic_migration.rb +0 -6
  97. data/test/dummy/config/initializers/secret_token.rb +0 -12
  98. data/test/dummy/config/initializers/session_store.rb +0 -3
  99. data/test/dummy/db/migrate/20130703191909_create_users.rb +0 -13
  100. data/test/dummy/db/migrate/20130703191937_create_addresses.rb +0 -13
  101. data/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb +0 -5
  102. data/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb +0 -5
  103. data/test/dummy/db/migrate/20140922133133_add_type_to_users.rb +0 -5
  104. data/test/dummy/db/schema.rb +0 -38
  105. data/test/dummy/db/seeds.rb +0 -7
  106. data/test/dummy/db/test.sqlite3 +0 -0
  107. data/test/dummy/log/test.log +0 -18394
  108. data/test/dummy/public/404.html +0 -58
  109. data/test/dummy/public/422.html +0 -58
  110. data/test/dummy/public/500.html +0 -57
  111. data/test/dummy/public/robots.txt +0 -5
  112. data/test/dummy/test/fixtures/addresses.yml +0 -15
  113. data/test/dummy/test/fixtures/users.yml +0 -15
  114. data/test/dummy/test/models/address_test.rb +0 -7
  115. data/test/dummy/test/models/user_test.rb +0 -7
  116. data/test/dummy/test/test_helper.rb +0 -15
  117. data/test/special_form_class_models_test.rb +0 -43
@@ -0,0 +1,49 @@
1
+ require_relative "../test_helper"
2
+
3
+ class FormBuilderTest < ActionView::TestCase
4
+
5
+ def test_initialization
6
+ builder = BootstrapForm::FormBuilder.new(nil, nil, self, {})
7
+
8
+ assert_equal "default", builder.bootstrap.layout
9
+ assert_equal "col-sm-2", builder.bootstrap.label_col_class
10
+ assert_equal "col-sm-10", builder.bootstrap.control_col_class
11
+ assert_equal "text-sm-right", builder.bootstrap.label_align_class
12
+ assert_equal "mr-sm-2", builder.bootstrap.inline_margin_class
13
+
14
+ refute builder.bootstrap.horizontal?
15
+
16
+ assert_equal "offset-sm-2", builder.bootstrap.offset_col_class
17
+ end
18
+
19
+ def test_initialization_with_options
20
+ builder = BootstrapForm::FormBuilder.new(nil, nil, self, {
21
+ skip_default_ids: true,
22
+ bootstrap: {
23
+ layout: "horizontal",
24
+ label_col_class: "col-md-2",
25
+ control_col_class: "col-md-10",
26
+ label_align_class: "text-md-right",
27
+ inline_margin_class: "mr-sm-2 mb-sm-2"
28
+ }
29
+ })
30
+
31
+ assert_equal "horizontal", builder.bootstrap.layout
32
+ assert_equal "col-md-2", builder.bootstrap.label_col_class
33
+ assert_equal "col-md-10", builder.bootstrap.control_col_class
34
+ assert_equal "text-md-right", builder.bootstrap.label_align_class
35
+ assert_equal "mr-sm-2 mb-sm-2", builder.bootstrap.inline_margin_class
36
+
37
+ assert builder.bootstrap.horizontal?
38
+
39
+ assert_equal "offset-md-2", builder.bootstrap.offset_col_class
40
+ end
41
+
42
+ def test_initialization_for_inline
43
+ builder = BootstrapForm::FormBuilder.new(nil, nil, self, {
44
+ bootstrap: {layout: :inline}
45
+ })
46
+ assert builder.bootstrap.inline?
47
+ end
48
+
49
+ end
@@ -0,0 +1,159 @@
1
+ require_relative "../test_helper"
2
+
3
+ class HorizontalFormTest < ActionView::TestCase
4
+
5
+ setup do
6
+ @user = User.new
7
+ @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {bootstrap: {layout: :horizontal}})
8
+ end
9
+
10
+ def test_text_field
11
+ actual = @builder.text_field(:email)
12
+ expected = <<-HTML
13
+ <div class="form-group row">
14
+ <label class="col-form-label col-sm-2 text-sm-right" for="user_email">Email</label>
15
+ <div class="col-sm-10">
16
+ <input class="form-control" type="text" name="user[email]" id="user_email" />
17
+ </div>
18
+ </div>
19
+ HTML
20
+ assert_xml_equal expected, actual
21
+ end
22
+
23
+ def test_text_field_with_no_label
24
+ actual = @builder.text_field(:email, bootstrap: {label: {hide: true}})
25
+ expected = <<-HTML
26
+ <div class="form-group row">
27
+ <label class="sr-only col-form-label col-sm-2 text-sm-right" for="user_email">Email</label>
28
+ <div class="col-sm-10 offset-sm-2">
29
+ <input class="form-control" type="text" name="user[email]" id="user_email" />
30
+ </div>
31
+ </div>
32
+ HTML
33
+ assert_xml_equal expected, actual
34
+ end
35
+
36
+ def test_check_box
37
+ actual = @builder.check_box(:terms)
38
+ expected = <<-HTML
39
+ <fieldset class="form-group row">
40
+ <div class="col-sm-10 offset-sm-2">
41
+ <div class="form-check">
42
+ <input name="user[terms]" type="hidden" value="0"/>
43
+ <input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1"/>
44
+ <label class="form-check-label" for="user_terms">Terms</label>
45
+ </div>
46
+ </div>
47
+ </fieldset>
48
+ HTML
49
+ assert_xml_equal expected, actual
50
+ end
51
+
52
+ def test_collection_radio_buttons
53
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize)
54
+ expected = <<-HTML
55
+ <fieldset class="form-group">
56
+ <div class="row">
57
+ <legend class="col-form-label pt-0 col-sm-2 text-sm-right">Test</legend>
58
+ <div class="col-sm-10">
59
+ <div class="form-check">
60
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
61
+ <label class="form-check-label" for="user_test_a">A</label>
62
+ </div>
63
+ <div class="form-check">
64
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
65
+ <label class="form-check-label" for="user_test_b">B</label>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </fieldset>
70
+ HTML
71
+ assert_xml_equal expected, actual
72
+ end
73
+
74
+ def test_collection_check_boxes_with_no_label
75
+ actual = @builder.collection_check_boxes(:test, ["a", "b"], :to_s, :titleize, bootstrap: {label: {hide: true}})
76
+ expected = <<-HTML
77
+ <input id="user_test" multiple="multiple" name="user[test][]" type="hidden" value=""/>
78
+ <fieldset class="form-group">
79
+ <div class="row">
80
+ <div class="col-sm-10 offset-sm-2">
81
+ <div class="form-check">
82
+ <input class="form-check-input" id="user_test_a" name="user[test][]" type="checkbox" value="a"/>
83
+ <label class="form-check-label" for="user_test_a">A</label>
84
+ </div>
85
+ <div class="form-check">
86
+ <input class="form-check-input" id="user_test_b" name="user[test][]" type="checkbox" value="b"/>
87
+ <label class="form-check-label" for="user_test_b">B</label>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </fieldset>
92
+ HTML
93
+ assert_xml_equal expected, actual
94
+ end
95
+
96
+ def test_submit
97
+ actual = @builder.submit
98
+ expected = <<-HTML
99
+ <div class="form-group row">
100
+ <div class="col-sm-10 offset-sm-2">
101
+ <input class="btn" data-disable-with="Create User" name="commit" type="submit" value="Create User"/>
102
+ </div>
103
+ </div>
104
+ HTML
105
+ assert_xml_equal expected, actual
106
+ end
107
+
108
+ def test_input_group_with_options
109
+ actual = @builder.text_field(:test, bootstrap: {
110
+ prepend: "prepend",
111
+ append: "append",
112
+ help: "help me"
113
+ })
114
+ expected = <<-HTML
115
+ <div class="form-group row">
116
+ <label class="col-form-label col-sm-2 text-sm-right" for="user_test">Test</label>
117
+ <div class="col-sm-10">
118
+ <div class="input-group">
119
+ <div class="input-group-prepend">
120
+ <span class="input-group-text">prepend</span>
121
+ </div>
122
+ <input class="form-control" id="user_test" name="user[test]" type="text"/>
123
+ <div class="input-group-append">
124
+ <span class="input-group-text">append</span>
125
+ </div>
126
+ <small class="form-text text-muted">help me</small>
127
+ </div>
128
+ </div>
129
+ </div>
130
+ HTML
131
+ assert_xml_equal expected, actual
132
+ end
133
+
134
+ def test_form_group
135
+ actual = @builder.form_group do
136
+ "test"
137
+ end
138
+ expected = <<-HTML
139
+ <div class="form-group row">
140
+ <div class="col-sm-10 offset-sm-2">test</div>
141
+ </div>
142
+ HTML
143
+ assert_xml_equal expected, actual
144
+ end
145
+
146
+ def test_form_group_with_label
147
+ actual = @builder.form_group(bootstrap: {label: {text: "Test"}}) do
148
+ "test"
149
+ end
150
+ expected = <<-HTML
151
+ <div class="form-group row">
152
+ <label class="col-form-label col-sm-2 text-sm-right">Test</label>
153
+ <div class="col-sm-10">test</div>
154
+ </div>
155
+ HTML
156
+ assert_xml_equal expected, actual
157
+ end
158
+
159
+ end
@@ -0,0 +1,68 @@
1
+ require_relative "../test_helper"
2
+
3
+ class InlineFormTest < ActionView::TestCase
4
+
5
+ setup do
6
+ @user = User.new
7
+ @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {bootstrap: {layout: :inline}})
8
+ end
9
+
10
+ def test_text_field
11
+ actual = @builder.text_field(:email)
12
+ expected = <<-HTML
13
+ <div class="form-group mr-sm-2">
14
+ <label class="mr-sm-2" for="user_email">Email</label>
15
+ <input class="form-control" id="user_email" name="user[email]" type="text"/>
16
+ </div>
17
+ HTML
18
+ assert_xml_equal expected, actual
19
+ end
20
+
21
+ def test_check_box
22
+ actual = @builder.check_box(:terms)
23
+ expected = <<-HTML
24
+ <fieldset class="form-group mr-sm-2">
25
+ <div class="form-check">
26
+ <input name="user[terms]" type="hidden" value="0"/>
27
+ <input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1"/>
28
+ <label class="form-check-label" for="user_terms">Terms</label>
29
+ </div>
30
+ </fieldset>
31
+ HTML
32
+ assert_xml_equal expected, actual
33
+ end
34
+
35
+ def test_submit
36
+ actual = @builder.submit
37
+ expected = <<-HTML
38
+ <div class="form-group">
39
+ <input class="btn" data-disable-with="Create User" name="commit" type="submit" value="Create User"/>
40
+ </div>
41
+ HTML
42
+ assert_xml_equal expected, actual
43
+ end
44
+
45
+ def test_form_group
46
+ actual = @builder.form_group do
47
+ "test"
48
+ end
49
+ expected = <<-HTML
50
+ <div class="form-group mr-sm-2">test</div>
51
+ HTML
52
+ assert_xml_equal expected, actual
53
+ end
54
+
55
+ def test_form_group_with_label
56
+ actual = @builder.form_group(bootstrap: {label: {text: "Test"}}) do
57
+ "test"
58
+ end
59
+ expected = <<-HTML
60
+ <div class="form-group mr-sm-2">
61
+ <label class="mr-sm-2">Test</label>
62
+ test
63
+ </div>
64
+ HTML
65
+ assert_xml_equal expected, actual
66
+ end
67
+
68
+ end
@@ -0,0 +1,53 @@
1
+ require_relative "../test_helper"
2
+
3
+ class InputGroupTest < ActionView::TestCase
4
+
5
+ setup do
6
+ @user = User.new
7
+ @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
8
+ end
9
+
10
+ def test_input_group
11
+ actual = @builder.text_field(:test, bootstrap: {
12
+ prepend: "prepend", append: "append"
13
+ })
14
+ expected = <<-HTML
15
+ <div class="form-group">
16
+ <label for="user_test">Test</label>
17
+ <div class="input-group">
18
+ <div class="input-group-prepend">
19
+ <span class="input-group-text">prepend</span>
20
+ </div>
21
+ <input class="form-control" id="user_test" name="user[test]" type="text"/>
22
+ <div class="input-group-append">
23
+ <span class="input-group-text">append</span>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ HTML
28
+ assert_xml_equal expected, actual
29
+ end
30
+
31
+ def test_input_group_with_html
32
+ actual = @builder.text_field(:test, bootstrap: {
33
+ prepend: {html: "<button>Go</button>".html_safe},
34
+ append: {html: "<button>Stop</button>".html_safe}
35
+ })
36
+ expected = <<-HTML
37
+ <div class="form-group">
38
+ <label for="user_test">Test</label>
39
+ <div class="input-group">
40
+ <div class="input-group-prepend">
41
+ <button>Go</button>
42
+ </div>
43
+ <input class="form-control" id="user_test" name="user[test]" type="text"/>
44
+ <div class="input-group-append">
45
+ <button>Stop</button>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ HTML
50
+ assert_xml_equal expected, actual
51
+ end
52
+
53
+ end
@@ -0,0 +1,208 @@
1
+ require_relative "../test_helper"
2
+
3
+ class RadiosAndCheckboxessTest < ActionView::TestCase
4
+
5
+ setup do
6
+ @user = User.new
7
+ @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
8
+ end
9
+
10
+ def test_checkbox
11
+ actual = @builder.check_box(:test)
12
+ expected = <<-HTML
13
+ <fieldset class="form-group">
14
+ <div class="form-check">
15
+ <input name="user[test]" type="hidden" value="0"/>
16
+ <input class="form-check-input" id="user_test" name="user[test]" type="checkbox" value="1"/>
17
+ <label class="form-check-label" for="user_test">Test</label>
18
+ </div>
19
+ </fieldset>
20
+ HTML
21
+ assert_xml_equal expected, actual
22
+ end
23
+
24
+ def test_checkbox_with_label
25
+ actual = @builder.check_box(:test, bootstrap: {label: {text: "Custom"}})
26
+ expected = <<-HTML
27
+ <fieldset class="form-group">
28
+ <div class="form-check">
29
+ <input name="user[test]" type="hidden" value="0"/>
30
+ <input class="form-check-input" id="user_test" name="user[test]" type="checkbox" value="1"/>
31
+ <label class="form-check-label" for="user_test">Custom</label>
32
+ </div>
33
+ </fieldset>
34
+ HTML
35
+ assert_xml_equal expected, actual
36
+ end
37
+
38
+ def test_checkbox_with_help
39
+ actual = @builder.check_box(:test, bootstrap: {help: "help me"})
40
+ expected = <<-HTML
41
+ <fieldset class="form-group">
42
+ <div class="form-check">
43
+ <input name="user[test]" type="hidden" value="0"/>
44
+ <input class="form-check-input" id="user_test" name="user[test]" type="checkbox" value="1"/>
45
+ <label class="form-check-label" for="user_test">Test</label>
46
+ <small class="form-text text-muted">help me</small>
47
+ </div>
48
+ </fieldset>
49
+ HTML
50
+ assert_xml_equal expected, actual
51
+ end
52
+
53
+ def test_collection_check_boxes
54
+ actual = @builder.collection_check_boxes(:test, ["a", "b"], :to_s, :titleize)
55
+ expected = <<-HTML
56
+ <input id="user_test" multiple="multiple" name="user[test][]" type="hidden" value=""/>
57
+ <fieldset class="form-group">
58
+ <legend class="col-form-label pt-0">Test</legend>
59
+ <div class="form-check">
60
+ <input class="form-check-input" id="user_test_a" name="user[test][]" type="checkbox" value="a"/>
61
+ <label class="form-check-label" for="user_test_a">A</label>
62
+ </div>
63
+ <div class="form-check">
64
+ <input class="form-check-input" id="user_test_b" name="user[test][]" type="checkbox" value="b"/>
65
+ <label class="form-check-label" for="user_test_b">B</label>
66
+ </div>
67
+ </fieldset>
68
+ HTML
69
+ assert_xml_equal expected, actual
70
+ end
71
+
72
+ def test_collection_checkboxes_without_hidden_field
73
+ actual = @builder.collection_check_boxes(:test, ["a", "b"], :to_s, :titleize, include_hidden: false)
74
+ expected = <<-HTML
75
+ <fieldset class="form-group">
76
+ <legend class="col-form-label pt-0">Test</legend>
77
+ <div class="form-check">
78
+ <input class="form-check-input" id="user_test_a" name="user[test][]" type="checkbox" value="a"/>
79
+ <label class="form-check-label" for="user_test_a">A</label>
80
+ </div>
81
+ <div class="form-check">
82
+ <input class="form-check-input" id="user_test_b" name="user[test][]" type="checkbox" value="b"/>
83
+ <label class="form-check-label" for="user_test_b">B</label>
84
+ </div>
85
+ </fieldset>
86
+ HTML
87
+ assert_xml_equal expected, actual
88
+ end
89
+
90
+ def test_radio_buttons
91
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize)
92
+ expected = <<-HTML
93
+ <fieldset class="form-group">
94
+ <legend class="col-form-label pt-0">Test</legend>
95
+ <div class="form-check">
96
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
97
+ <label class="form-check-label" for="user_test_a">A</label>
98
+ </div>
99
+ <div class="form-check">
100
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
101
+ <label class="form-check-label" for="user_test_b">B</label>
102
+ </div>
103
+ </fieldset>
104
+ HTML
105
+ assert_xml_equal expected, actual
106
+ end
107
+
108
+ def test_radio_buttons_inline
109
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
110
+ inline: true
111
+ })
112
+ expected = <<-HTML
113
+ <fieldset class="form-group">
114
+ <legend class="col-form-label pt-0">Test</legend>
115
+ <div class="form-check form-check-inline">
116
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
117
+ <label class="form-check-label" for="user_test_a">A</label>
118
+ </div>
119
+ <div class="form-check form-check-inline">
120
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
121
+ <label class="form-check-label" for="user_test_b">B</label>
122
+ </div>
123
+ </fieldset>
124
+ HTML
125
+ assert_xml_equal expected, actual
126
+ end
127
+
128
+ def test_radio_buttons_custom_label
129
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
130
+ label: {text: "Custom"}
131
+ })
132
+ expected = <<-HTML
133
+ <fieldset class="form-group">
134
+ <legend class="col-form-label pt-0">Custom</legend>
135
+ <div class="form-check">
136
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
137
+ <label class="form-check-label" for="user_test_a">A</label>
138
+ </div>
139
+ <div class="form-check">
140
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
141
+ <label class="form-check-label" for="user_test_b">B</label>
142
+ </div>
143
+ </fieldset>
144
+ HTML
145
+ assert_xml_equal expected, actual
146
+ end
147
+
148
+ def test_radio_buttons_no_label
149
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
150
+ label: {hide: true}
151
+ })
152
+ expected = <<-HTML
153
+ <fieldset class="form-group">
154
+ <div class="form-check">
155
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
156
+ <label class="form-check-label" for="user_test_a">A</label>
157
+ </div>
158
+ <div class="form-check">
159
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
160
+ <label class="form-check-label" for="user_test_b">B</label>
161
+ </div>
162
+ </fieldset>
163
+ HTML
164
+ assert_xml_equal expected, actual
165
+ end
166
+
167
+ def test_radio_buttons_with_help
168
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
169
+ help: "help me"
170
+ })
171
+ expected = <<-HTML
172
+ <fieldset class="form-group">
173
+ <legend class="col-form-label pt-0">Test</legend>
174
+ <div class="form-check">
175
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
176
+ <label class="form-check-label" for="user_test_a">A</label>
177
+ </div>
178
+ <div class="form-check">
179
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
180
+ <label class="form-check-label" for="user_test_b">B</label>
181
+ <small class="form-text text-muted">help me</small>
182
+ </div>
183
+ </fieldset>
184
+ HTML
185
+ assert_xml_equal expected, actual
186
+ end
187
+
188
+ def test_radio_buttons_with_inline_help
189
+ actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
190
+ inline: true, help: "help me"
191
+ })
192
+ expected = <<-HTML
193
+ <fieldset class="form-group">
194
+ <legend class="col-form-label pt-0">Test</legend>
195
+ <div class="form-check form-check-inline">
196
+ <input class="form-check-input" id="user_test_a" name="user[test]" type="radio" value="a"/>
197
+ <label class="form-check-label" for="user_test_a">A</label>
198
+ </div>
199
+ <div class="form-check form-check-inline">
200
+ <input class="form-check-input" id="user_test_b" name="user[test]" type="radio" value="b"/>
201
+ <label class="form-check-label" for="user_test_b">B</label>
202
+ </div>
203
+ <small class="form-text text-muted">help me</small>
204
+ </fieldset>
205
+ HTML
206
+ assert_xml_equal expected, actual
207
+ end
208
+ end