forme 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +14 -0
- data/lib/forme.rb +25 -0
- data/lib/forme/transformers/formatter.rb +22 -9
- data/lib/forme/transformers/serializer.rb +1 -12
- data/lib/forme/version.rb +1 -1
- data/lib/sequel/plugins/forme.rb +5 -1
- data/lib/sequel/plugins/forme_set.rb +1 -1
- data/spec/bs3_reference_spec.rb +4 -4
- data/spec/bs3_sequel_plugin_spec.rb +45 -45
- data/spec/bs3_spec.rb +1 -1
- data/spec/erb_helper.rb +2 -2
- data/spec/forme_spec.rb +25 -4
- data/spec/rails_integration_spec.rb +4 -4
- data/spec/sequel_i18n_plugin_spec.rb +4 -4
- data/spec/sequel_plugin_spec.rb +48 -49
- data/spec/sequel_set_plugin_spec.rb +55 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abf3346d90f5f4eddb69a0c0c2a63a2fcee549cf2b928bec7ab8a9505a8135aa
|
4
|
+
data.tar.gz: 577dccded6b59dae158e5275b7bed4dcb87a9756b29d2e3f367accca1f32313b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35dbc13c7de3c746a229b0f4d6026a0dfc3b8fa9dda3952ae3aa2117c6b1ad843ec07c3c40ab754cd2ae91c3ffea83cb281ee48539b886b48b832f2f1f887bab
|
7
|
+
data.tar.gz: 39fdd8a5b87777f1fd1831adf05c100624619e7e1cdf09d9e207d8118a8ab154971f6d229d7db1c3141faf423816a68a66b67001fd4e0b29462af2a545493e09
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 1.9.0 (2018-11-16)
|
2
|
+
|
3
|
+
* Automatically add maxlength attributes to text and textarea inputs in the Sequel plugin based on maximum database column length (jeremyevans)
|
4
|
+
|
5
|
+
* Make forme_set Sequel plugin recognize default formatter changes set via with_opts (jeremyevans)
|
6
|
+
|
7
|
+
* Use div with nested p tags instead of spans for readonly textarea inputs (jeremyevans)
|
8
|
+
|
9
|
+
* Make readonly text input spans use the readonly-text class for easier styling (jeremyevans)
|
10
|
+
|
11
|
+
* Add Forme.h for HTML escaping, using cgi/escape if available for faster escaping (jeremyevans)
|
12
|
+
|
13
|
+
* Correctly handle :value=>false option and false option values in select, radioset, and checkboxset inputs (jeremyevans)
|
14
|
+
|
1
15
|
=== 1.8.0 (2018-06-11)
|
2
16
|
|
3
17
|
* Add support for :errors form option for setting error information for multiple inputs, similar to :values form option (adam12) (#32)
|
data/lib/forme.rb
CHANGED
@@ -8,6 +8,31 @@ module Forme
|
|
8
8
|
class Error < StandardError
|
9
9
|
end
|
10
10
|
|
11
|
+
begin
|
12
|
+
require 'cgi/escape'
|
13
|
+
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
14
|
+
CGI = Object.new
|
15
|
+
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
|
16
|
+
end
|
17
|
+
def self.h(value)
|
18
|
+
CGI.escapeHTML(value.to_s)
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
ESCAPE_TABLE = {'&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => '''}.freeze
|
22
|
+
ESCAPE_TABLE.each_value(&:freeze)
|
23
|
+
if RUBY_VERSION >= '1.9'
|
24
|
+
# Escape the following characters with their HTML/XML
|
25
|
+
# equivalents.
|
26
|
+
def self.h(value)
|
27
|
+
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
def self.h(value)
|
31
|
+
value.to_s.gsub(/[&<>"']/){|s| ESCAPE_TABLE[s]}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
11
36
|
@default_add_blank_prompt = nil
|
12
37
|
@default_config = :default
|
13
38
|
class << self
|
@@ -186,9 +186,9 @@ module Forme
|
|
186
186
|
copy_options_to_attributes([:size])
|
187
187
|
|
188
188
|
os = process_select_optgroups(:_format_select_optgroup) do |label, value, sel, attrs|
|
189
|
-
if value || sel
|
190
|
-
|
191
|
-
attrs[:value] = value
|
189
|
+
if !value.nil? || sel
|
190
|
+
attrs = attrs.dup
|
191
|
+
attrs[:value] = value unless value.nil?
|
192
192
|
attrs[:selected] = :selected if sel
|
193
193
|
end
|
194
194
|
tag(:option, attrs, [label])
|
@@ -234,11 +234,13 @@ module Forme
|
|
234
234
|
wrapper = Forme.transformer(:wrapper, wrapper)
|
235
235
|
|
236
236
|
tags = process_select_optgroups(:_format_set_optgroup) do |label, value, sel, attrs|
|
237
|
-
value
|
237
|
+
value = label if value.nil?
|
238
238
|
label_attr = {:class=>:option}
|
239
239
|
label_attr.merge!(@opts[:label_attr]) if @opts[:label_attr]
|
240
240
|
r_opts = attrs.merge(tag_attrs).merge(:label=>label||value, :label_attr=>label_attr, :wrapper=>tag_wrapper, :labeler=>tag_labeler)
|
241
|
-
r_opts[:value]
|
241
|
+
if r_opts[:value].nil?
|
242
|
+
r_opts[:value] = value unless value.nil?
|
243
|
+
end
|
242
244
|
r_opts[:checked] ||= :checked if sel
|
243
245
|
r_opts[:formatter] = @opts[:formatter] if @opts[:formatter]
|
244
246
|
|
@@ -462,7 +464,7 @@ module Forme
|
|
462
464
|
text = x
|
463
465
|
end
|
464
466
|
|
465
|
-
yield [text, val, val ? cmp.call(val) : cmp.call(text), attr]
|
467
|
+
yield [text, val, !val.nil? ? cmp.call(val) : cmp.call(text), attr]
|
466
468
|
end
|
467
469
|
end
|
468
470
|
end
|
@@ -539,7 +541,7 @@ module Forme
|
|
539
541
|
|
540
542
|
# Use a span with text instead of an input field.
|
541
543
|
def _format_input(type)
|
542
|
-
tag(:span, {}, @attr[:value])
|
544
|
+
tag(:span, {'class'=>'readonly-text'}, @attr[:value])
|
543
545
|
end
|
544
546
|
|
545
547
|
# Disabled radio button inputs.
|
@@ -560,9 +562,20 @@ module Forme
|
|
560
562
|
''
|
561
563
|
end
|
562
564
|
|
563
|
-
#
|
565
|
+
# Format the text as separate paragraphs.
|
564
566
|
def format_textarea
|
565
|
-
|
567
|
+
text = @attr[:value]
|
568
|
+
case text
|
569
|
+
when nil, Forme::Raw
|
570
|
+
# nothing
|
571
|
+
when String
|
572
|
+
text = text.gsub(/\A[\r\n]+|[\r\n]+\z/, '').split(/(?:\r?\n)(?:\r?\n)+/).map do |t|
|
573
|
+
t = Forme.h(t)
|
574
|
+
t.gsub!(/\r?\n/, "<br />")
|
575
|
+
tag(:p, {}, Forme.raw(t))
|
576
|
+
end
|
577
|
+
end
|
578
|
+
tag(:div, {'class'=>'readonly-textarea'}, text)
|
566
579
|
end
|
567
580
|
end
|
568
581
|
end
|
@@ -8,12 +8,6 @@ module Forme
|
|
8
8
|
class Serializer
|
9
9
|
Forme.register_transformer(:serializer, :default, new)
|
10
10
|
|
11
|
-
# Borrowed from Rack::Utils, map of single character strings to html escaped versions.
|
12
|
-
ESCAPE_HTML = {"&" => "&", "<" => "<", ">" => ">", "'" => "'", '"' => """}
|
13
|
-
|
14
|
-
# A regexp that matches all html characters requiring escaping.
|
15
|
-
ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)
|
16
|
-
|
17
11
|
# Which tags are self closing (such tags ignore children).
|
18
12
|
SELF_CLOSING = [:img, :input]
|
19
13
|
|
@@ -43,7 +37,7 @@ module Forme
|
|
43
37
|
when Raw
|
44
38
|
tag.to_s
|
45
39
|
else
|
46
|
-
h
|
40
|
+
Forme.h(tag)
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
@@ -69,11 +63,6 @@ module Forme
|
|
69
63
|
time.is_a?(Time) ? (time.strftime('%Y-%m-%dT%H:%M:%S') + sprintf(".%03d", time.usec)) : (time.strftime('%Y-%m-%dT%H:%M:%S.') + time.strftime('%N')[0...3])
|
70
64
|
end
|
71
65
|
|
72
|
-
# Escape ampersands, brackets and quotes to their HTML/XML entities.
|
73
|
-
def h(string)
|
74
|
-
string.to_s.gsub(ESCAPE_HTML_PATTERN){|c| ESCAPE_HTML[c] }
|
75
|
-
end
|
76
|
-
|
77
66
|
# Join attribute values that are arrays with spaces instead of an empty
|
78
67
|
# string.
|
79
68
|
def attr_value(v)
|
data/lib/forme/version.rb
CHANGED
data/lib/sequel/plugins/forme.rb
CHANGED
@@ -207,6 +207,7 @@ module Sequel # :nodoc:
|
|
207
207
|
# Update the attributes and options for any recognized validations
|
208
208
|
def handle_validations(f)
|
209
209
|
m = obj.model
|
210
|
+
|
210
211
|
if m.respond_to?(:validation_reflections) and (vs = m.validation_reflections[f])
|
211
212
|
attr = opts[:attr]
|
212
213
|
vs.each do |type, options|
|
@@ -218,7 +219,7 @@ module Sequel # :nodoc:
|
|
218
219
|
attr[:title] = options[:title] unless attr.has_key?(:title)
|
219
220
|
when :length
|
220
221
|
unless attr.has_key?(:maxlength)
|
221
|
-
if max =(options[:maximum] || options[:is])
|
222
|
+
if max = (options[:maximum] || options[:is])
|
222
223
|
attr[:maxlength] = max
|
223
224
|
elsif (w = options[:within]) && w.is_a?(Range)
|
224
225
|
attr[:maxlength] = if w.exclude_end? && w.end.is_a?(Integer)
|
@@ -442,6 +443,9 @@ module Sequel # :nodoc:
|
|
442
443
|
# is overridden.
|
443
444
|
def standard_input(type)
|
444
445
|
type = opts.delete(:type) || type
|
446
|
+
if type.to_s =~ /\A(text|textarea|password|email|tel|url)\z/ && !opts[:attr].has_key?(:maxlength) && (sch = obj.db_schema[field]) && (max_length = sch[:max_length])
|
447
|
+
opts[:attr][:maxlength] = max_length
|
448
|
+
end
|
445
449
|
opts[:value] = obj.send(field) unless opts.has_key?(:value)
|
446
450
|
_input(type, opts)
|
447
451
|
end
|
@@ -48,7 +48,7 @@ module Sequel # :nodoc:
|
|
48
48
|
|
49
49
|
forme_inputs.each do |field, input|
|
50
50
|
opts = input.opts
|
51
|
-
next if SKIP_FORMATTERS.include?(opts.fetch(:formatter){input.
|
51
|
+
next if SKIP_FORMATTERS.include?(opts.fetch(:formatter){input.form_opts[:formatter]})
|
52
52
|
|
53
53
|
if attr = opts[:attr]
|
54
54
|
name = attr[:name] || attr['name']
|
data/spec/bs3_reference_spec.rb
CHANGED
@@ -38,12 +38,12 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
38
38
|
|
39
39
|
describe 'from a Sequel model' do
|
40
40
|
it "should create a correct input[:text] tag from Sequel model" do
|
41
|
-
@c.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="c"/></div>'
|
41
|
+
@c.input(:name).to_s.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>'
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
45
45
|
@ac.errors.add(:name, 'name not valid')
|
46
|
-
@c.input(:name).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="c"/><span class="help-block with-errors">name not valid</span></div>'
|
46
|
+
@c.input(:name).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="c"/><span class="help-block with-errors">name not valid</span></div>'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -185,12 +185,12 @@ describe "Forme Bootstrap3 (BS3) forms" do
|
|
185
185
|
|
186
186
|
describe 'from a Sequel model' do
|
187
187
|
it "should create a correct input[:text] tag from Sequel model" do
|
188
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
188
|
+
@c.input(:name, :as=>:textarea).to_s.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>'
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
192
192
|
@ac.errors.add(:name, 'name not valid')
|
193
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea><span class="help-block with-errors">name not valid</span></div>'
|
193
|
+
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" maxlength="255" name="album[name]">c</textarea><span class="help-block with-errors">name not valid</span></div>'
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
@@ -31,18 +31,18 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should use a text field for strings" do
|
34
|
-
@b.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/></div>'
|
35
|
-
@c.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="c"/></div>'
|
34
|
+
@b.input(:name).to_s.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).to_s.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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">b</textarea></div>'
|
40
|
-
@c.input(:name, :as=>:textarea).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
39
|
+
@b.input(:name, :as=>:textarea).to_s.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).to_s.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).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">b</textarea></div>'
|
45
|
-
@c.input(:name, :type=>:textarea).to_s.must_equal '<div class="form-group"><label for="album_name">Name</label> <textarea class="form-control" id="album_name" name="album[name]">c</textarea></div>'
|
44
|
+
@b.input(:name, :type=>:textarea).to_s.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).to_s.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
|
@@ -65,22 +65,22 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/></div>'
|
68
|
+
f.input(:name).to_s.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
69
|
f.input(:release_date).to_s.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
70
|
f.input(:created_at).to_s.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).to_s.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" name="album[name]" required="required" type="text" value="b"/></div>'
|
74
|
+
@b.input(:name, :required=>true).to_s.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').to_s.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" name="album[name]" required="required" type="text" value="b"/></div>'
|
78
|
+
@b.input(:name, :required=>true, :label=>'Foo').to_s.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).to_s.must_equal '<li class="string required"><label for="album_name">Name<abbr title="required">*</abbr></label> <input class="form-control" id="album_name" name="album[name]" required="required" type="text" value="b"/></li>'
|
83
|
+
f.input(:name, :required=>true).to_s.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
|
@@ -323,7 +323,7 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
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).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/><span class="help-block with-errors">tis not valid</span></div>'
|
326
|
+
@b.input(:name).to_s.must_equal '<div class="form-group has-error string"><label for="album_name">Name</label> <input class="form-control" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/><span class="help-block with-errors">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
|
@@ -357,90 +357,90 @@ describe "Forme Sequel::Model BS3 forms" do
|
|
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).to_s.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" name="album[name]" required="required" type="text" value="b"/></div>'
|
360
|
+
@b.input(:name).to_s.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)}}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
364
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.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])}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
368
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name])}.to_s.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'))}.to_s.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" name="album[artist_attributes][name]" type="text" value="b"/></div></fieldset></form>'
|
372
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :obj=>Artist.new(:name=>'b'))}.to_s.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')}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
376
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>'Foo')}.to_s.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}"})}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
380
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :legend=>proc{|o| "Foo - #{o.name}"})}.to_s.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)}}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></div></fieldset></form>'
|
385
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist){f.input(:name)}}.to_s.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)}}.to_s.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" name="album[album_info_attributes][info]" type="text" value="a"/></div></fieldset></form>'
|
389
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:album_info, :obj=>AlbumInfo.new(:info=>'a')){f.input(:info)}}.to_s.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)}}.to_s.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"/><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" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
393
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.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"/><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><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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)}}.to_s.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" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><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" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
|
397
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.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="x"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><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])}.to_s.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"/><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" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
401
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.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"/><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><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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})"})}.to_s.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"/><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" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
405
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.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"/><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><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><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)}}.to_s.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" 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" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
|
410
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.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)}}.to_s.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"/><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" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><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" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
414
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.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"/><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><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><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)}}.to_s.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" 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" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
|
419
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.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.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" 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"/><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" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><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 #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" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
|
423
|
+
Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.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"/><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><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 #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)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
427
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><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'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
431
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><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')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
435
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><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)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
439
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><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)}.to_s.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" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
|
443
|
+
Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.to_s.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).to_s.must_equal '<div class="form-group string"><label for="test_password">Password</label> <input class="form-control" id="test_password" name="test[password]" type="password"/></div>'
|
455
|
+
f(:password).to_s.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).to_s.must_equal '<div class="form-group string"><label for="test_email">Email</label> <input class="form-control" id="test_email" name="test[email]" type="email" value="foo"/></div>'
|
459
|
+
f(:email).to_s.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).to_s.must_equal '<div class="form-group string"><label for="test_phone">Phone</label> <input class="form-control" id="test_phone" name="test[phone]" type="tel" value="foo"/></div>'
|
464
|
-
f(:fax).to_s.must_equal '<div class="form-group string"><label for="test_fax">Fax</label> <input class="form-control" id="test_fax" name="test[fax]" type="tel" value="foo"/></div>'
|
463
|
+
f(:phone).to_s.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).to_s.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).to_s.must_equal '<div class="form-group string"><label for="test_url">Url</label> <input class="form-control" id="test_url" name="test[url]" type="url" value="foo"/></div>'
|
469
|
-
f(:uri).to_s.must_equal '<div class="form-group string"><label for="test_uri">Uri</label> <input class="form-control" id="test_uri" name="test[uri]" type="url" value="foo"/></div>'
|
470
|
-
f(:website).to_s.must_equal '<div class="form-group string"><label for="test_website">Website</label> <input class="form-control" id="test_website" name="test[website]" type="url" value="foo"/></div>'
|
468
|
+
f(:url).to_s.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).to_s.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).to_s.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
|
|
@@ -491,11 +491,11 @@ 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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="[A-z]+" type="text"/></div>'
|
494
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/).input(:name).to_s.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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="[A-z]+" title="Foo" type="text"/></div>'
|
498
|
+
f(:validates_format_of, :name, :with=>/[A-z]+/, :title=>'Foo').input(:name).to_s.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
|
@@ -506,18 +506,18 @@ describe "Forme Sequel::Model validation parsing" do
|
|
506
506
|
end
|
507
507
|
|
508
508
|
it "should turn numericality into a pattern" do
|
509
|
-
f(:validates_numericality_of, :name).input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="must be a number" type="text"/></div>'
|
509
|
+
f(:validates_numericality_of, :name).input(:name).to_s.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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+$" title="must be a number" type="text"/></div>'
|
513
|
+
f(:validates_numericality_of, :name, :only_integer=>true).input(:name).to_s.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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" pattern="^[+\-]?\d+(\.\d+)?$" title="Foo" type="text"/></div>'
|
517
|
+
f(:validates_numericality_of, :name, :title=>'Foo').input(:name).to_s.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).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" placeholder="must be unique" type="text"/></div>'
|
521
|
+
f(:validates_uniqueness_of, :name, :placeholder=>'must be unique').input(:name).to_s.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
|