forme 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +16 -0
- data/README.rdoc +10 -5
- data/lib/forme/bs3.rb +7 -7
- data/lib/forme/bs5.rb +213 -0
- 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/forme.rb +2 -1
- data/lib/roda/plugins/forme_set.rb +5 -3
- data/lib/sequel/plugins/forme.rb +8 -6
- data/lib/sequel/plugins/forme_set.rb +4 -4
- metadata +7 -24
- data/Rakefile +0 -82
- data/spec/all.rb +0 -2
- data/spec/bs3_reference_spec.rb +0 -358
- data/spec/bs3_sequel_plugin_spec.rb +0 -523
- data/spec/bs3_spec.rb +0 -722
- data/spec/erb_helper.rb +0 -198
- data/spec/erubi_capture_helper.rb +0 -198
- data/spec/forme_coverage.rb +0 -13
- data/spec/forme_spec.rb +0 -1216
- data/spec/rails_integration_spec.rb +0 -274
- data/spec/roda_integration_spec.rb +0 -523
- data/spec/sequel_helper.rb +0 -101
- data/spec/sequel_i18n_helper.rb +0 -40
- data/spec/sequel_i18n_plugin_spec.rb +0 -31
- data/spec/sequel_plugin_spec.rb +0 -600
- data/spec/sequel_set_plugin_spec.rb +0 -232
- data/spec/shared_erb_specs.rb +0 -71
- data/spec/sinatra_integration_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -31
data/Rakefile
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require "rake"
|
2
|
-
require "rake/clean"
|
3
|
-
|
4
|
-
NAME = 'forme'
|
5
|
-
VERS = lambda do
|
6
|
-
require File.expand_path("../lib/forme/version", __FILE__)
|
7
|
-
Forme.version
|
8
|
-
end
|
9
|
-
CLEAN.include ["#{NAME}-*.gem", "rdoc", "coverage", '**/*.rbc']
|
10
|
-
|
11
|
-
# Gem Packaging and Release
|
12
|
-
|
13
|
-
desc "Packages #{NAME}"
|
14
|
-
task :package=>[:clean] do |p|
|
15
|
-
sh %{gem build #{NAME}.gemspec}
|
16
|
-
end
|
17
|
-
|
18
|
-
desc "Upload #{NAME} gem to rubygems"
|
19
|
-
task :release=>[:package] do
|
20
|
-
sh %{gem push ./#{NAME}-#{VERS.call}.gem}
|
21
|
-
end
|
22
|
-
|
23
|
-
### RDoc
|
24
|
-
|
25
|
-
RDOC_DEFAULT_OPTS = ["--line-numbers", "--inline-source", '--title', 'Forme']
|
26
|
-
|
27
|
-
begin
|
28
|
-
gem 'hanna-nouveau'
|
29
|
-
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
|
30
|
-
rescue Gem::LoadError
|
31
|
-
end
|
32
|
-
|
33
|
-
rdoc_task_class = begin
|
34
|
-
require "rdoc/task"
|
35
|
-
RDoc::Task
|
36
|
-
rescue LoadError
|
37
|
-
require "rake/rdoctask"
|
38
|
-
Rake::RDocTask
|
39
|
-
end
|
40
|
-
|
41
|
-
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
42
|
-
|
43
|
-
rdoc_task_class.new do |rdoc|
|
44
|
-
rdoc.rdoc_dir = "rdoc"
|
45
|
-
rdoc.options += RDOC_OPTS
|
46
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
47
|
-
end
|
48
|
-
|
49
|
-
### Specs
|
50
|
-
|
51
|
-
desc "Run specs"
|
52
|
-
task :spec do
|
53
|
-
sh "#{FileUtils::RUBY} #{'-w' if RUBY_VERSION >= '3'} spec/all.rb"
|
54
|
-
end
|
55
|
-
task :default => :spec
|
56
|
-
|
57
|
-
desc "Run specs with coverage"
|
58
|
-
task :spec_cov do
|
59
|
-
ENV['COVERAGE'] = '1'
|
60
|
-
sh "#{FileUtils::RUBY} spec/all.rb"
|
61
|
-
end
|
62
|
-
|
63
|
-
### Other
|
64
|
-
|
65
|
-
desc "Print #{NAME} version"
|
66
|
-
task :version do
|
67
|
-
puts VERS.call
|
68
|
-
end
|
69
|
-
|
70
|
-
desc "Check syntax of all .rb files"
|
71
|
-
task :check_syntax do
|
72
|
-
Dir['**/*.rb'].each{|file| print `#{ENV['RUBY'] || :ruby} -c #{file} | fgrep -v "Syntax OK"`}
|
73
|
-
end
|
74
|
-
|
75
|
-
desc "Start an IRB shell using the extension"
|
76
|
-
task :irb do
|
77
|
-
require 'rbconfig'
|
78
|
-
ruby = ENV['RUBY'] || File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
|
79
|
-
irb = ENV['IRB'] || File.join(RbConfig::CONFIG['bindir'], File.basename(ruby).sub('ruby', 'irb'))
|
80
|
-
sh %{#{irb} -I lib -r forme}
|
81
|
-
end
|
82
|
-
|
data/spec/all.rb
DELETED
data/spec/bs3_reference_spec.rb
DELETED
@@ -1,358 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require_relative 'sequel_helper'
|
3
|
-
require_relative '../lib/forme/bs3'
|
4
|
-
|
5
|
-
describe "Forme Bootstrap3 (BS3) forms" do
|
6
|
-
def sel(opts, s)
|
7
|
-
opts.map{|o| "<option #{'selected="selected" ' if o == s}value=\"#{o}\">#{sprintf("%02i", o)}</option>"}.join
|
8
|
-
end
|
9
|
-
|
10
|
-
before do
|
11
|
-
@f = Forme::Form.new(:config=>:bs3)
|
12
|
-
@ab = Album[1]
|
13
|
-
@b = Forme::Form.new(@ab, :config=>:bs3)
|
14
|
-
@ac = Album[2]
|
15
|
-
@c = Forme::Form.new(@ac, :config=>:bs3)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'input[:text]' do
|
19
|
-
it "should create a simple input[:text] tag" do
|
20
|
-
@f.input(:text).to_s.must_equal '<div class="form-group"><input class="form-control" type="text"/></div>'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should create an input[:text] tag with a label when ':label => Name'" do
|
24
|
-
@f.input(:text, :label=>"Name").to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="text"/></div>'
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should create an input[:text] tag with a label when ':class => bar'" do
|
28
|
-
@f.input(:text, :label=>"Name", :class=>'bar').to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="text"/></div>'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create an input[:text] tag with a label when ':id => bar'" do
|
32
|
-
@f.input(:text, :label=>"Name", :id=>'bar').to_s.must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="text"/></div>'
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should create an input[:text] tag with a label when ':id => bar' with an error" do
|
36
|
-
@f.input(:text, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-text-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="text"/><span class="help-block with-errors">input-text-error</span></div>'
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'from a Sequel model' do
|
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" maxlength="255" name="album[name]" type="text" value="c"/></div>'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
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 aria-describedby="album_name_error_message" aria-invalid="true" 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
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'input[:password]' do
|
52
|
-
it "should create a simple input[:password] tag" do
|
53
|
-
@f.input(:password).to_s.must_equal '<div class="form-group"><input class="form-control" type="password"/></div>'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should create an input[:password] tag with a label when ':label => Name'" do
|
57
|
-
@f.input(:password, :label=>"Name").to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="password"/></div>'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should create an input[:password] tag with a label when ':class => bar'" do
|
61
|
-
@f.input(:password, :label=>"Name", :class=>'bar').to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="password"/></div>'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should create an input[:password] tag with a label when ':id => bar'" do
|
65
|
-
@f.input(:password, :label=>"Name", :id=>'bar').to_s.must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="password"/></div>'
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should create an input[:password] tag with a label when ':id => bar' with an error" do
|
69
|
-
@f.input(:password, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-password-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="password"/><span class="help-block with-errors">input-password-error</span></div>'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'input[:email]' do
|
74
|
-
it "should create a simple input[:email] tag" do
|
75
|
-
@f.input(:email).to_s.must_equal '<div class="form-group"><input class="form-control" type="email"/></div>'
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should create an input[:email] tag with a label when ':label => Name'" do
|
79
|
-
@f.input(:email, :label=>"Name").to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control" type="email"/></div>'
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should create an input[:email] tag with a label when ':class => bar'" do
|
83
|
-
@f.input(:email, :label=>"Name", :class=>'bar').to_s.must_equal '<div class="form-group"><label>Name</label> <input class="form-control bar" type="email"/></div>'
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should create an input[:email] tag with a label when ':id => bar'" do
|
87
|
-
@f.input(:email, :label=>"Name", :id=>'bar').to_s.must_equal '<div class="form-group"><label for="bar">Name</label> <input class="form-control" id="bar" type="email"/></div>'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should create an input[:email] tag with a label when ':id => bar' with an error" do
|
91
|
-
@f.input(:email, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-email-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="form-control foo" id="bar" type="email"/><span class="help-block with-errors">input-email-error</span></div>'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe 'input[:file]' do
|
96
|
-
it "should create a simple input[:file] tag" do
|
97
|
-
@f.input(:file).to_s.must_equal '<div class="form-group"><input type="file"/></div>'
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should create an input[:file] tag with a label when ':label => Name'" do
|
101
|
-
@f.input(:file, :label=>"Name").to_s.must_equal '<div class="form-group"><label>Name</label> <input type="file"/></div>'
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should create an input[:file] tag with a label when ':class => bar'" do
|
105
|
-
@f.input(:file, :label=>"Name", :class=>'bar').to_s.must_equal '<div class="form-group"><label>Name</label> <input class="bar" type="file"/></div>'
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should create an input[:file] tag with a label when ':id => bar'" do
|
109
|
-
@f.input(:file, :label=>"Name", :id=>'bar').to_s.must_equal '<div class="form-group"><label for="bar">Name</label> <input id="bar" type="file"/></div>'
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should create an input[:file] tag with a label when ':id => bar' with an error" do
|
113
|
-
@f.input(:file, :label=>"Name", :id=>'bar', :class=>'foo', :error=>'input-file-error').to_s.must_equal '<div class="form-group has-error"><label for="bar">Name</label> <input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="file"/><span class="help-block with-errors">input-file-error</span></div>'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'input[:submit]' do
|
118
|
-
it "should create a simple input[:submit] tag" do
|
119
|
-
@f.input(:submit).to_s.must_equal '<input class="btn btn-default" type="submit"/>'
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should create an input[:submit] tag with the correct value" do
|
123
|
-
@f.input(:submit, :value=>'Save').to_s.must_equal '<input class="btn btn-default" type="submit" value="Save"/>'
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should create an input[:submit] tag with the correct class" do
|
127
|
-
@f.input(:submit, :value=>'Save', :class=>'btn-primary').to_s.must_equal '<input class="btn btn-primary" type="submit" value="Save"/>'
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should create an input[:submit] tag with the correct id" do
|
131
|
-
@f.input(:submit, :value=>'Save', :id=>'foo').to_s.must_equal '<input class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should create an input[:submit] tag without error message " do
|
135
|
-
@f.input(:submit, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input aria-describedby="foo_error_message" aria-invalid="true" class="btn btn-default" id="foo" type="submit" value="Save"/>'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'input[:reset]' do
|
140
|
-
it "should create a simple input[:reset] tag" do
|
141
|
-
@f.input(:reset).to_s.must_equal '<input class="btn btn-default" type="reset"/>'
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should create an input[:reset] tag with the correct value" do
|
145
|
-
@f.input(:reset, :value=>'Save').to_s.must_equal '<input class="btn btn-default" type="reset" value="Save"/>'
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should create an input[:reset] tag with the correct class" do
|
149
|
-
@f.input(:reset, :value=>'Save', :class=>'btn-primary').to_s.must_equal '<input class="btn btn-primary" type="reset" value="Save"/>'
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should create an input[:reset] tag with the correct id" do
|
153
|
-
@f.input(:reset, :value=>'Save', :id=>'foo').to_s.must_equal '<input class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should create an input[:reset] tag without error message " do
|
157
|
-
@f.input(:reset, :value=>'Save', :id=>'foo', :error=>'error-message').to_s.must_equal '<input aria-describedby="foo_error_message" aria-invalid="true" class="btn btn-default" id="foo" type="reset" value="Save"/>'
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe 'textarea' do
|
162
|
-
it "should create a simple :textarea tag" do
|
163
|
-
@f.input(:textarea).to_s.must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should create an :textarea tag with the correct value" do
|
167
|
-
@f.input(:textarea, :value=>'Bio').to_s.must_equal '<div class="form-group"><textarea class="form-control">Bio</textarea></div>'
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should create an :textarea tag with the correct class" do
|
171
|
-
@f.input(:textarea, :class=>'foo').to_s.must_equal '<div class="form-group"><textarea class="form-control foo"></textarea></div>'
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should create an :textarea tag with the correct id" do
|
175
|
-
@f.input(:textarea, :id=>'bar').to_s.must_equal '<div class="form-group"><textarea class="form-control" id="bar"></textarea></div>'
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should create a textarea tag without a .has-error and error message span when ':skip_error => true'" do
|
179
|
-
@f.input(:textarea, :skip_error=>true).to_s.must_equal '<div class="form-group"><textarea class="form-control"></textarea></div>'
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should create a textarea tag with .has-error and error message when ':error => is-a-string'" do
|
183
|
-
@f.input(:textarea, :error=>'input-textarea-error').to_s.must_equal '<div class="form-group has-error"><textarea aria-invalid="true" class="form-control"></textarea><span class="help-block with-errors">input-textarea-error</span></div>'
|
184
|
-
end
|
185
|
-
|
186
|
-
describe 'from a Sequel model' do
|
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" maxlength="255" name="album[name]">c</textarea></div>'
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should correctly handle an input[:text] tag from Sequel model with error" do
|
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 aria-describedby="album_name_error_message" aria-invalid="true" 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
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe 'select' do
|
199
|
-
it "should create a simple :select tag" do
|
200
|
-
@f.input(:select).to_s.must_equal '<div class="form-group"><select class="form-control"></select></div>'
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should create a simple :select tag with options" do
|
204
|
-
@f.input(:select, :options=>[[:a, 1], [:b,2]]).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option value="2">b</option></select></div>'
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should create a simple :select tag with options and the correct value" do
|
208
|
-
@f.input(:select, :options=>[[:a, 1], [:b,2]], :value=>2).to_s.must_equal '<div class="form-group"><select class="form-control"><option value="1">a</option><option selected="selected" value="2">b</option></select></div>'
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should support :add_blank option for select inputs" do
|
212
|
-
@f.input(:select, :options=>[[:a, 1], [:b, 2]], :add_blank=>true, :value=>1).to_s.must_equal '<div class="form-group"><select class="form-control"><option value=""></option><option selected="selected" value="1">a</option><option value="2">b</option></select></div>'
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should create an :select tag with the correct class" do
|
216
|
-
@f.input(:select, :class=>'foo').to_s.must_equal '<div class="form-group"><select class="form-control foo"></select></div>'
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should create an :select tag with the correct id" do
|
220
|
-
@f.input(:select, :id=>'bar').to_s.must_equal '<div class="form-group"><select class="form-control" id="bar"></select></div>'
|
221
|
-
end
|
222
|
-
|
223
|
-
it "should create a select tag without .has-error and error message span when ':skip_error => true'" do
|
224
|
-
@f.input(:select, :skip_error=>true).to_s.must_equal '<div class="form-group"><select class="form-control"></select></div>'
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should create a select tag with .has-error and error message when ':error => is-a-string'" do
|
228
|
-
@f.input(:select, :error=>'input-select-error').to_s.must_equal '<div class="form-group has-error"><select aria-invalid="true" class="form-control"></select><span class="help-block with-errors">input-select-error</span></div>'
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should correctly handle a Sequel model output :as => :select" do
|
232
|
-
@b.input(:artist, :as=>:select).to_s.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>'
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should correctly handle a Sequel model output :as => :select with error" do
|
236
|
-
@ac.errors.add(:artist, 'error message')
|
237
|
-
@c.input(:artist, :as=>:select).to_s.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 value="1">a</option><option selected="selected" value="2">d</option></select><span class="help-block with-errors">error message</span></div>'
|
238
|
-
end
|
239
|
-
|
240
|
-
describe 'from a Sequel model' do
|
241
|
-
it "should correctly handle a boolean attribute from a Sequel model" do
|
242
|
-
@c.input(:gold).to_s.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>'
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should correctly handle a boolean attribute from a Sequel model with an error" do
|
246
|
-
@ac.errors.add(:gold, 'error message')
|
247
|
-
@c.input(:gold).to_s.must_equal '<div class="boolean form-group has-error"><label for="album_gold">Gold</label> <select aria-describedby="album_gold_error_message" aria-invalid="true" 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><span class="help-block with-errors">error message</span></div>'
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
describe 'input[:checkbox]' do
|
253
|
-
it "should create a simple input[:checkbox] tag" do
|
254
|
-
@f.input(:checkbox).to_s.must_equal '<div class="checkbox"><input type="checkbox"/></div>'
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should create an input[:checkbox] tag with a label when ':label => Gold'" do
|
258
|
-
@f.input(:checkbox, :label=>"Gold").to_s.must_equal '<div class="checkbox"><label><input type="checkbox"/> Gold</label></div>'
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should create an input[:checkbox] tag with a label when ':class => bar'" do
|
262
|
-
@f.input(:checkbox, :label=>"Gold", :class=>'bar').to_s.must_equal '<div class="checkbox"><label><input class="bar" type="checkbox"/> Gold</label></div>'
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should create an input[:checkbox] tag with a label when ':id => bar'" do
|
266
|
-
@f.input(:checkbox, :label=>"Gold", :id=>'bar').to_s.must_equal '<div class="checkbox"><label for="bar"><input id="bar" type="checkbox"/> Gold</label></div>'
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should create an input[:checkbox] tag with a label when ':id => bar' with an error" do
|
270
|
-
@f.input(:checkbox, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-checkbox-error').to_s.must_equal '<div class="has-error"><div class="checkbox"><label for="bar"><input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="checkbox"/> Gold</label></div><span class="help-block with-errors">input-checkbox-error</span></div>'
|
271
|
-
end
|
272
|
-
|
273
|
-
describe 'from a Sequel model' do
|
274
|
-
it "should correctly handle a boolean attribute ':as=>:checkbox'" do
|
275
|
-
@c.input(:gold, :as=>:checkbox).to_s.must_equal '<div class="boolean checkbox"><label for="album_gold"><input id="album_gold_hidden" name="album[gold]" type="hidden" value="f"/><input checked="checked" id="album_gold" name="album[gold]" type="checkbox" value="t"/> Gold</label></div>'
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should correctly handle a boolean attribute ':as=>:checkbox' with an error" do
|
279
|
-
@ac.errors.add(:gold, 'error message')
|
280
|
-
@c.input(:gold, :as=>:checkbox).to_s.must_equal '<div class="boolean has-error"><div class="checkbox"><label for="album_gold"><input id="album_gold_hidden" name="album[gold]" type="hidden" value="f"/><input aria-describedby="album_gold_error_message" aria-invalid="true" checked="checked" id="album_gold" name="album[gold]" type="checkbox" value="t"/> Gold</label></div><span class="help-block with-errors">error message</span></div>'
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
|
286
|
-
describe 'input[:radio]' do
|
287
|
-
it "should create a simple input[:radio] tag" do
|
288
|
-
@f.input(:radio).to_s.must_equal '<div class="radio"><input type="radio"/></div>'
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should create an input[:radio] tag with a label when ':label => Gold'" do
|
292
|
-
@f.input(:radio, :label=>"Gold").to_s.must_equal '<div class="radio"><label><input type="radio"/> Gold</label></div>'
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should create an input[:radio] tag with a label when ':class => bar'" do
|
296
|
-
@f.input(:radio, :label=>"Gold", :class=>'bar').to_s.must_equal '<div class="radio"><label><input class="bar" type="radio"/> Gold</label></div>'
|
297
|
-
end
|
298
|
-
|
299
|
-
it "should create an input[:radio] tag with a label when ':id => bar'" do
|
300
|
-
@f.input(:radio, :label=>"Gold", :id=>'bar').to_s.must_equal '<div class="radio"><label for="bar"><input id="bar" type="radio"/> Gold</label></div>'
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should create an input[:radio] tag with a label when ':id => bar' with an error" do
|
304
|
-
@f.input(:radio, :label=>"Gold", :id=>'bar', :class=>'foo', :error=>'input-radio-error').to_s.must_equal '<div class="has-error"><div class="radio"><label for="bar"><input aria-describedby="bar_error_message" aria-invalid="true" class="foo" id="bar" type="radio"/> Gold</label></div><span class="help-block with-errors">input-radio-error</span></div>'
|
305
|
-
end
|
306
|
-
|
307
|
-
describe 'from a Sequel model' do
|
308
|
-
it "should correctly handle a boolean attribute ':as=>:radio'" do
|
309
|
-
@c.input(:gold, :as=>:radio).to_s.must_equal '<div class="boolean radioset"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div></div>'
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should correctly handle a boolean attribute ':as=>:radio' with an error" do
|
313
|
-
@ac.errors.add(:gold, 'error message')
|
314
|
-
@c.input(:gold, :as=>:radio).to_s.must_equal '<div class="boolean radioset has-error"><label>Gold</label><div class="radio"><label class="option" for="album_gold_yes"><input checked="checked" id="album_gold_yes" name="album[gold]" type="radio" value="t"/> Yes</label></div><div class="radio"><label class="option" for="album_gold_no"><input id="album_gold_no" name="album[gold]" type="radio" value="f"/> No</label></div><span class="help-block with-errors">error message</span></div>'
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
|
320
|
-
it "should correctly handle a :checkboxset tag" do
|
321
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]]).to_s.must_equal '<div class="checkboxset"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="2"/> b</label></div></div>'
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should correctly handle a :checkboxset tag without options" do
|
325
|
-
@f.input(:checkboxset, :options=>[]).to_s.must_equal '<div class="checkboxset"></div>'
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should correctly handle a :checkboxset tag with an error - Alternative A: (see BS3 HTML reference)" do
|
329
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message').to_s.must_equal '<div class="checkboxset has-error"><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should correctly handle a :checkboxset tag with an error and label - Alternative A: (see BS3 HTML reference)" do
|
333
|
-
@f.input(:checkboxset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'CheckboxSet').to_s.must_equal '<div class="checkboxset has-error"><label>CheckboxSet</label><div class="checkbox"><label class="option"><input type="checkbox" value="1"/> a</label></div><div class="checkbox"><label class="option"><input type="checkbox" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should correctly handle a :radioset tag" do
|
337
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]]).to_s.must_equal '<div class="radioset"><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input type="radio" value="2"/> b</label></div></div>'
|
338
|
-
end
|
339
|
-
|
340
|
-
it "should correctly handle a :radioset tag without options" do
|
341
|
-
@f.input(:radioset, :options=>[]).to_s.must_equal '<div class="radioset"></div>'
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should correctly handle a :radioset tag with an error - Alternative A: (see BS3 HTML reference)" do
|
345
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message').to_s.must_equal '<div class="radioset has-error"><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input type="radio" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
346
|
-
end
|
347
|
-
|
348
|
-
it "should correctly handle a :radioset tag with an error and label - Alternative A: (see BS3 HTML reference)" do
|
349
|
-
@f.input(:radioset, :options=>[[:a, 1], [:b,2]], :error=>'error message', :label=>'RadioSet').to_s.must_equal '<div class="radioset has-error"><label>RadioSet</label><div class="radio"><label class="option"><input type="radio" value="1"/> a</label></div><div class="radio"><label class="option"><input type="radio" value="2"/> b</label></div><span class="help-block with-errors">error message</span></div>'
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should use a set of radio buttons for many_to_one associations with :as=>:radio option" do
|
353
|
-
@b.input(:artist, :as=>:radio).to_s.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>'
|
354
|
-
@b.input(:artist, :as=>:radio, :wrapper=>nil).to_s.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>'
|
355
|
-
@c.input(:artist, :as=>:radio).to_s.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>'
|
356
|
-
@c.input(:artist, :as=>:radio, :wrapper=>:div).to_s.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>'
|
357
|
-
end
|
358
|
-
end
|