forme 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -1,232 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require_relative 'sequel_helper'
|
3
|
-
|
4
|
-
describe "Sequel forme_set plugin" do
|
5
|
-
before do
|
6
|
-
@ab = Album.new
|
7
|
-
@f = Forme::Form.new(@ab)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#forme_set should only set values in the form" do
|
11
|
-
@ab.forme_set(:name=>'Foo')
|
12
|
-
@ab.name.must_be_nil
|
13
|
-
|
14
|
-
@f.input(:name)
|
15
|
-
@ab.forme_set(:name=>'Foo')
|
16
|
-
@ab.name.must_equal 'Foo'
|
17
|
-
|
18
|
-
@ab.forme_set('copies_sold'=>'1')
|
19
|
-
@ab.name.must_be_nil
|
20
|
-
@ab.copies_sold.must_be_nil
|
21
|
-
|
22
|
-
@f.input(:copies_sold)
|
23
|
-
@ab.forme_set('name'=>'Bar', 'copies_sold'=>'1')
|
24
|
-
@ab.name.must_equal 'Bar'
|
25
|
-
@ab.copies_sold.must_equal 1
|
26
|
-
end
|
27
|
-
|
28
|
-
it "#forme_set should handle different ways to specify parameter names" do
|
29
|
-
[{:attr=>{:name=>'foo'}}, {:attr=>{'name'=>:foo}}, {:name=>'foo'}, {:name=>'foo[]'}, {:name=>'bar[foo][]'}, {:name=>'bar[foo]'}, {:key=>:foo}].each do |opts|
|
30
|
-
@f.input(:name, opts)
|
31
|
-
|
32
|
-
@ab.forme_set(:name=>'Foo')
|
33
|
-
@ab.name.must_be_nil
|
34
|
-
|
35
|
-
@ab.forme_set('foo'=>'Foo')
|
36
|
-
@ab.name.must_equal 'Foo'
|
37
|
-
@ab.forme_inputs.clear
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "#forme_set should ignore values where key is explicitly set to nil" do
|
42
|
-
@f.input(:name, :key=>nil)
|
43
|
-
@ab.forme_set(:name=>'Foo')
|
44
|
-
@ab.name.must_be_nil
|
45
|
-
@ab.forme_set(nil=>'Foo')
|
46
|
-
@ab.name.must_be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it "#forme_set should skip inputs with disabled/readonly formatter set on input" do
|
50
|
-
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
51
|
-
@f.input(:name, :formatter=>formatter)
|
52
|
-
@ab.forme_set(:name=>'Foo')
|
53
|
-
@ab.name.must_be_nil
|
54
|
-
end
|
55
|
-
|
56
|
-
@f.input(:name, :formatter=>:default)
|
57
|
-
@ab.forme_set(:name=>'Foo')
|
58
|
-
@ab.name.must_equal 'Foo'
|
59
|
-
end
|
60
|
-
|
61
|
-
it "#forme_set should skip inputs with disabled/readonly formatter set on Form" do
|
62
|
-
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
63
|
-
@f = Forme::Form.new(@ab, :formatter=>:disabled)
|
64
|
-
@f.input(:name)
|
65
|
-
@ab.forme_set(:name=>'Foo')
|
66
|
-
@ab.name.must_be_nil
|
67
|
-
end
|
68
|
-
|
69
|
-
@f = Forme::Form.new(@ab, :formatter=>:default)
|
70
|
-
@f.input(:name)
|
71
|
-
@ab.forme_set(:name=>'Foo')
|
72
|
-
@ab.name.must_equal 'Foo'
|
73
|
-
end
|
74
|
-
|
75
|
-
it "#forme_set should skip inputs with disabled/readonly formatter set using with_opts" do
|
76
|
-
[:disabled, :readonly, ::Forme::Formatter::Disabled, ::Forme::Formatter::ReadOnly].each do |formatter|
|
77
|
-
@f.with_opts(:formatter=>formatter) do
|
78
|
-
@f.input(:name)
|
79
|
-
end
|
80
|
-
@ab.forme_set(:name=>'Foo')
|
81
|
-
@ab.name.must_be_nil
|
82
|
-
end
|
83
|
-
|
84
|
-
@f.with_opts(:formatter=>:default) do
|
85
|
-
@f.input(:name)
|
86
|
-
end
|
87
|
-
@ab.forme_set(:name=>'Foo')
|
88
|
-
@ab.name.must_equal 'Foo'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "#forme_set should prefer input formatter to with_opts formatter" do
|
92
|
-
@f.with_opts(:formatter=>:default) do
|
93
|
-
@f.input(:name, :formatter=>:readonly)
|
94
|
-
end
|
95
|
-
@ab.forme_set(:name=>'Foo')
|
96
|
-
@ab.name.must_be_nil
|
97
|
-
|
98
|
-
@f.with_opts(:formatter=>:readonly) do
|
99
|
-
@f.input(:name, :formatter=>:default)
|
100
|
-
end
|
101
|
-
@ab.forme_set(:name=>'Foo')
|
102
|
-
@ab.name.must_equal 'Foo'
|
103
|
-
end
|
104
|
-
|
105
|
-
it "#forme_set should prefer with_opts formatter to form formatter" do
|
106
|
-
@f = Forme::Form.new(@ab, :formatter=>:default)
|
107
|
-
@f.with_opts(:formatter=>:readonly) do
|
108
|
-
@f.input(:name)
|
109
|
-
end
|
110
|
-
@ab.forme_set(:name=>'Foo')
|
111
|
-
@ab.name.must_be_nil
|
112
|
-
|
113
|
-
@f = Forme::Form.new(@ab, :formatter=>:readonly)
|
114
|
-
@f.with_opts(:formatter=>:default) do
|
115
|
-
@f.input(:name)
|
116
|
-
end
|
117
|
-
@ab.forme_set(:name=>'Foo')
|
118
|
-
@ab.name.must_equal 'Foo'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "#forme_set should handle setting values for associated objects" do
|
122
|
-
@ab.forme_set(:artist_id=>1)
|
123
|
-
@ab.artist_id.must_be_nil
|
124
|
-
|
125
|
-
@f.input(:artist)
|
126
|
-
@ab.forme_set(:artist_id=>'1')
|
127
|
-
@ab.artist_id.must_equal 1
|
128
|
-
|
129
|
-
@ab.forme_set('tag_pks'=>%w'1 2')
|
130
|
-
@ab.artist_id.must_be_nil
|
131
|
-
@ab.tag_pks.must_equal []
|
132
|
-
|
133
|
-
@f.input(:tags)
|
134
|
-
@ab.forme_set('artist_id'=>'1', 'tag_pks'=>%w'1 2')
|
135
|
-
@ab.artist_id.must_equal 1
|
136
|
-
@ab.tag_pks.must_equal [1, 2]
|
137
|
-
end
|
138
|
-
|
139
|
-
it "#forme_set should handle validations for filtered associations" do
|
140
|
-
[
|
141
|
-
[{:dataset=>proc{|ds| ds.exclude(:id=>1)}},
|
142
|
-
{:dataset=>proc{|ds| ds.exclude(:id=>1)}}],
|
143
|
-
[{:options=>Artist.exclude(:id=>1).select_order_map([:name, :id])},
|
144
|
-
{:options=>Tag.exclude(:id=>1).select_order_map(:id), :name=>'tag_pks[]'}],
|
145
|
-
[{:options=>Artist.exclude(:id=>1).all, :text_method=>:name, :value_method=>:id},
|
146
|
-
{:options=>Tag.exclude(:id=>1).all, :text_method=>:name, :value_method=>:id}],
|
147
|
-
].each do |artist_opts, tag_opts|
|
148
|
-
@ab.forme_inputs.clear
|
149
|
-
@f.input(:artist, artist_opts)
|
150
|
-
@f.input(:tags, tag_opts)
|
151
|
-
|
152
|
-
@ab.forme_validations.clear
|
153
|
-
@ab.forme_set('artist_id'=>'1', 'tag_pks'=>%w'1 2')
|
154
|
-
@ab.artist_id.must_equal 1
|
155
|
-
@ab.tag_pks.must_equal [1, 2]
|
156
|
-
|
157
|
-
@ab.valid?.must_equal false
|
158
|
-
@ab.errors[:artist_id].must_equal ['invalid value submitted']
|
159
|
-
@ab.errors[:tag_pks].must_equal ['invalid value submitted']
|
160
|
-
|
161
|
-
@ab.forme_validations.clear
|
162
|
-
@ab.forme_set('artist_id'=>'1', 'tag_pks'=>['2'])
|
163
|
-
@ab.valid?.must_equal false
|
164
|
-
@ab.errors[:artist_id].must_equal ['invalid value submitted']
|
165
|
-
@ab.errors[:tag_pks].must_be_nil
|
166
|
-
|
167
|
-
@ab.forme_validations.clear
|
168
|
-
@ab.forme_set('artist_id'=>'2', 'tag_pks'=>['2'])
|
169
|
-
@ab.valid?.must_equal true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
it "#forme_set should not require associated values for many_to_one association with select boxes" do
|
174
|
-
@f.input(:artist)
|
175
|
-
@ab.forme_set({})
|
176
|
-
@ab.valid?.must_equal true
|
177
|
-
end
|
178
|
-
|
179
|
-
it "#forme_set should not require associated values for many_to_one association with radio buttons" do
|
180
|
-
@f.input(:artist, :as=>:radio)
|
181
|
-
@ab.forme_set({})
|
182
|
-
@ab.valid?.must_equal true
|
183
|
-
end
|
184
|
-
|
185
|
-
it "#forme_set should require associated values for many_to_one association with select boxes when :required is used" do
|
186
|
-
@f.input(:artist, :required=>true)
|
187
|
-
@ab.forme_set({})
|
188
|
-
@ab.valid?.must_equal false
|
189
|
-
@ab.errors[:artist_id].must_equal ['invalid value submitted']
|
190
|
-
end
|
191
|
-
|
192
|
-
it "#forme_set should require associated values for many_to_one association with radio buttons when :required is used" do
|
193
|
-
@f.input(:artist, :as=>:radio, :required=>true)
|
194
|
-
@ab.forme_set({})
|
195
|
-
@ab.valid?.must_equal false
|
196
|
-
@ab.errors[:artist_id].must_equal ['invalid value submitted']
|
197
|
-
end
|
198
|
-
|
199
|
-
it "#forme_set should handle cases where currently associated values is nil" do
|
200
|
-
@f.input(:tags)
|
201
|
-
@ab.forme_set({:tag_pks=>[1]})
|
202
|
-
def @ab.tag_pks; nil; end
|
203
|
-
@ab.valid?.must_equal true
|
204
|
-
end
|
205
|
-
|
206
|
-
it "#forme_parse should return hash with values and validations" do
|
207
|
-
@f.input(:name)
|
208
|
-
@ab.forme_parse(:name=>'Foo').must_equal(:values=>{:name=>'Foo'}, :validations=>{})
|
209
|
-
|
210
|
-
@f.input(:artist, :dataset=>proc{|ds| ds.exclude(:id=>1)})
|
211
|
-
hash = @ab.forme_parse(:name=>'Foo', 'artist_id'=>'1')
|
212
|
-
hash[:values] = {:name=>'Foo', :artist_id=>'1'}
|
213
|
-
@ab.set(hash[:values])
|
214
|
-
@ab.valid?.must_equal true
|
215
|
-
|
216
|
-
@ab.forme_validations.merge!(hash[:validations])
|
217
|
-
@ab.valid?.must_equal false
|
218
|
-
@ab.errors[:artist_id].must_equal ['invalid value submitted']
|
219
|
-
end
|
220
|
-
|
221
|
-
it "#forme_parse should return hash with values and validations" do
|
222
|
-
@ab.forme_validations[:name] = [:bar, []]
|
223
|
-
proc{@ab.valid?}.must_raise Sequel::Plugins::Forme::Error
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should handle frozen instances as form inputs" do
|
227
|
-
@ab.freeze
|
228
|
-
@ab.forme_inputs.must_equal({})
|
229
|
-
@ab.forme_validations.must_equal({})
|
230
|
-
@f.input(:name).must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text"/></label>'
|
231
|
-
end
|
232
|
-
end
|
data/spec/shared_erb_specs.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
module FormeErbSpecs
|
2
|
-
extend Minitest::Spec::DSL
|
3
|
-
|
4
|
-
before do
|
5
|
-
o = Object.new
|
6
|
-
def o.puts(*) end
|
7
|
-
@rack = {'rack.input'=>'', 'REQUEST_METHOD'=>'GET', 'rack.errors'=>o, 'SCRIPT_NAME'=>''}
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
11
|
-
sin_get('/').must_equal '<form action="/baz"> <p>FBB</p> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="Save"/> </form>'
|
12
|
-
end
|
13
|
-
|
14
|
-
it "#form should have inputs work with a block" do
|
15
|
-
sin_get('/inputs_block').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend> <input id="last" name="last" type="text" value="bar"/> </fieldset></form>'
|
16
|
-
end
|
17
|
-
|
18
|
-
it "#form should have inputs with fieldset_ol wrapper work with block" do
|
19
|
-
sin_get('/inputs_block_wrapper').must_equal '<form action="/baz"><fieldset class="inputs"><legend>FBB</legend><ol> <input id="last" name="last" type="text" value="bar"/> </ol></fieldset></form>'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "#form should add start and end tags and yield Forme::Form instance" do
|
23
|
-
sin_get('/nest').must_equal '<form action="/baz"> <p>FBB</p> <div> <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> </div> </form>'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "#form should correctly handle situation where multiple templates are used with same form object" do
|
27
|
-
sin_get('/nest_sep').sub(/ 4\z/, '4').must_equal '0 <form action="/baz"> 1 <p>FBB</p> 2 n1 <div> n2 <input id="first" name="first" type="text" value="foo"/> <input id="last" name="last" type="text" value="bar"/> n3 </div> n4 <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> n5 3 </form>4'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "#form should correctly handle situation Sequel integration with subforms where multiple templates are used with same form object" do
|
31
|
-
sin_get('/nest_seq_simple').sub(/ 4\z/, '4').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 n1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Artist</legend> n2 <label>Name2: <input id="album_artist_attributes_name2" name="album[artist_attributes][name2]" type="text" value="A2"/></label> n3 </fieldset> n4 3 </form>4'
|
32
|
-
|
33
|
-
sin_get('/nest_seq').sub(/ 4\z/, '4').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Foo</legend><label>Name: <input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></label></fieldset> 2 n1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Artist</legend> n2 <label>Name2: <input id="album_artist_attributes_name2" name="album[artist_attributes][name2]" type="text" value="A2"/></label> n3 </fieldset> n4 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Bar</legend><label>Name3: <input id="album_artist_attributes_name3" name="album[artist_attributes][name3]" type="text" value="A3"/></label></fieldset> n5 3 </form>4'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "#form should correctly handle subform with :grid option with block" do
|
37
|
-
sin_get('/grid-block').sub(/ 4\z/, '4').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td> 2 </tr></tbody></table> 3 <input type="submit" value="Sub"/></form>4'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "#form should correctly handle subform with :grid option without block" do
|
41
|
-
sin_get('/grid-noblock').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "#form should correctly handle subform with :grid option without block" do
|
45
|
-
sin_get('/grid-noblock-multiple').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme artist" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><table><caption>Foo</caption><thead><tr><th>Name</th><th>Copies</th></tr></thead><tbody><tr><td class="string"><input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="N"/></td><td class="integer"><input id="artist_albums_attributes_0_copies_sold" name="artist[albums_attributes][0][copies_sold]" type="number" value="2"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
|
46
|
-
end
|
47
|
-
|
48
|
-
it "#form should accept two hashes instead of requiring obj as first argument" do
|
49
|
-
sin_get('/hash').must_equal '<form action="/baz"> <input id="first" name="first" type="text" value="foo"/> </form>'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "#form should deal with emitted code" do
|
53
|
-
sin_get('/legend').must_equal '<form action="/baz"> <p>FBB</p> <fieldset class="inputs"><legend>Foo</legend><input id="first" name="first" type="text" value="foo"/><input id="last" name="last" type="text" value="bar"/></fieldset> <p>FBB2</p> </form>'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "#form should work with :inputs, :button, and :legend options" do
|
57
|
-
sin_get('/combined').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "#form should work without a block" do
|
61
|
-
sin_get('/noblock').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "#form should work without a block and still have hidden tags emitted" do
|
65
|
-
sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
|
66
|
-
end
|
67
|
-
|
68
|
-
it "#form with an empty form should work" do
|
69
|
-
sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
|
70
|
-
end
|
71
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require_relative 'sequel_helper'
|
3
|
-
require_relative 'erb_helper'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'sinatra/base'
|
7
|
-
require 'rack/csrf'
|
8
|
-
rescue LoadError
|
9
|
-
warn "unable to load sinatra or rack/csrf, skipping sinatra spec"
|
10
|
-
else
|
11
|
-
begin
|
12
|
-
require 'tilt/erubis'
|
13
|
-
rescue LoadError
|
14
|
-
require 'tilt/erb'
|
15
|
-
begin
|
16
|
-
require 'erubis'
|
17
|
-
rescue LoadError
|
18
|
-
require 'erb'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
require_relative '../lib/forme/erb'
|
22
|
-
class FormeSinatraTest < Sinatra::Base
|
23
|
-
helpers(Forme::ERB::Helper)
|
24
|
-
disable :show_exceptions
|
25
|
-
enable :raise_errors
|
26
|
-
enable :sessions
|
27
|
-
use Rack::Csrf
|
28
|
-
|
29
|
-
def self.get(path, &block)
|
30
|
-
super("/#{path}", &block)
|
31
|
-
end
|
32
|
-
|
33
|
-
instance_exec(self, &ERB_BLOCK)
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "Forme Sinatra ERB integration" do
|
37
|
-
def sin_get(path)
|
38
|
-
s = String.new
|
39
|
-
FormeSinatraTest.new.call(@rack.merge('PATH_INFO'=>path))[2].each{|str| s << str}
|
40
|
-
s.gsub(/\s+/, ' ').strip
|
41
|
-
end
|
42
|
-
|
43
|
-
include FormeErbSpecs
|
44
|
-
end
|
45
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
$:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib'))
|
2
|
-
|
3
|
-
if ENV['COVERAGE']
|
4
|
-
require_relative 'forme_coverage'
|
5
|
-
SimpleCov.forme_coverage
|
6
|
-
end
|
7
|
-
|
8
|
-
require_relative '../lib/forme'
|
9
|
-
|
10
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
11
|
-
gem 'minitest'
|
12
|
-
require 'minitest/global_expectations/autorun'
|
13
|
-
|
14
|
-
module Minitest::Spec::DSL
|
15
|
-
def silence_warnings(name, &block)
|
16
|
-
it(name) do
|
17
|
-
silence_warnings do
|
18
|
-
instance_exec(&block)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Minitest::Spec
|
25
|
-
def silence_warnings
|
26
|
-
verbose, $VERBOSE = $VERBOSE, nil
|
27
|
-
yield
|
28
|
-
ensure
|
29
|
-
$VERBOSE = verbose
|
30
|
-
end
|
31
|
-
end
|