bootstrap_form 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,10 +3,17 @@ module BootstrapForm
3
3
  def bootstrap_form_for(object, options = {}, &block)
4
4
  options[:builder] = BootstrapForm::FormBuilder
5
5
 
6
- # add .form-vertical class if it's not horizontal
7
- options[:html] = {} unless options.has_key?(:html)
8
- css = options[:html].fetch(:class, '')
9
- options[:html][:class] = "#{css} form-vertical" unless css.match /form-horizontal/
6
+ style = case options[:style]
7
+ when :inline
8
+ "form-inline"
9
+ when :horizontal
10
+ "form-horizontal"
11
+ end
12
+
13
+ if style
14
+ options[:html] ||= {}
15
+ options[:html][:class] = "#{options[:html][:class]} #{style}".lstrip
16
+ end
10
17
 
11
18
  temporarily_disable_field_error_proc do
12
19
  form_for(object, options, &block)
@@ -1,3 +1,3 @@
1
1
  module BootstrapForm
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -5,23 +5,34 @@ class BootstrapFormTest < ActionView::TestCase
5
5
 
6
6
  def setup
7
7
  @user = User.new(email: 'steve@example.com', password: 'secret', comments: 'my comment')
8
- @builder = BootstrapForm::FormBuilder.new :user, @user, self, {}, nil
8
+ @builder = BootstrapForm::FormBuilder.new(:user, @user, self, {}, nil)
9
+ @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { style: :horizontal, left: "col-sm-2", right: "col-sm-10" }, nil)
9
10
  end
10
11
 
11
- test "helper method to wrap bootstrap a vertical form builder" do
12
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div></form>}
12
+ test "default-style forms" do
13
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
13
14
  assert_equal expected, bootstrap_form_for(@user) { |f| nil }
14
15
  end
15
16
 
16
- test "helper method to wrap bootstrap a horizontal form builder" do
17
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\"form-horizontal\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div></form>}
18
- assert_equal expected, bootstrap_form_for(@user, html: { class: 'form-horizontal' }) { |f| nil }
17
+ test "inline-style forms" do
18
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-inline" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div></form>}
19
+ assert_equal expected, bootstrap_form_for(@user, style: :inline) { |f| nil }
20
+ end
21
+
22
+ test "horizontal-style forms" do
23
+ expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="col-sm-2 control-label" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
24
+ assert_equal expected, bootstrap_form_for(@user, style: :horizontal) { |f| f.email_field :email }
25
+ end
26
+
27
+ test "existing styles aren't clobbered when specifying a form style" do
28
+ expected = %{<form accept-charset="UTF-8" action="/users" class="my-style form-horizontal" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="col-sm-2 control-label" for="user_email">Email</label><div class="col-sm-10"><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></div></form>}
29
+ assert_equal expected, bootstrap_form_for(@user, style: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email }
19
30
  end
20
31
 
21
32
  test "alert message is wrapped correctly" do
22
33
  @user.email = nil
23
34
  @user.valid?
24
- expected = %{<div class="alert alert-error">Please fix the following errors:</div>}
35
+ expected = %{<div class="alert alert-danger">Please fix the following errors:</div>}
25
36
  assert_equal expected, @builder.alert_message('Please fix the following errors:')
26
37
  end
27
38
 
@@ -33,242 +44,198 @@ class BootstrapFormTest < ActionView::TestCase
33
44
  end
34
45
 
35
46
  test "text fields are wrapped correctly" do
36
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
47
+ expected = %{<div class="form-group"><label for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
37
48
  assert_equal expected, @builder.text_field(:email)
38
49
  end
39
50
 
40
51
  test "password fields are wrapped correctly" do
41
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_password\">Password</label><div class=\"controls\"><input id=\"user_password\" name=\"user[password]\" type=\"text\" value=\"secret\" /></div></div>}
52
+ expected = %{<div class="form-group"><label for="user_password">Password</label><input class="form-control" id="user_password" name="user[password]" type="text" value="secret" /></div>}
42
53
  assert_equal expected, @builder.text_field(:password)
43
54
  end
44
55
 
45
56
  test "text areas are wrapped correctly" do
46
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_comments\">Comments</label><div class=\"controls\"><textarea id=\"user_comments\" name=\"user[comments]\">\nmy comment</textarea></div></div>}
57
+ expected = %{<div class="form-group"><label for="user_comments">Comments</label><textarea class="form-control" id="user_comments" name="user[comments]">\nmy comment</textarea></div>}
47
58
  assert_equal expected, @builder.text_area(:comments)
48
59
  end
49
60
 
50
61
  test "file fields are wrapped correctly" do
51
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"file\" /></div></div>}
62
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="file" /></div>}
52
63
  assert_equal expected, @builder.file_field(:misc)
53
64
  end
54
65
 
55
66
  test "number fields are wrapped correctly" do
56
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"number\" /></div></div>}
67
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="number" /></div>}
57
68
  assert_equal expected, @builder.number_field(:misc)
58
69
  end
59
70
 
60
71
  test "email fields are wrapped correctly" do
61
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"email\" /></div></div>}
72
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="email" /></div>}
62
73
  assert_equal expected, @builder.email_field(:misc)
63
74
  end
64
75
 
65
76
  test "telephone/phone fields are wrapped correctly" do
66
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"tel\" /></div></div>}
77
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="tel" /></div>}
67
78
  assert_equal expected, @builder.telephone_field(:misc)
68
79
  assert_equal expected, @builder.phone_field(:misc)
69
80
  end
70
81
 
71
82
  test "url fields are wrapped correctly" do
72
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc\" name=\"user[misc]\" type=\"url\" /></div></div>}
83
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input class="form-control" id="user_misc" name="user[misc]" type="url" /></div>}
73
84
  assert_equal expected, @builder.url_field(:misc)
74
85
  end
75
86
 
76
87
  test "selects are wrapped correctly (select)" do
77
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_status\">Status</label><div class=\"controls\"><select id=\"user_status\" name=\"user[status]\"><option value=\"1\">activated</option>\n<option value=\"2\">blocked</option></select></div></div>}
88
+ expected = %{<div class="form-group"><label for="user_status">Status</label><select id="user_status" name="user[status]"><option value="1">activated</option>\n<option value="2">blocked</option></select></div>}
78
89
  assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]])
79
90
  end
80
91
 
81
92
  test "selects are wrapped correctly (collection_select)" do
82
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_status\">Status</label><div class=\"controls\"><select id=\"user_status\" name=\"user[status]\"></select></div></div>}
93
+ expected = %{<div class="form-group"><label for="user_status">Status</label><select id="user_status" name="user[status]"></select></div>}
83
94
  assert_equal expected, @builder.collection_select(:status, [], :id, :name)
84
95
  end
85
96
 
86
97
  test "date selects are wrapped correctly" do
87
98
  Timecop.freeze(Time.utc(2012, 2, 3)) do
88
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><select id=\"user_misc_1i\" name=\"user[misc(1i)]\">\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n<option value=\"2009\">2009</option>\n<option value=\"2010\">2010</option>\n<option value=\"2011\">2011</option>\n<option selected=\"selected\" value=\"2012\">2012</option>\n<option value=\"2013\">2013</option>\n<option value=\"2014\">2014</option>\n<option value=\"2015\">2015</option>\n<option value=\"2016\">2016</option>\n<option value=\"2017\">2017</option>\n</select>\n<select id=\"user_misc_2i\" name=\"user[misc(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"user_misc_3i\" name=\"user[misc(3i)]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n</div></div>}
99
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><select id="user_misc_1i" name="user[misc(1i)]">\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option selected="selected" value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select id="user_misc_2i" name="user[misc(2i)]">\n<option value="1">January</option>\n<option selected="selected" value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="user_misc_3i" name="user[misc(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option selected="selected" value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</div>}
89
100
  assert_equal expected, @builder.date_select(:misc)
90
101
  end
91
102
  end
92
103
 
93
104
  test "time selects are wrapped correctly" do
94
105
  Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
95
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc_1i\" name=\"user[misc(1i)]\" type=\"hidden\" value=\"2012\" />\n<input id=\"user_misc_2i\" name=\"user[misc(2i)]\" type=\"hidden\" value=\"2\" />\n<input id=\"user_misc_3i\" name=\"user[misc(3i)]\" type=\"hidden\" value=\"3\" />\n<select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option selected=\"selected\" value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
106
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><input id="user_misc_1i" name="user[misc(1i)]" type="hidden" value="2012" />\n<input id="user_misc_2i" name="user[misc(2i)]" type="hidden" value="2" />\n<input id="user_misc_3i" name="user[misc(3i)]" type="hidden" value="3" />\n<select id="user_misc_4i" name="user[misc(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option selected="selected" value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="user_misc_5i" name="user[misc(5i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div>}
96
107
  assert_equal expected, @builder.time_select(:misc)
97
108
  end
98
109
  end
99
110
 
100
111
  test "datetime selects are wrapped correctly" do
101
112
  Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
102
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><select id=\"user_misc_1i\" name=\"user[misc(1i)]\">\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n<option value=\"2009\">2009</option>\n<option value=\"2010\">2010</option>\n<option value=\"2011\">2011</option>\n<option selected=\"selected\" value=\"2012\">2012</option>\n<option value=\"2013\">2013</option>\n<option value=\"2014\">2014</option>\n<option value=\"2015\">2015</option>\n<option value=\"2016\">2016</option>\n<option value=\"2017\">2017</option>\n</select>\n<select id=\"user_misc_2i\" name=\"user[misc(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"user_misc_3i\" name=\"user[misc(3i)]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n &mdash; <select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option selected=\"selected\" value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
113
+ expected = %{<div class="form-group"><label for="user_misc">Misc</label><select id="user_misc_1i" name="user[misc(1i)]">\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n<option value="2010">2010</option>\n<option value="2011">2011</option>\n<option selected="selected" value="2012">2012</option>\n<option value="2013">2013</option>\n<option value="2014">2014</option>\n<option value="2015">2015</option>\n<option value="2016">2016</option>\n<option value="2017">2017</option>\n</select>\n<select id="user_misc_2i" name="user[misc(2i)]">\n<option value="1">January</option>\n<option selected="selected" value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="user_misc_3i" name="user[misc(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option selected="selected" value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select id="user_misc_4i" name="user[misc(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option selected="selected" value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="user_misc_5i" name="user[misc(5i)]">\n<option selected="selected" value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</div>}
103
114
  assert_equal expected, @builder.datetime_select(:misc)
104
115
  end
105
116
  end
106
117
 
107
118
  test "check_box is wrapped correctly" do
108
- expected = %{<label class=\"checkbox\" for=\"user_misc\"><input name=\"user[misc]\" type=\"hidden\" value=\"0\" /><input id=\"user_misc\" name=\"user[misc]\" type=\"checkbox\" value=\"1\" /> This is a checkbox</label>}
119
+ expected = %{<div class="checkbox"><label for="user_misc"><input name="user[misc]" type="hidden" value="0" /><input id="user_misc" name="user[misc]" type="checkbox" value="1" /> This is a checkbox</label></div>}
109
120
  assert_equal expected, @builder.check_box(:misc, label: 'This is a checkbox')
110
121
  end
111
122
 
112
123
  test "check_box responds to checked_value and unchecked_value arguments" do
113
- expected = %{<label class=\"checkbox\" for=\"user_misc\"><input name=\"user[misc]\" type=\"hidden\" value=\"no\" /><input id=\"user_misc\" name=\"user[misc]\" type=\"checkbox\" value=\"yes\" /> This is a checkbox</label>}
124
+ expected = %{<div class="checkbox"><label for="user_misc"><input name="user[misc]" type="hidden" value="no" /><input id="user_misc" name="user[misc]" type="checkbox" value="yes" /> This is a checkbox</label></div>}
114
125
  assert_equal expected, @builder.check_box(:misc, {label: 'This is a checkbox'}, 'yes', 'no')
115
126
  end
116
127
 
117
- test "check_box inline label is setted correctly" do
118
- expected = %{<label class=\"checkbox inline\" for=\"user_misc\"><input name=\"user[misc]\" type=\"hidden\" value=\"0\" /><input id=\"user_misc\" name=\"user[misc]\" type=\"checkbox\" value=\"1\" /> This is a checkbox</label>}
128
+ test "inline checkboxes" do
129
+ expected = %{<label class="checkbox-inline" for="user_misc"><input name="user[misc]" type="hidden" value="0" /><input id="user_misc" name="user[misc]" type="checkbox" value="1" /> This is a checkbox</label>}
119
130
  assert_equal expected, @builder.check_box(:misc, label: 'This is a checkbox', inline: true)
120
131
  end
121
132
 
122
133
  test "radio_button is wrapped correctly" do
123
- expected = %{<label class=\"radio\" for=\"user_misc_1\"><input id=\"user_misc_1\" name=\"user[misc]\" type=\"radio\" value=\"1\" /> This is a radio button</label>}
134
+ expected = %{<label class="radio" for="user_misc_1"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
124
135
  assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button')
125
136
  end
126
137
 
127
138
  test "radio_button inline label is setted correctly" do
128
- expected = %{<label class=\"radio inline\" for=\"user_misc_1\"><input id=\"user_misc_1\" name=\"user[misc]\" type=\"radio\" value=\"1\" /> This is a radio button</label>}
139
+ expected = %{<label class="radio-inline" for="user_misc_1"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
129
140
  assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true)
130
141
  end
131
142
 
132
143
  test "changing the label text" do
133
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email Address</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
144
+ expected = %{<div class="form-group"><label for="user_email">Email Address</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
134
145
  assert_equal expected, @builder.text_field(:email, label: 'Email Address')
135
146
  end
136
147
 
137
- test "render the field without label" do
138
- expected = %{<div class=\"control-group\"><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
139
- assert_equal expected, @builder.text_field(:email, label: :none)
148
+ test "hiding a label" do
149
+ expected = %{<div class="form-group"><label class="sr-only" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
150
+ assert_equal expected, @builder.text_field(:email, hide_label: true)
140
151
  end
141
152
 
142
153
  test "adding prepend text" do
143
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">Gmail</span><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div></div>}
144
- assert_equal expected, @builder.text_field(:email, prepend: 'Gmail')
154
+ expected = %{<div class="form-group"><label for="user_email">Email</label><div class="input-group"><span class="input-group-addon">@</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
155
+ assert_equal expected, @builder.text_field(:email, prepend: '@')
145
156
  end
146
157
 
147
158
  test "adding append text" do
148
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-append\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class="add-on">Gmail</span></div></div></div>}
149
- assert_equal expected, @builder.text_field(:email, append: 'Gmail')
159
+ expected = %{<div class="form-group"><label for="user_email">Email</label><div class="input-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
160
+ assert_equal expected, @builder.text_field(:email, append: '.00')
150
161
  end
151
162
 
152
- test "passing :help to a field displays it inline" do
153
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-inline\">This is required</span></div></div>}
154
- assert_equal expected, @builder.text_field(:email, help: 'This is required')
163
+ test "adding both prepend and append text" do
164
+ expected = %{<div class="form-group"><label for="user_email">Email</label><div class="input-group"><span class="input-group-addon">$</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="input-group-addon">.00</span></div></div>}
165
+ assert_equal expected, @builder.text_field(:email, prepend: '$', append: '.00')
155
166
  end
156
167
 
157
- test "passing other options to a field get passed through" do
158
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input autofocus=\"autofocus\" id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /></div></div>}
159
- assert_equal expected, @builder.text_field(:email, autofocus: true)
160
- end
161
-
162
- test "control_group creates a valid structure and allows arbitrary html to be added via a block" do
163
- output = @builder.control_group do
164
- content_tag(:span, 'custom control here')
165
- end
166
-
167
- expected = %{<div class="control-group"><div class="controls"><span>custom control here</span></div></div>}
168
- assert_equal expected, output
168
+ test "help messages for default forms" do
169
+ expected = %{<div class="form-group"><label for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /><span class="help-block">This is required</span></div>}
170
+ assert_equal expected, @builder.text_field(:email, help: 'This is required')
169
171
  end
170
172
 
171
- test "control_group renders the options for div.control_group" do
172
- output = @builder.control_group nil, id: 'foo' do
173
- content_tag(:span, 'custom control here')
174
- end
175
-
176
- expected = %{<div class="control-group" id="foo"><div class="controls"><span>custom control here</span></div></div>}
177
- assert_equal expected, output
173
+ test "help messages for horizontal forms" do
174
+ expected = %{<div class="form-group"><label class="col-sm-2 control-label" 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>}
175
+ assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required")
178
176
  end
179
177
 
180
- test "control_group overrides the control-group class if another is passed" do
181
- output = @builder.control_group nil, class: 'foo' do
182
- content_tag(:span, 'custom control here')
183
- end
184
-
185
- expected = %{<div class="foo"><div class="controls"><span>custom control here</span></div></div>}
186
- assert_equal expected, output
178
+ test "passing options to a form control get passed through" do
179
+ expected = %{<div class="form-group"><label for="user_email">Email</label><input autofocus="autofocus" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
180
+ assert_equal expected, @builder.text_field(:email, autofocus: true)
187
181
  end
188
182
 
189
- test "control_group renders the label correctly" do
190
- output = @builder.control_group :email, label: { text: 'Custom Control' } do
191
- content_tag(:span, 'custom control here')
183
+ test "form_group creates a valid structure and allows arbitrary html to be added via a block" do
184
+ output = @horizontal_builder.form_group :nil, label: { text: 'Foo' } do
185
+ %{<p class="form-control-static">Bar</p>}.html_safe
192
186
  end
193
187
 
194
- expected = %{<div class="control-group"><label class="control-label" for="user_email">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
188
+ expected = %{<div class="form-group"><label class="col-sm-2 control-label" for="user_nil">Foo</label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
195
189
  assert_equal expected, output
196
190
  end
197
191
 
198
- test "control_group overrides the label's 'class' and 'for' attributes if others are passed" do
199
- output = @builder.control_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
200
- content_tag(:span, 'custom control here')
192
+ test "form_group adds a spacer when no label exists for a horizontal form" do
193
+ output = @horizontal_builder.form_group do
194
+ %{<p class="form-control-static">Bar</p>}.html_safe
201
195
  end
202
196
 
203
- expected = %{<div class="control-group"><label class="foo" for="bar">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
197
+ expected = %{<div class="form-group"><label class="col-sm-2 control-label"></label><div class="col-sm-10"><p class="form-control-static">Bar</p></div></div>}
204
198
  assert_equal expected, output
205
199
  end
206
200
 
207
- test "control_group label's 'for' attribute should be empty if no name was passed" do
208
- output = @builder.control_group nil, label: { text: 'Custom Control' } do
209
- content_tag(:span, 'custom control here')
201
+ test "form_group renders the label correctly" do
202
+ output = @horizontal_builder.form_group :email, label: { text: 'Custom Control' } do
203
+ %{<p class="form-control-static">Bar</p>}.html_safe
210
204
  end
211
205
 
212
- expected = %{<div class="control-group"><label class="control-label" for="">Custom Control</label><div class="controls"><span>custom control here</span></div></div>}
206
+ expected = %{<div class="form-group"><label class="col-sm-2 control-label" for="user_email">Custom Control</label><div class="col-sm-10"><p class=\"form-control-static\">Bar</p></div></div>}
213
207
  assert_equal expected, output
214
208
  end
215
209
 
216
- test 'control_group renders the :help corrrectly' do
217
- output = @builder.control_group nil, help: 'Foobar' do
218
- content_tag(:span, 'custom control here')
210
+ test "form_group overrides the label's 'class' and 'for' attributes if others are passed" do
211
+ output = @horizontal_builder.form_group nil, label: { text: 'Custom Control', class: 'foo', for: 'bar' } do
212
+ %{<p class="form-control-static">Bar</p>}.html_safe
219
213
  end
220
214
 
221
- expected = %{<div class="control-group"><div class="controls"><span>custom control here</span><span class="help-inline">Foobar</span></div></div>}
215
+ expected = %{<div class="form-group"><label class="foo col-sm-2 control-label" for="bar">Custom Control</label><div class="col-sm-10"><p class=\"form-control-static\">Bar</p></div></div>}
222
216
  assert_equal expected, output
223
217
  end
224
218
 
225
- test 'control_group renders the "error" class and message corrrectly when object is invalid' do
219
+ test 'form_group renders the "error" class and message corrrectly when object is invalid' do
226
220
  @user.email = nil
227
221
  @user.valid?
228
222
 
229
- output = @builder.control_group :email do
230
- content_tag(:span, 'custom control here')
223
+ output = @builder.form_group :email do
224
+ %{<p class="form-control-static">Bar</p>}.html_safe
231
225
  end
232
226
 
233
- expected = %{<div class="control-group error"><div class="controls"><span>custom control here</span><span class="help-inline">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div>}
227
+ expected = %{<div class="form-group has-error"><p class="form-control-static">Bar</p><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div>}
234
228
  assert_equal expected, output
235
229
  end
236
230
 
237
- test "actions are wrapped correctly" do
238
- output = @builder.actions do
239
- 'something'
240
- end
241
- expected = %{<div class="form-actions">something</div>}
242
- assert_equal expected, output
231
+ test "submit button uses default button classes" do
232
+ expected = %{<input class="btn btn-default" name="commit" type="submit" value="Submit Form" />}
233
+ assert_equal expected, @builder.submit("Submit Form")
243
234
  end
244
235
 
245
- test "primary button contains the correct classes" do
246
- expected = %{<input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Submit\" />}
247
- assert_equal expected, @builder.primary('Submit')
248
- end
249
-
250
- test "primary button with a disabled state" do
251
- expected = %{<input class=\"btn btn-primary\" data-disable-with="Saving..." name=\"commit\" type=\"submit\" value=\"Submit\" />}
252
- assert_equal expected, @builder.primary('Submit', data: { disable_with: 'Saving...' })
253
- end
254
-
255
- test "secondary button contains the correct classes" do
256
- expected = %{<input class=\"btn\" name=\"commit\" type=\"submit\" value=\"Submit\" />}
257
- assert_equal expected, @builder.secondary('Submit')
258
- end
259
-
260
- test "secondary button with a disabled state" do
261
- expected = %{<input class=\"btn\" data-disable-with="Saving..." name=\"commit\" type=\"submit\" value=\"Submit\" />}
262
- assert_equal expected, @builder.secondary('Submit', data: { disable_with: 'Saving...' })
263
- end
264
-
265
- test "passing :help :block to the form builder" do
266
- output = bootstrap_form_for(@user, help: :block) do |f|
267
- f.text_field(:email, help: 'This is required')
268
- end
269
-
270
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-block\">This is required</span></div></div></form>}
271
- assert_equal expected, output
236
+ test "override submit button classes" do
237
+ expected = %{<input class="btn btn-primary" name="commit" type="submit" value="Submit Form" />}
238
+ assert_equal expected, @builder.submit("Submit Form", class: "btn btn-primary")
272
239
  end
273
240
 
274
241
  test "the field contains the error and is not wrapped in div.field_with_errors when bootstrap_form_for is used" do
@@ -279,7 +246,7 @@ class BootstrapFormTest < ActionView::TestCase
279
246
  f.text_field(:email, help: 'This is required')
280
247
  end
281
248
 
282
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" /><span class=\"help-block\">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div></form>}
249
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><label for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="text" /><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
283
250
  assert_equal expected, output
284
251
  end
285
252
 
@@ -291,11 +258,11 @@ class BootstrapFormTest < ActionView::TestCase
291
258
  f.text_field(:email, help: 'This is required')
292
259
  end
293
260
 
294
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\"new_user\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group error\"><div class=\"field_with_errors\"><label class=\"control-label\" for=\"user_email\">Email</label></div><div class=\"controls\"><div class=\"field_with_errors\"><input id=\"user_email\" name=\"user[email]\" type=\"text\" /></div><span class=\"help-block\">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></div></form>}
261
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group has-error"><div class="field_with_errors"><label for="user_email">Email</label></div><div class="field_with_errors"><input class="form-control" id="user_email" name="user[email]" type="text" /></div><span class="help-block">can&#39;t be blank, is too short (minimum is 5 characters)</span></div></form>}
295
262
  assert_equal expected, output
296
263
  end
297
264
 
298
- test "form_for helper works for associations" do
265
+ test "bootstrap_form_for helper works for associations" do
299
266
  @user.address = Address.new(street: '123 Main Street')
300
267
 
301
268
  output = bootstrap_form_for(@user) do |f|
@@ -304,14 +271,26 @@ class BootstrapFormTest < ActionView::TestCase
304
271
  end
305
272
  end
306
273
 
307
- expected = %{<form accept-charset=\"UTF-8\" action=\"/users\" class=\" form-vertical\" id=\"new_user\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /></div><div class=\"control-group\"><label class=\"control-label\" for=\"user_address_attributes_street\">Street</label><div class=\"controls\"><input id=\"user_address_attributes_street\" name=\"user[address_attributes][street]\" type=\"text\" value=\"123 Main Street\" /></div></div></form>}
274
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label 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>}
275
+ assert_equal expected, output
276
+ end
277
+
278
+ test "bootstrap_form_for helper works for serialized hash attributes" do
279
+ @user.preferences = { favorite_color: "cerulean" }
280
+
281
+ output = bootstrap_form_for(@user) do |f|
282
+ f.fields_for :preferences do |builder|
283
+ builder.text_field :favorite_color, value: @user.preferences[:favorite_color]
284
+ end
285
+ end
286
+
287
+ expected = %{<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label 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>}
308
288
  assert_equal expected, output
309
289
  end
310
290
 
311
291
  test "allows the form object to be nil" do
312
292
  builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {}, nil
313
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"other_model_email\">Email</label><div class=\"controls\"><input id=\"other_model_email\" name=\"other_model[email]\" type=\"text\" /></div></div>}
293
+ expected = %{<div class="form-group"><label for="other_model_email">Email</label><input class="form-control" id="other_model_email" name="other_model[email]" type="text" /></div>}
314
294
  assert_equal expected, builder.text_field(:email)
315
295
  end
316
296
  end
317
-
@@ -1,4 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
+ serialize :preferences
3
+
2
4
  validates :email, presence: true, :length => { minimum: 5 }
3
5
 
4
6
  has_one :address
@@ -0,0 +1,5 @@
1
+ class AddPreferencesToUser < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :preferences, :text
4
+ end
5
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20130703191937) do
14
+ ActiveRecord::Schema.define(version: 20130912171202) do
15
15
 
16
16
  create_table "addresses", force: true do |t|
17
17
  t.integer "user_id"
@@ -31,6 +31,7 @@ ActiveRecord::Schema.define(version: 20130703191937) do
31
31
  t.string "misc"
32
32
  t.datetime "created_at"
33
33
  t.datetime "updated_at"
34
+ t.text "preferences"
34
35
  end
35
36
 
36
37
  end