forme 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +10 -0
- data/README.rdoc +3 -3
- data/lib/forme/bs3.rb +7 -7
- data/lib/forme/form.rb +2 -0
- data/lib/forme/transformers/error_handler.rb +10 -10
- data/lib/forme/transformers/formatter.rb +32 -34
- data/lib/forme/version.rb +1 -1
- data/lib/sequel/plugins/forme.rb +8 -6
- data/lib/sequel/plugins/forme_set.rb +2 -4
- data/spec/bs3_reference_spec.rb +288 -311
- data/spec/bs3_sequel_plugin_spec.rb +152 -152
- data/spec/bs3_spec.rb +234 -205
- data/spec/forme_coverage.rb +1 -0
- data/spec/forme_spec.rb +429 -353
- data/spec/rails_integration_spec.rb +13 -1
- data/spec/roda_integration_spec.rb +20 -2
- data/spec/sequel_helper.rb +3 -1
- data/spec/sequel_i18n_plugin_spec.rb +4 -4
- data/spec/sequel_plugin_spec.rb +252 -149
- data/spec/sequel_set_plugin_spec.rb +6 -0
- data/spec/shared_erb_specs.rb +1 -1
- data/spec/sinatra_integration_spec.rb +26 -0
- metadata +2 -2
@@ -11,210 +11,210 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should add appropriate attributes by default" do
|
14
|
-
@b.form.
|
14
|
+
@b.form.must_equal '<form class="forme album" method="post"></form>'
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should allow overriding of attributes" do
|
18
|
-
@b.form(:class=>:foo, :method=>:get).
|
18
|
+
@b.form(:class=>:foo, :method=>:get).must_equal '<form class="foo forme album" method="get"></form>'
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should handle invalid methods" do
|
22
22
|
def @ab.db_schema
|
23
23
|
super.merge(:foo=>{:type=>:bar})
|
24
24
|
end
|
25
|
-
@b.input(:foo, :value=>'baz').
|
25
|
+
@b.input(:foo, :value=>'baz').must_equal '<div class="bar form-group"><label for="album_foo">Foo</label> <input class="form-control" id="album_foo" name="album[foo]" type="text" value="baz"/></div>'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should allow an array of classes" do
|
29
|
-
@b.form(:class=>[:foo, :bar]).
|
30
|
-
@b.form(:class=>[:foo, [:bar, :baz]]).
|
29
|
+
@b.form(:class=>[:foo, :bar]).must_equal '<form class="foo bar forme album" method="post"></form>'
|
30
|
+
@b.form(:class=>[:foo, [:bar, :baz]]).must_equal '<form class="foo bar baz forme album" method="post"></form>'
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should use a text field for strings" do
|
34
|
-
@b.input(:name).
|
35
|
-
@c.input(:name).
|
34
|
+
@b.input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></div>'
|
35
|
+
@c.input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="c"/></div>'
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should allow :as=>:textarea to use a textarea" do
|
39
|
-
@b.input(:name, :as=>:textarea).
|
40
|
-
@c.input(:name, :as=>:textarea).
|
39
|
+
@b.input(:name, :as=>:textarea).must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">b</textarea></div>'
|
40
|
+
@c.input(:name, :as=>:textarea).must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea></div>'
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should allow :type=>:textarea to use a textarea" do
|
44
|
-
@b.input(:name, :type=>:textarea).
|
45
|
-
@c.input(:name, :type=>:textarea).
|
44
|
+
@b.input(:name, :type=>:textarea).must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">b</textarea></div>'
|
45
|
+
@c.input(:name, :type=>:textarea).must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea></div>'
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should use number inputs for integers" do
|
49
|
-
@b.input(:copies_sold).
|
49
|
+
@b.input(:copies_sold).must_equal '<div class="form-group integer"><label for="album_copies_sold">Copies sold</label> <input class="form-control" id="album_copies_sold" inputmode="numeric" name="album[copies_sold]" pattern="-?[0-9]*" type="text" value="10"/></div>'
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should use date inputs for Dates" do
|
53
|
-
@b.input(:release_date).
|
53
|
+
@b.input(:release_date).must_equal '<div class="date form-group"><label for="album_release_date">Release date</label> <input class="form-control" id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></div>'
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should use datetime inputs for Time" do
|
57
|
-
@b.input(:created_at).
|
57
|
+
@b.input(:created_at).must_match %r{<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album\[created_at\]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>}
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should use datetime inputs for DateTimes" do
|
61
61
|
@ab.values[:created_at] = DateTime.new(2011, 6, 5)
|
62
|
-
@b.input(:created_at).
|
62
|
+
@b.input(:created_at).must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>'
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should include type as wrapper class" do
|
66
66
|
@ab.values[:created_at] = DateTime.new(2011, 6, 5)
|
67
67
|
f = Forme::Form.new(@ab, :config=>:bs3)
|
68
|
-
f.input(:name).
|
69
|
-
f.input(:release_date).
|
70
|
-
f.input(:created_at).
|
68
|
+
f.input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></div>'
|
69
|
+
f.input(:release_date).must_equal '<div class="date form-group"><label for="album_release_date">Release date</label> <input class="form-control" id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></div>'
|
70
|
+
f.input(:created_at).must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>'
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should include required * in label if required" do
|
74
|
-
@b.input(:name, :required=>true).
|
74
|
+
@b.input(:name, :required=>true).must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should add required to label even if :label option specified" do
|
78
|
-
@b.input(:name, :required=>true, :label=>'Foo').
|
78
|
+
@b.input(:name, :required=>true, :label=>'Foo').must_equal '<div class="form-group required string"><label for="album_name">Foo<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should include required wrapper class if required" do
|
82
82
|
f = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
83
|
-
f.input(:name, :required=>true).
|
83
|
+
f.input(:name, :required=>true).must_equal '<li class="string required"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></li>'
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should use a select box for tri-valued boolean fields" do
|
87
|
-
@b.input(:gold).
|
88
|
-
@c.input(:gold).
|
87
|
+
@b.input(:gold).must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option value="t">True</option><option selected="selected" value="f">False</option></select></div>'
|
88
|
+
@c.input(:gold).must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option selected="selected" value="t">True</option><option value="f">False</option></select></div>'
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should respect :true_label and :false_label options for tri-valued boolean fields" do
|
92
|
-
@b.input(:gold, :true_label=>"Foo", :false_label=>"Bar").
|
92
|
+
@b.input(:gold, :true_label=>"Foo", :false_label=>"Bar").must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option value="t">Foo</option><option selected="selected" value="f">Bar</option></select></div>'
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should respect :true_value and :false_value options for tri-valued boolean fields" do
|
96
|
-
@b.input(:gold, :true_value=>"Foo", :false_value=>"Bar").
|
96
|
+
@b.input(:gold, :true_value=>"Foo", :false_value=>"Bar").must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value=""></option><option value="Foo">True</option><option value="Bar">False</option></select></div>'
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should respect :add_blank option for tri-valued boolean fields" do
|
100
|
-
@b.input(:gold, :add_blank=>'NULL').
|
100
|
+
@b.input(:gold, :add_blank=>'NULL').must_equal '<div class="boolean form-group"><label for="album_gold">Gold</label> <select class="form-control" id="album_gold" name="album[gold]"><option value="">NULL</option><option value="t">True</option><option selected="selected" value="f">False</option></select></div>'
|
101
101
|
end
|
102
102
|
|
103
103
|
it "should use a select box for dual-valued boolean fields where :required => false" do
|
104
|
-
@b.input(:platinum, :required=>false).
|
105
|
-
@c.input(:platinum, :required=>false).
|
104
|
+
@b.input(:platinum, :required=>false).must_equal '<div class="boolean form-group"><label for="album_platinum">Platinum</label> <select class="form-control" id="album_platinum" name="album[platinum]"><option value=""></option><option value="t">True</option><option selected="selected" value="f">False</option></select></div>'
|
105
|
+
@c.input(:platinum, :required=>false).must_equal '<div class="boolean form-group"><label for="album_platinum">Platinum</label> <select class="form-control" id="album_platinum" name="album[platinum]"><option value=""></option><option selected="selected" value="t">True</option><option value="f">False</option></select></div>'
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should use a checkbox for dual-valued boolean fields" do
|
109
|
-
@b.input(:platinum).
|
110
|
-
@c.input(:platinum).
|
109
|
+
@b.input(:platinum).must_equal '<div class="boolean checkbox"><label for="album_platinum"><input id="album_platinum_hidden" name="album[platinum]" type="hidden" value="f"/><input id="album_platinum" name="album[platinum]" type="checkbox" value="t"/> Platinum</label></div>'
|
110
|
+
@c.input(:platinum).must_equal '<div class="boolean checkbox"><label for="album_platinum"><input id="album_platinum_hidden" name="album[platinum]" type="hidden" value="f"/><input checked="checked" id="album_platinum" name="album[platinum]" type="checkbox" value="t"/> Platinum</label></div>'
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should use radio buttons for boolean fields if :as=>:radio is used" do
|
114
|
-
@b.input(:platinum, :as=>:radio).
|
115
|
-
@c.input(:platinum, :as=>:radio).
|
114
|
+
@b.input(:platinum, :as=>:radio).must_equal '<div class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
115
|
+
@c.input(:platinum, :as=>:radio).must_equal '<div class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input checked="checked" id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should wrap both inputs if :as=>:radio is used" do
|
119
119
|
@b = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
120
|
-
@b.input(:platinum, :as=>:radio).
|
121
|
-
@b.input(:platinum, :as=>:radio,:wrapper=>:li).
|
122
|
-
@b.input(:platinum, :as=>:radio, :wrapper=>:div, :tag_wrapper=>:span).
|
120
|
+
@b.input(:platinum, :as=>:radio).must_equal '<div class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
121
|
+
@b.input(:platinum, :as=>:radio,:wrapper=>:li).must_equal '<li class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></li>'
|
122
|
+
@b.input(:platinum, :as=>:radio, :wrapper=>:div, :tag_wrapper=>:span).must_equal '<div class="boolean radioset"><label>Platinum</label><span><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></span><span><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></span></div>'
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should handle errors on radio buttons for boolean fields if :as=>:radio is used" do
|
126
126
|
@ab.errors.add(:platinum, 'foo')
|
127
|
-
@b.input(:platinum, :as=>:radio).
|
128
|
-
@b.input(:platinum, :as=>:radio, :wrapper=>:li).
|
129
|
-
@b.input(:platinum, :as=>:radio, :wrapper=>:bs3).
|
127
|
+
@b.input(:platinum, :as=>:radio).must_equal '<div class="boolean radioset has-error"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">foo</span></div>'
|
128
|
+
@b.input(:platinum, :as=>:radio, :wrapper=>:li).must_equal '<li class="boolean radioset has-error"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">foo</span></li>'
|
129
|
+
@b.input(:platinum, :as=>:radio, :wrapper=>:bs3).must_equal '<div class="boolean form-group has-error radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">foo</span></div>'
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should handle Raw :label options if :as=>:radio is used" do
|
133
|
-
@b.input(:platinum, :as=>:radio, :label=>Forme.raw('Foo:<br />')).
|
134
|
-
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />').
|
135
|
-
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>nil).
|
136
|
-
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>:li).
|
137
|
-
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>:bs3).
|
133
|
+
@b.input(:platinum, :as=>:radio, :label=>Forme.raw('Foo:<br />')).must_equal '<div class="boolean radioset"><label>Foo:<br /></label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
134
|
+
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />').must_equal '<div class="boolean radioset"><label>Foo:<br /></label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
135
|
+
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>nil).must_equal '<label>Foo:<br /></label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div>'
|
136
|
+
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>:li).must_equal '<li class="boolean radioset"><label>Foo:<br /></label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></li>'
|
137
|
+
@b.input(:platinum, :as=>:radio, :label=>'Foo:<br />', :wrapper=>:bs3).must_equal '<div class="boolean form-group radioset"><label>Foo:<br /></label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label></div></div>'
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should respect :true_label and :false_label options for boolean fields if :as=>:radio is used" do
|
141
|
-
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar").
|
142
|
-
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>nil).
|
143
|
-
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>:li).
|
144
|
-
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>:bs3).
|
141
|
+
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar").must_equal '<div class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Foo</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> Bar</label></div></div>'
|
142
|
+
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>nil).must_equal '<label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Foo</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> Bar</label></div>'
|
143
|
+
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>:li).must_equal '<li class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Foo</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> Bar</label></div></li>'
|
144
|
+
@b.input(:platinum, :as=>:radio, :true_label=>"Foo", :false_label=>"Bar",:wrapper=>:bs3).must_equal '<div class="boolean form-group radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Foo</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> Bar</label></div></div>'
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should respect :true_value and :false_value options for boolean fields if :as=>:radio is used" do
|
148
|
-
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar").
|
149
|
-
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>nil).
|
150
|
-
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>:li).
|
151
|
-
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>:bs3).
|
148
|
+
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar").must_equal '<div class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="Foo"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="Bar"/> No</label></div></div>'
|
149
|
+
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>nil).must_equal '<label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="Foo"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="Bar"/> No</label></div>'
|
150
|
+
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>:li).must_equal '<li class="boolean radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="Foo"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="Bar"/> No</label></div></li>'
|
151
|
+
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar", :wrapper=>:bs3).must_equal '<div class="boolean form-group radioset"><label>Platinum</label><div class="radio"><label class="option" for="album_platinum_yes"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="Foo"/> Yes</label></div><div class="radio"><label class="option" for="album_platinum_no"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="Bar"/> No</label></div></div>'
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should use a select box for many_to_one associations" do
|
155
|
-
@b.input(:artist).
|
156
|
-
@c.input(:artist).
|
155
|
+
@b.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></div>'
|
156
|
+
@c.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a</option><option selected="selected" value="2">d</option></select></div>'
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should not add a blank option by default if there is a default value and it is required" do
|
160
|
-
@b.input(:artist, :required=>true).
|
160
|
+
@b.input(:artist, :required=>true).must_equal '<div class="form-group many_to_one required"><label for="album_artist_id">Artist<abbr title="required">*</abbr></label> <select class="form-control" id="album_artist_id" name="album[artist_id]" required="required"><option selected="selected" value="1">a</option><option value="2">d</option></select></div>'
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should allow overriding default input type using a :type option" do
|
164
|
-
@b.input(:artist, :type=>:string, :value=>nil).
|
164
|
+
@b.input(:artist, :type=>:string, :value=>nil).must_equal '<div class="form-group"><label for="album_artist">Artist</label> <input class="form-control" id="album_artist" name="album[artist]" type="text"/></div>'
|
165
165
|
end
|
166
166
|
|
167
167
|
it "should use a required wrapper tag for many_to_one required associations" do
|
168
|
-
@b.input(:artist, :required=>true, :wrapper=>:li).
|
168
|
+
@b.input(:artist, :required=>true, :wrapper=>:li).must_equal '<li class="many_to_one required"><label for="album_artist_id">Artist<abbr title="required">*</abbr></label> <select class="form-control" id="album_artist_id" name="album[artist_id]" required="required"><option selected="selected" value="1">a</option><option value="2">d</option></select></li>'
|
169
169
|
end
|
170
170
|
|
171
171
|
it "should use a set of radio buttons for many_to_one associations with :as=>:radio option" do
|
172
|
-
@b.input(:artist, :as=>:radio).
|
173
|
-
@b.input(:artist, :as=>:radio, :wrapper=>nil).
|
174
|
-
@c.input(:artist, :as=>:radio).
|
175
|
-
@c.input(:artist, :as=>:radio, :wrapper=>:div).
|
172
|
+
@b.input(:artist, :as=>:radio).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
173
|
+
@b.input(:artist, :as=>:radio, :wrapper=>nil).must_equal '<label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div>'
|
174
|
+
@c.input(:artist, :as=>:radio).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input checked="checked" id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
175
|
+
@c.input(:artist, :as=>:radio, :wrapper=>:div).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input checked="checked" id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should handle Raw label for many_to_one associations with :as=>:radio option" do
|
179
|
-
@b.input(:artist, :as=>:radio, :label=>Forme.raw('Foo:<br />')).
|
180
|
-
@b.input(:artist, :as=>:radio, :label=>'Foo<br />').
|
179
|
+
@b.input(:artist, :as=>:radio, :label=>Forme.raw('Foo:<br />')).must_equal '<div class="many_to_one radioset"><label>Foo:<br /></label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
180
|
+
@b.input(:artist, :as=>:radio, :label=>'Foo<br />').must_equal '<div class="many_to_one radioset"><label>Foo<br /></label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should correctly use the forms wrapper for wrapping radio buttons for many_to_one associations with :as=>:radio option" do
|
184
184
|
@b = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
185
|
-
@b.input(:artist, :as=>:radio).
|
186
|
-
@b.input(:artist, :as=>:radio,:wrapper=>:li).
|
187
|
-
@b.input(:artist, :as=>:radio,:wrapper=>nil).
|
185
|
+
@b.input(:artist, :as=>:radio).must_equal '<div class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></div>'
|
186
|
+
@b.input(:artist, :as=>:radio,:wrapper=>:li).must_equal '<li class="many_to_one radioset"><label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div></li>'
|
187
|
+
@b.input(:artist, :as=>:radio,:wrapper=>nil).must_equal '<label>Artist</label><div class="radio"><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></div><div class="radio"><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></div>'
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should support custom wrappers for many_to_one associations with :as=>:radio via :tag_wrapper option" do
|
191
191
|
@b = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
192
|
-
@b.input(:artist, :as=>:radio, :wrapper=>proc{|t, i| i.tag(:div, {}, [t])}, :tag_wrapper=>proc{|t, i| i.tag(:span, {}, [t])}).
|
192
|
+
@b.input(:artist, :as=>:radio, :wrapper=>proc{|t, i| i.tag(:div, {}, [t])}, :tag_wrapper=>proc{|t, i| i.tag(:span, {}, [t])}).must_equal '<div><label>Artist</label><span><label class="option" for="album_artist_id_1"><input checked="checked" id="album_artist_id_1" name="album[artist_id]" type="radio" value="1"/> a</label></span><span><label class="option" for="album_artist_id_2"><input id="album_artist_id_2" name="album[artist_id]" type="radio" value="2"/> d</label></span></div>'
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should respect an :options entry" do
|
196
|
-
@b.input(:artist, :options=>Artist.order(:name).map{|a| [a.name, a.id+1]}).
|
197
|
-
@c.input(:artist, :options=>Artist.order(:name).map{|a| [a.name, a.id+1]}).
|
196
|
+
@b.input(:artist, :options=>Artist.order(:name).map{|a| [a.name, a.id+1]}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="2">a</option><option value="3">d</option></select></div>'
|
197
|
+
@c.input(:artist, :options=>Artist.order(:name).map{|a| [a.name, a.id+1]}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="2">a</option><option value="3">d</option></select></div>'
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should support :name_method option for choosing name method" do
|
201
|
-
@b.input(:artist, :name_method=>:idname).
|
202
|
-
@c.input(:artist, :name_method=>:idname).
|
201
|
+
@b.input(:artist, :name_method=>:idname).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">1a</option><option value="2">2d</option></select></div>'
|
202
|
+
@c.input(:artist, :name_method=>:idname).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">1a</option><option selected="selected" value="2">2d</option></select></div>'
|
203
203
|
end
|
204
204
|
|
205
205
|
it "should support :name_method option being a callable object" do
|
206
|
-
@b.input(:artist, :name_method=>lambda{|obj| obj.idname * 2}).
|
207
|
-
@c.input(:artist, :name_method=>lambda{|obj| obj.idname * 2}).
|
206
|
+
@b.input(:artist, :name_method=>lambda{|obj| obj.idname * 2}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">1a1a</option><option value="2">2d2d</option></select></div>'
|
207
|
+
@c.input(:artist, :name_method=>lambda{|obj| obj.idname * 2}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">1a1a</option><option selected="selected" value="2">2d2d</option></select></div>'
|
208
208
|
end
|
209
209
|
|
210
210
|
it "should support :dataset option providing dataset to search" do
|
211
|
-
@b.input(:artist, :dataset=>Artist.reverse_order(:name)).
|
212
|
-
@c.input(:artist, :dataset=>Artist.reverse_order(:name)).
|
211
|
+
@b.input(:artist, :dataset=>Artist.reverse_order(:name)).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="2">d</option><option selected="selected" value="1">a</option></select></div>'
|
212
|
+
@c.input(:artist, :dataset=>Artist.reverse_order(:name)).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="2">d</option><option value="1">a</option></select></div>'
|
213
213
|
end
|
214
214
|
|
215
215
|
it "should support :dataset option being a callback proc returning modified dataset to search" do
|
216
|
-
@b.input(:artist, :dataset=>proc{|ds| ds.reverse_order(:name)}).
|
217
|
-
@c.input(:artist, :dataset=>proc{|ds| ds.reverse_order(:name)}).
|
216
|
+
@b.input(:artist, :dataset=>proc{|ds| ds.reverse_order(:name)}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="2">d</option><option selected="selected" value="1">a</option></select></div>'
|
217
|
+
@c.input(:artist, :dataset=>proc{|ds| ds.reverse_order(:name)}).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="2">d</option><option value="1">a</option></select></div>'
|
218
218
|
end
|
219
219
|
|
220
220
|
it "should try a list of methods to get a suitable one for select box naming" do
|
@@ -225,16 +225,16 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
225
225
|
f = Forme::Form.new(al.new, { :config=>:bs3 })
|
226
226
|
|
227
227
|
ar.class_eval{def number() "#{self[:name]}1" end}
|
228
|
-
f.input(:artist).
|
228
|
+
f.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a1</option><option value="2">d1</option></select></div>'
|
229
229
|
|
230
230
|
ar.class_eval{def title() "#{self[:name]}2" end}
|
231
|
-
f.input(:artist).
|
231
|
+
f.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a2</option><option value="2">d2</option></select></div>'
|
232
232
|
|
233
233
|
ar.class_eval{def name() "#{self[:name]}3" end}
|
234
|
-
f.input(:artist).
|
234
|
+
f.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a3</option><option value="2">d3</option></select></div>'
|
235
235
|
|
236
236
|
ar.class_eval{def forme_name() "#{self[:name]}4" end}
|
237
|
-
f.input(:artist).
|
237
|
+
f.input(:artist).must_equal '<div class="form-group many_to_one"><label for="album_artist_id">Artist</label> <select class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a4</option><option value="2">d4</option></select></div>'
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should raise an error when using an association without a usable name method" do
|
@@ -246,89 +246,89 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
246
246
|
end
|
247
247
|
|
248
248
|
it "should use a multiple select box for one_to_many associations" do
|
249
|
-
@b.input(:tracks).
|
250
|
-
@c.input(:tracks).
|
249
|
+
@b.input(:tracks).must_equal '<div class="form-group one_to_many"><label for="album_track_pks">Tracks</label> <select class="form-control" id="album_track_pks" multiple="multiple" name="album[track_pks][]"><option selected="selected" value="1">m</option><option selected="selected" value="2">n</option><option value="3">o</option></select></div>'
|
250
|
+
@c.input(:tracks).must_equal '<div class="form-group one_to_many"><label for="album_track_pks">Tracks</label> <select class="form-control" id="album_track_pks" multiple="multiple" name="album[track_pks][]"><option value="1">m</option><option value="2">n</option><option selected="selected" value="3">o</option></select></div>'
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should use a multiple select box for many_to_many associations" do
|
254
|
-
@b.input(:tags).
|
255
|
-
@c.input(:tags).
|
254
|
+
@b.input(:tags).must_equal '<div class="form-group many_to_many"><label for="album_tag_pks">Tags</label> <select class="form-control" id="album_tag_pks" multiple="multiple" name="album[tag_pks][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></div>'
|
255
|
+
@c.input(:tags).must_equal '<div class="form-group many_to_many"><label for="album_tag_pks">Tags</label> <select class="form-control" id="album_tag_pks" multiple="multiple" name="album[tag_pks][]"><option value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></div>'
|
256
256
|
end
|
257
257
|
|
258
258
|
it "should use a multiple select box for pg_array_to_many associations" do
|
259
|
-
@b.input(:atags).
|
259
|
+
@b.input(:atags).must_equal '<div class="form-group pg_array_to_many"><label for="album_atag_ids">Atags</label> <select class="form-control" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></div>'
|
260
260
|
@c.obj.atag_ids.delete(1)
|
261
|
-
@c.input(:atags).
|
261
|
+
@c.input(:atags).must_equal '<div class="form-group pg_array_to_many"><label for="album_atag_ids">Atags</label> <select class="form-control" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select></div>'
|
262
262
|
end
|
263
263
|
|
264
264
|
it "should handle an error message on the underlying column for pg_array_to_many associations" do
|
265
265
|
@ab.errors.add(:atag_ids, 'tis not valid')
|
266
|
-
@b.input(:atags).
|
267
|
-
@b.input(:atags, :as=>:checkbox).
|
268
|
-
@b.input(:atags, :as=>:checkbox,:wrapper=>:li).
|
266
|
+
@b.input(:atags).must_equal '<div class="form-group has-error pg_array_to_many"><label for="album_atag_ids">Atags</label> <select aria-describedby="album_atag_ids_error_message" aria-invalid="true" class="form-control" id="album_atag_ids" multiple="multiple" name="album[atag_ids][]"><option selected="selected" value="1">s</option><option selected="selected" value="2">t</option><option value="3">u</option></select><span class="help-block with-errors" id="album_atag_ids_error_message">tis not valid</span></div>'
|
267
|
+
@b.input(:atags, :as=>:checkbox).must_equal '<div class="pg_array_to_many checkboxset has-error"><label>Atags</label><div class="checkbox"><label class="option" for="album_atag_ids_1"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_atag_ids_2"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_atag_ids_3"><input id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label></div><span class="help-block with-errors">tis not valid</span></div>'
|
268
|
+
@b.input(:atags, :as=>:checkbox,:wrapper=>:li).must_equal '<li class="pg_array_to_many checkboxset has-error"><label>Atags</label><div class="checkbox"><label class="option" for="album_atag_ids_1"><input checked="checked" id="album_atag_ids_1" name="album[atag_ids][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_atag_ids_2"><input checked="checked" id="album_atag_ids_2" name="album[atag_ids][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_atag_ids_3"><input id="album_atag_ids_3" name="album[atag_ids][]" type="checkbox" value="3"/> u</label></div><span class="help-block with-errors">tis not valid</span></li>'
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should use a regular select box for *_to_many associations if multiple if false" do
|
272
|
-
@b.input(:tracks, :multiple=>false).
|
273
|
-
@c.input(:tags, :multiple=>false).
|
272
|
+
@b.input(:tracks, :multiple=>false).must_equal '<div class="form-group one_to_many"><label for="album_track_pks">Tracks</label> <select class="form-control" id="album_track_pks" name="album[track_pks][]"><option value="1">m</option><option value="2">n</option><option value="3">o</option></select></div>'
|
273
|
+
@c.input(:tags, :multiple=>false).must_equal '<div class="form-group many_to_many"><label for="album_tag_pks">Tags</label> <select class="form-control" id="album_tag_pks" name="album[tag_pks][]"><option value="1">s</option><option value="2">t</option><option value="3">u</option></select></div>'
|
274
274
|
end
|
275
275
|
|
276
276
|
it "should use multiple checkboxes for one_to_many associations if :as=>:checkbox" do
|
277
|
-
@b.input(:tracks).
|
278
|
-
@b.input(:tracks, :as=>:checkbox).
|
279
|
-
@c.input(:tracks, :as=>:checkbox,:wrapper=>:li).
|
277
|
+
@b.input(:tracks).must_equal '<div class="form-group one_to_many"><label for="album_track_pks">Tracks</label> <select class="form-control" id="album_track_pks" multiple="multiple" name="album[track_pks][]"><option selected="selected" value="1">m</option><option selected="selected" value="2">n</option><option value="3">o</option></select></div>'
|
278
|
+
@b.input(:tracks, :as=>:checkbox).must_equal '<div class="one_to_many checkboxset"><label>Tracks</label><div class="checkbox"><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></div>'
|
279
|
+
@c.input(:tracks, :as=>:checkbox,:wrapper=>:li).must_equal '<li class="one_to_many checkboxset"><label>Tracks</label><div class="checkbox"><label class="option" for="album_track_pks_1"><input id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input checked="checked" id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></li>'
|
280
280
|
end
|
281
281
|
|
282
282
|
it "should use multiple checkboxes for many_to_many associations if :as=>:checkbox" do
|
283
|
-
@b.input(:tags, :as=>:checkbox).
|
284
|
-
@c.input(:tags, :as=>:checkbox).
|
285
|
-
@c.input(:tags, :as=>:checkbox, :wrapper=>:div).
|
283
|
+
@b.input(:tags, :as=>:checkbox).must_equal '<div class="many_to_many checkboxset"><label>Tags</label><div class="checkbox"><label class="option" for="album_tag_pks_1"><input checked="checked" id="album_tag_pks_1" name="album[tag_pks][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_tag_pks_2"><input checked="checked" id="album_tag_pks_2" name="album[tag_pks][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_tag_pks_3"><input id="album_tag_pks_3" name="album[tag_pks][]" type="checkbox" value="3"/> u</label></div></div>'
|
284
|
+
@c.input(:tags, :as=>:checkbox).must_equal '<div class="many_to_many checkboxset"><label>Tags</label><div class="checkbox"><label class="option" for="album_tag_pks_1"><input id="album_tag_pks_1" name="album[tag_pks][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_tag_pks_2"><input checked="checked" id="album_tag_pks_2" name="album[tag_pks][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_tag_pks_3"><input id="album_tag_pks_3" name="album[tag_pks][]" type="checkbox" value="3"/> u</label></div></div>'
|
285
|
+
@c.input(:tags, :as=>:checkbox, :wrapper=>:div).must_equal '<div class="many_to_many checkboxset"><label>Tags</label><div class="checkbox"><label class="option" for="album_tag_pks_1"><input id="album_tag_pks_1" name="album[tag_pks][]" type="checkbox" value="1"/> s</label></div><div class="checkbox"><label class="option" for="album_tag_pks_2"><input checked="checked" id="album_tag_pks_2" name="album[tag_pks][]" type="checkbox" value="2"/> t</label></div><div class="checkbox"><label class="option" for="album_tag_pks_3"><input id="album_tag_pks_3" name="album[tag_pks][]" type="checkbox" value="3"/> u</label></div></div>'
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should handle Raw label for associations with :as=>:checkbox" do
|
289
|
-
@b.input(:tracks, :as=>:checkbox, :label=>'Foo<br />').
|
290
|
-
@b.input(:tracks, :as=>:checkbox, :label=>'Foo<br />',:wrapper=>:div).
|
289
|
+
@b.input(:tracks, :as=>:checkbox, :label=>'Foo<br />').must_equal '<div class="one_to_many checkboxset"><label>Foo<br /></label><div class="checkbox"><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></div>'
|
290
|
+
@b.input(:tracks, :as=>:checkbox, :label=>'Foo<br />',:wrapper=>:div).must_equal '<div class="one_to_many checkboxset"><label>Foo<br /></label><div class="checkbox"><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></div>'
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should correctly use the forms wrapper for wrapping radio buttons for one_to_many associations with :as=>:checkbox option" do
|
294
294
|
@b = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
295
|
-
@b.input(:tracks, :as=>:checkbox).
|
296
|
-
@b.input(:tracks, :as=>:checkbox, :wrapper=>:li).
|
295
|
+
@b.input(:tracks, :as=>:checkbox).must_equal '<div class="one_to_many checkboxset"><label>Tracks</label><div class="checkbox"><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></div>'
|
296
|
+
@b.input(:tracks, :as=>:checkbox, :wrapper=>:li).must_equal '<li class="one_to_many checkboxset"><label>Tracks</label><div class="checkbox"><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></div><div class="checkbox"><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></div><div class="checkbox"><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></div></li>'
|
297
297
|
end
|
298
298
|
|
299
299
|
it "should support custom wrappers for one_to_many associations with :as=>:checkbox via :tag_wrapper option" do
|
300
300
|
@b = Forme::Form.new(@ab, :config=>:bs3, :wrapper=>:li)
|
301
|
-
@b.input(:tracks, :as=>:checkbox, :wrapper=>proc{|t, i| i.tag(:div, i.opts[:wrapper_attr], [t])}, :tag_wrapper=>proc{|t, i| i.tag(:span, {}, [t])}).
|
301
|
+
@b.input(:tracks, :as=>:checkbox, :wrapper=>proc{|t, i| i.tag(:div, i.opts[:wrapper_attr], [t])}, :tag_wrapper=>proc{|t, i| i.tag(:span, {}, [t])}).must_equal '<div class="one_to_many checkboxset"><label>Tracks</label><span><label class="option" for="album_track_pks_1"><input checked="checked" id="album_track_pks_1" name="album[track_pks][]" type="checkbox" value="1"/> m</label></span><span><label class="option" for="album_track_pks_2"><input checked="checked" id="album_track_pks_2" name="album[track_pks][]" type="checkbox" value="2"/> n</label></span><span><label class="option" for="album_track_pks_3"><input id="album_track_pks_3" name="album[track_pks][]" type="checkbox" value="3"/> o</label></span></div>'
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should use a text field methods not backed by columns" do
|
305
|
-
@b.input(:artist_name).
|
306
|
-
@c.input(:artist_name).
|
305
|
+
@b.input(:artist_name).must_equal '<div class="form-group"><label for="album_artist_name">Artist name</label> <input class="form-control" id="album_artist_name" name="album[artist_name]" type="text" value="a"/></div>'
|
306
|
+
@c.input(:artist_name).must_equal '<div class="form-group"><label for="album_artist_name">Artist name</label> <input class="form-control" id="album_artist_name" name="album[artist_name]" type="text" value="d"/></div>'
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should handle errors on methods not backed by columns" do
|
310
310
|
@ab.errors.add(:artist_name, 'foo')
|
311
|
-
@b.input(:artist_name).
|
311
|
+
@b.input(:artist_name).must_equal '<div class="form-group has-error"><label for="album_artist_name">Artist name</label> <input aria-describedby="album_artist_name_error_message" aria-invalid="true" class="form-control" id="album_artist_name" name="album[artist_name]" type="text" value="a"/><span class="help-block with-errors" id="album_artist_name_error_message">foo</span></div>'
|
312
312
|
end
|
313
313
|
|
314
314
|
it "should respect a :type option with a schema type as the input type for methods not backed by columns" do
|
315
315
|
def @ab.foo; false end
|
316
|
-
@b.input(:foo, :type=>:boolean, :as=>:select).
|
316
|
+
@b.input(:foo, :type=>:boolean, :as=>:select).must_equal '<div class="form-group"><label for="album_foo">Foo</label> <select class="form-control" id="album_foo" name="album[foo]"><option value=""></option><option value="t">True</option><option selected="selected" value="f">False</option></select></div>'
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should respect a :type option with an input type as the input type for methods not backed by columns" do
|
320
320
|
def @ab.foo; "bar" end
|
321
|
-
@b.input(:foo, :type=>:phone).
|
321
|
+
@b.input(:foo, :type=>:phone).must_equal '<div class="form-group"><label for="album_foo">Foo</label> <input class="form-control" id="album_foo" name="album[foo]" type="phone" value="bar"/></div>'
|
322
322
|
end
|
323
323
|
|
324
324
|
it "should correctly show an error message if there is one" do
|
325
325
|
@ab.errors.add(:name, 'tis not valid')
|
326
|
-
@b.input(:name).
|
326
|
+
@b.input(:name).must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input aria-describedby="album_name_error_message" aria-invalid="true" class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/><span class="help-block with-errors" id="album_name_error_message">tis not valid</span></div>'
|
327
327
|
end
|
328
328
|
|
329
329
|
it "should correctly show an error message for many_to_one associations if there is one" do
|
330
330
|
@ab.errors.add(:artist_id, 'tis not valid')
|
331
|
-
@b.input(:artist).
|
331
|
+
@b.input(:artist).must_equal '<div class="form-group has-error many_to_one"><label for="album_artist_id">Artist</label> <select aria-describedby="album_artist_id_error_message" aria-invalid="true" class="form-control" id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select><span class="help-block with-errors" id="album_artist_id_error_message">tis not valid</span></div>'
|
332
332
|
end
|
333
333
|
|
334
334
|
it "should raise an error for unhandled associations" do
|
@@ -343,104 +343,104 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should respect a :type option with a schema type as the input type for unhandled fields" do
|
346
|
-
@b.input(:foo, :type=>:string).
|
347
|
-
@b.input(:password, :type=>:string).
|
346
|
+
@b.input(:foo, :type=>:string).must_equal '<div class="form-group"><label for="album_foo">Foo</label> <input class="form-control" id="album_foo" name="album[foo]" type="text"/></div>'
|
347
|
+
@b.input(:password, :type=>:string).must_equal '<div class="form-group"><label for="album_password">Password</label> <input class="form-control" id="album_password" name="album[password]" type="password"/></div>'
|
348
348
|
end
|
349
349
|
|
350
350
|
it "should respect a :type option with an input type as the input type for unhandled fields" do
|
351
|
-
@b.input(:foo, :type=>:phone).
|
351
|
+
@b.input(:foo, :type=>:phone).must_equal '<div class="form-group"><label for="album_foo">Foo</label> <input class="form-control" id="album_foo" name="album[foo]" type="phone"/></div>'
|
352
352
|
end
|
353
353
|
|
354
354
|
it "should respect a :multiple option for the name attribute for unhandled fields" do
|
355
|
-
@b.input(:foo, :type=>:phone, :multiple=>true).
|
355
|
+
@b.input(:foo, :type=>:phone, :multiple=>true).must_equal '<div class="form-group"><label for="album_foo">Foo</label> <input class="form-control" id="album_foo" name="album[foo][]" type="phone"/></div>'
|
356
356
|
end
|
357
357
|
|
358
358
|
it "should add required attribute if the column doesn't support nil values" do
|
359
359
|
def @ab.db_schema; h = super.dup; h[:name] = h[:name].merge(:allow_null=>false); h end
|
360
|
-
@b.input(:name).
|
360
|
+
@b.input(:name).must_equal '<div class="form-group required string"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" required="required" type="text" value="b"/></div>'
|
361
361
|
end
|
362
362
|
|
363
363
|
it "should use allow nested forms with many_to_one associations" do
|
364
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.
|
364
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
365
365
|
end
|
366
366
|
|
367
367
|
it "should have #subform respect an :inputs option" do
|
368
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name])}.
|
368
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name])}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
369
369
|
end
|
370
370
|
|
371
371
|
it "should have #subform respect an :obj option overriding the object to use" do
|
372
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :obj=>Artist.new(:name=>'b'))}.
|
372
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :obj=>Artist.new(:name=>'b'))}.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="b"/></div></fieldset></form>'
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should have #subform respect a :legend option if :inputs is used" do
|
376
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>'Foo')}.
|
376
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>'Foo')}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
377
377
|
end
|
378
378
|
|
379
379
|
it "should have #subform respect a callable :legend option if :inputs is used" do
|
380
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>proc{|o| "Foo - #{o.name}"})}.
|
380
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>proc{|o| "Foo - #{o.name}"})}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Foo - a</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
381
381
|
end
|
382
382
|
|
383
383
|
it "should not add hidden primary key field for new many_to_one associated objects" do
|
384
384
|
@ab.associations[:artist] = Artist.new(:name=>'a')
|
385
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.
|
385
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Artist</legend><div class="form-group string"><label for="album_artist_attributes_name">Name</label> <input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
386
386
|
end
|
387
387
|
|
388
388
|
it "should use allow nested forms with one_to_one associations" do
|
389
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:album_info, :obj=>AlbumInfo.new(:info=>'a')){f.input(:info)}}.
|
389
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:album_info, :obj=>AlbumInfo.new(:info=>'a')){f.input(:info)}}.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Album info</legend><div class="form-group string"><label for="album_album_info_attributes_info">Info</label> <input class="form-control" id="album_album_info_attributes_info" maxlength="255" name="album[album_info_attributes][info]" type="text" value="a"/></div></fieldset></form>'
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should use allow nested forms with one_to_many associations" do
|
393
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.
|
393
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
394
394
|
end
|
395
395
|
|
396
396
|
it "should support :obj option for *_to_many associations" do
|
397
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.
|
397
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
|
398
398
|
end
|
399
399
|
|
400
400
|
it "should auto number legends when using subform with inputs for *_to_many associations" do
|
401
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.
|
401
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
402
402
|
end
|
403
403
|
|
404
404
|
it "should support callable :legend option when using subform with inputs for *_to_many associations" do
|
405
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.
|
405
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 0 (m)</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track 1 (n)</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
406
406
|
end
|
407
407
|
|
408
408
|
it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
|
409
409
|
@ab.associations[:tracks] = [Track.new(:name=>'m'), Track.new(:name=>'n')]
|
410
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.
|
410
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
411
411
|
end
|
412
412
|
|
413
413
|
it "should use allow nested forms with many_to_many associations" do
|
414
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.
|
414
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
415
415
|
end
|
416
416
|
|
417
417
|
it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
|
418
418
|
@ab.associations[:tags] = [Tag.new(:name=>'s'), Tag.new(:name=>'t')]
|
419
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.
|
419
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
420
420
|
end
|
421
421
|
|
422
422
|
it "should handle multiple nested levels" do
|
423
|
-
Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.
|
423
|
+
Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></div><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_1_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
|
424
424
|
end
|
425
425
|
|
426
426
|
it "should have #subform :grid option create a grid" do
|
427
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.
|
427
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
428
428
|
end
|
429
429
|
|
430
430
|
it "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
|
431
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.
|
431
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
432
432
|
end
|
433
433
|
|
434
434
|
it "should have #subform :grid option handle :legend and :labels options" do
|
435
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.
|
435
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
436
436
|
end
|
437
437
|
|
438
438
|
it "should have #subform :grid option handle :legend and :labels nil values" do
|
439
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.
|
439
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
440
440
|
end
|
441
441
|
|
442
442
|
it "should have #subform :grid option handle :skip_primary_key option" do
|
443
|
-
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.
|
443
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
444
444
|
end
|
445
445
|
|
446
446
|
end
|
@@ -452,22 +452,22 @@ describe "Forme Sequel plugin default input types based on column names" do
|
|
452
452
|
end
|
453
453
|
|
454
454
|
it "should use password input with no value for string columns with name password" do
|
455
|
-
f(:password).
|
455
|
+
f(:password).must_equal '<div class="form-group string"><label for="test_password">Password</label> <input class="form-control" id="test_password" maxlength="255" name="test[password]" type="password"/></div>'
|
456
456
|
end
|
457
457
|
|
458
458
|
it "should use email input for string columns with name email" do
|
459
|
-
f(:email).
|
459
|
+
f(:email).must_equal '<div class="form-group string"><label for="test_email">Email</label> <input class="form-control" id="test_email" maxlength="255" name="test[email]" type="email" value="foo"/></div>'
|
460
460
|
end
|
461
461
|
|
462
462
|
it "should use tel input for string columns with name phone or fax" do
|
463
|
-
f(:phone).
|
464
|
-
f(:fax).
|
463
|
+
f(:phone).must_equal '<div class="form-group string"><label for="test_phone">Phone</label> <input class="form-control" id="test_phone" maxlength="255" name="test[phone]" type="tel" value="foo"/></div>'
|
464
|
+
f(:fax).must_equal '<div class="form-group string"><label for="test_fax">Fax</label> <input class="form-control" id="test_fax" maxlength="255" name="test[fax]" type="tel" value="foo"/></div>'
|
465
465
|
end
|
466
466
|
|
467
467
|
it "should use url input for string columns with name url, uri, or website" do
|
468
|
-
f(:url).
|
469
|
-
f(:uri).
|
470
|
-
f(:website).
|
468
|
+
f(:url).must_equal '<div class="form-group string"><label for="test_url">Url</label> <input class="form-control" id="test_url" maxlength="255" name="test[url]" type="url" value="foo"/></div>'
|
469
|
+
f(:uri).must_equal '<div class="form-group string"><label for="test_uri">Uri</label> <input class="form-control" id="test_uri" maxlength="255" name="test[uri]" type="url" value="foo"/></div>'
|
470
|
+
f(:website).must_equal '<div class="form-group string"><label for="test_website">Website</label> <input class="form-control" id="test_website" maxlength="255" name="test[website]" type="url" value="foo"/></div>'
|
471
471
|
end
|
472
472
|
end
|
473
473
|
|
@@ -478,7 +478,7 @@ describe "Forme Sequel plugin default input types based on column type" do
|
|
478
478
|
end
|
479
479
|
|
480
480
|
it "should use password input with no value for string columns with name password" do
|
481
|
-
f(File).
|
481
|
+
f(File).must_equal '<div class="blob form-group"><label for="test_foo">Foo</label> <input id="test_foo" name="test[foo]" type="file"/></div>'
|
482
482
|
end
|
483
483
|
end
|
484
484
|
|
@@ -491,33 +491,33 @@ describe "Forme Sequel::Model validation parsing" do
|
|
491
491
|
end
|
492
492
|
|
493
493
|
it "should turn format into a pattern" do
|
494
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).
|
494
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" pattern="[A-z]+" type="text"/></div>'
|
495
495
|
end
|
496
496
|
|
497
497
|
it "should respect :title option for format" do
|
498
|
-
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).
|
498
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" pattern="[A-z]+" title="Foo" type="text"/></div>'
|
499
499
|
end
|
500
500
|
|
501
501
|
it "should use maxlength for length :maximum, :is, and :within" do
|
502
|
-
f(:validates_length_of, :name, :maximum=>10).input(:name).
|
503
|
-
f(:validates_length_of, :name, :is=>10).input(:name).
|
504
|
-
f(:validates_length_of, :name, :within=>2..10).input(:name).
|
505
|
-
f(:validates_length_of, :name, :within=>2...11).input(:name).
|
502
|
+
f(:validates_length_of, :name, :maximum=>10).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="10" name="album[name]" type="text"/></div>'
|
503
|
+
f(:validates_length_of, :name, :is=>10).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="10" name="album[name]" type="text"/></div>'
|
504
|
+
f(:validates_length_of, :name, :within=>2..10).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="10" name="album[name]" type="text"/></div>'
|
505
|
+
f(:validates_length_of, :name, :within=>2...11).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="10" name="album[name]" type="text"/></div>'
|
506
506
|
end
|
507
507
|
|
508
508
|
it "should turn numericality into a pattern" do
|
509
|
-
f(:validates_numericality_of, :name).input(:name).
|
509
|
+
f(:validates_numericality_of, :name).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></div>'
|
510
510
|
end
|
511
511
|
|
512
512
|
it "should turn numericality :only_integer into a pattern" do
|
513
|
-
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).
|
513
|
+
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></div>'
|
514
514
|
end
|
515
515
|
|
516
516
|
it "should respect :title option for numericality" do
|
517
|
-
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).
|
517
|
+
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></div>'
|
518
518
|
end
|
519
519
|
|
520
520
|
it "should respect :placeholder option for any validation" do
|
521
|
-
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).
|
521
|
+
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" placeholder="must be unique" type="text"/></div>'
|
522
522
|
end
|
523
523
|
end
|