strelka 0.6.0 → 0.7.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
- checksums.yaml.gz.sig +0 -0
- data/ChangeLog +156 -9
- data/History.rdoc +15 -0
- data/IDEAS.rdoc +17 -1
- data/MILESTONES.rdoc +1 -1
- data/Manifest.txt +10 -2
- data/Plugins.rdoc +4 -4
- data/README.rdoc +3 -3
- data/Rakefile +5 -4
- data/bin/strelka +19 -10
- data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
- data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
- data/examples/apps/hello-world +1 -0
- data/examples/apps/ws-chat +69 -0
- data/examples/apps/ws-echo +61 -0
- data/examples/gen-config.rb +6 -5
- data/lib/strelka/app/auth.rb +2 -2
- data/lib/strelka/app/errors.rb +1 -1
- data/lib/strelka/app/filters.rb +3 -2
- data/lib/strelka/app/negotiation.rb +2 -2
- data/lib/strelka/app/parameters.rb +1 -2
- data/lib/strelka/app/restresources.rb +3 -2
- data/lib/strelka/app/routing.rb +1 -1
- data/lib/strelka/app/sessions.rb +2 -2
- data/lib/strelka/app/templating.rb +7 -3
- data/lib/strelka/app.rb +5 -145
- data/lib/strelka/behavior/plugin.rb +4 -4
- data/lib/strelka/discovery.rb +211 -0
- data/lib/strelka/httprequest.rb +1 -0
- data/lib/strelka/httpresponse/negotiation.rb +7 -1
- data/lib/strelka/mixins.rb +4 -1
- data/lib/strelka/paramvalidator.rb +1 -1
- data/lib/strelka/plugins.rb +8 -6
- data/lib/strelka/websocketserver/routing.rb +116 -0
- data/lib/strelka/websocketserver.rb +147 -0
- data/lib/strelka.rb +5 -4
- data/spec/{lib/constants.rb → constants.rb} +3 -2
- data/spec/{lib/helpers.rb → helpers.rb} +15 -14
- data/spec/strelka/app/auth_spec.rb +145 -142
- data/spec/strelka/app/errors_spec.rb +20 -26
- data/spec/strelka/app/filters_spec.rb +67 -54
- data/spec/strelka/app/negotiation_spec.rb +8 -14
- data/spec/strelka/app/parameters_spec.rb +23 -29
- data/spec/strelka/app/restresources_spec.rb +98 -100
- data/spec/strelka/app/routing_spec.rb +57 -57
- data/spec/strelka/app/sessions_spec.rb +11 -17
- data/spec/strelka/app/templating_spec.rb +36 -40
- data/spec/strelka/app_spec.rb +48 -147
- data/spec/strelka/authprovider/basic_spec.rb +5 -11
- data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
- data/spec/strelka/authprovider_spec.rb +3 -9
- data/spec/strelka/cookie_spec.rb +32 -38
- data/spec/strelka/cookieset_spec.rb +31 -37
- data/spec/strelka/discovery_spec.rb +144 -0
- data/spec/strelka/exceptions_spec.rb +2 -8
- data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
- data/spec/strelka/httprequest/auth_spec.rb +5 -15
- data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
- data/spec/strelka/httprequest/session_spec.rb +12 -22
- data/spec/strelka/httprequest_spec.rb +1 -7
- data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
- data/spec/strelka/httpresponse/session_spec.rb +25 -35
- data/spec/strelka/httpresponse_spec.rb +20 -26
- data/spec/strelka/mixins_spec.rb +66 -61
- data/spec/strelka/multipartparser_spec.rb +31 -37
- data/spec/strelka/paramvalidator_spec.rb +389 -373
- data/spec/strelka/plugins_spec.rb +17 -23
- data/spec/strelka/router/default_spec.rb +32 -38
- data/spec/strelka/router/exclusive_spec.rb +28 -34
- data/spec/strelka/router_spec.rb +2 -8
- data/spec/strelka/session/db_spec.rb +17 -15
- data/spec/strelka/session/default_spec.rb +22 -28
- data/spec/strelka/session_spec.rb +3 -9
- data/spec/strelka/websocketserver/routing_spec.rb +119 -0
- data/spec/strelka/websocketserver_spec.rb +149 -0
- data/spec/strelka_spec.rb +11 -13
- data.tar.gz.sig +3 -3
- metadata +22 -14
- metadata.gz.sig +0 -0
@@ -1,15 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
4
|
+
require_relative '../helpers'
|
10
5
|
|
11
6
|
require 'rspec'
|
12
|
-
require 'spec/lib/helpers'
|
13
7
|
require 'strelka/httpresponse'
|
14
8
|
|
15
9
|
|
@@ -38,15 +32,15 @@ describe Strelka::HTTPResponse do
|
|
38
32
|
@res.content_type = 'text/html'
|
39
33
|
@res.charset = Encoding::UTF_8
|
40
34
|
|
41
|
-
@res.header_data.
|
35
|
+
expect( @res.header_data ).to match( %r{Content-type: text/html; charset=UTF-8}i )
|
42
36
|
end
|
43
37
|
|
44
38
|
it "replaces the existing content-type header charset if it's text/* and one is explicitly set" do
|
45
39
|
@res.content_type = 'text/html; charset=iso-8859-1'
|
46
40
|
@res.charset = Encoding::UTF_8
|
47
41
|
|
48
|
-
@res.header_data.
|
49
|
-
@res.header_data.
|
42
|
+
expect( @res.header_data ).to match( /charset=UTF-8/i )
|
43
|
+
expect( @res.header_data ).to_not match( /charset=iso-8859-1/ )
|
50
44
|
end
|
51
45
|
|
52
46
|
it "adds a charset to the response's content-type header based on the entity body's encoding " +
|
@@ -54,7 +48,7 @@ describe Strelka::HTTPResponse do
|
|
54
48
|
@res.body = "Стрелке".encode( 'koi8-r' )
|
55
49
|
@res.content_type = 'text/plain'
|
56
50
|
|
57
|
-
@res.header_data.
|
51
|
+
expect( @res.header_data ).to match( /charset=koi8-r/i )
|
58
52
|
end
|
59
53
|
|
60
54
|
it "adds a charset to the response's content-type header based on the entity body's " +
|
@@ -62,15 +56,15 @@ describe Strelka::HTTPResponse do
|
|
62
56
|
@res.body = File.open( __FILE__, 'r:iso-8859-5' )
|
63
57
|
@res.content_type = 'text/plain'
|
64
58
|
|
65
|
-
@res.header_data.
|
59
|
+
expect( @res.header_data ).to match( /charset=iso-8859-5/i )
|
66
60
|
end
|
67
61
|
|
68
62
|
it "doesn't replace a charset in a text/* content-type header with one based on the entity body" do
|
69
63
|
@res.body = "Стрелке".encode( 'iso-8859-5' )
|
70
64
|
@res.content_type = 'text/plain; charset=utf-8'
|
71
65
|
|
72
|
-
@res.header_data.
|
73
|
-
@res.header_data.
|
66
|
+
expect( @res.header_data ).to_not match( /charset=iso-8859-5/i )
|
67
|
+
expect( @res.header_data ).to match( /charset=utf-8/i )
|
74
68
|
end
|
75
69
|
|
76
70
|
it "doesn't add a charset to the response's content-type header if it's explicitly set " +
|
@@ -78,12 +72,12 @@ describe Strelka::HTTPResponse do
|
|
78
72
|
@res.content_type = 'text/plain'
|
79
73
|
@res.charset = Encoding::ASCII_8BIT
|
80
74
|
|
81
|
-
@res.header_data.
|
75
|
+
expect( @res.header_data ).to_not match( /charset/i )
|
82
76
|
end
|
83
77
|
|
84
78
|
it "doesn't add a charset to the response's content-type header if it's not text/*" do
|
85
79
|
@res.content_type = 'application/octet-stream'
|
86
|
-
@res.header_data.
|
80
|
+
expect( @res.header_data ).to_not match( /charset/i )
|
87
81
|
end
|
88
82
|
|
89
83
|
it "strips an existing charset from the response's content-type header if it's explicitly " +
|
@@ -91,51 +85,51 @@ describe Strelka::HTTPResponse do
|
|
91
85
|
@res.content_type = 'text/plain; charset=ISO-8859-15'
|
92
86
|
@res.charset = Encoding::ASCII_8BIT
|
93
87
|
|
94
|
-
@res.header_data.
|
88
|
+
expect( @res.header_data ).to_not match( /charset/i )
|
95
89
|
end
|
96
90
|
|
97
91
|
it "doesn't try to add an encoding to a response that doesn't have a content type" do
|
98
92
|
@res.content_type = nil
|
99
|
-
@res.header_data.
|
93
|
+
expect( @res.header_data ).to_not match( /charset/ )
|
100
94
|
end
|
101
95
|
|
102
96
|
it "adds a Content-encoding header if there is one encoding" do
|
103
97
|
@res.encodings << 'gzip'
|
104
|
-
@res.header_data.
|
98
|
+
expect( @res.header_data ).to match( /content-encoding: gzip\s*$/i )
|
105
99
|
end
|
106
100
|
|
107
101
|
it "adds a Content-encoding header if there is more than one encoding" do
|
108
102
|
@res.encodings << 'gzip' << 'compress'
|
109
|
-
@res.header_data.
|
103
|
+
expect( @res.header_data ).to match( /content-encoding: gzip, compress\s*$/i )
|
110
104
|
end
|
111
105
|
|
112
106
|
|
113
107
|
it "adds a Content-language header if there is one language" do
|
114
108
|
@res.languages << 'de'
|
115
|
-
@res.header_data.
|
109
|
+
expect( @res.header_data ).to match( /content-language: de\s*$/i )
|
116
110
|
end
|
117
111
|
|
118
112
|
it "adds a Content-language header if there is more than one language" do
|
119
113
|
@res.languages << 'en' << 'sv-chef'
|
120
|
-
@res.header_data.
|
114
|
+
expect( @res.header_data ).to match( /content-language: en, sv-chef\s*$/i )
|
121
115
|
end
|
122
116
|
|
123
117
|
|
124
118
|
it "allows cookies to be set via a Hash-like interface" do
|
125
119
|
@res.cookies[:foom] = 'chuckUfarly'
|
126
|
-
@res.header_data.
|
120
|
+
expect( @res.header_data ).to match( /set-cookie: foom=chuckufarly/i )
|
127
121
|
end
|
128
122
|
|
129
123
|
it "allows cookies to be appended" do
|
130
124
|
@res.cookies << Strelka::Cookie.new( 'session', '64a3a92eb7403a8199301e03e8b83810' )
|
131
125
|
@res.cookies << Strelka::Cookie.new( 'cn', '18', :expires => '+1d' )
|
132
|
-
@res.header_data.
|
133
|
-
@res.header_data.
|
126
|
+
expect( @res.header_data ).to match( /set-cookie: session=64a3a92eb7403a8199301e03e8b83810/i )
|
127
|
+
expect( @res.header_data ).to match( /set-cookie: cn=18; expires=/i )
|
134
128
|
end
|
135
129
|
|
136
130
|
|
137
131
|
it "shares a 'notes' Hash with its associated request" do
|
138
|
-
@res.notes.
|
132
|
+
expect( @res.notes ).to be( @req.notes )
|
139
133
|
end
|
140
134
|
|
141
135
|
end
|
data/spec/strelka/mixins_spec.rb
CHANGED
@@ -2,15 +2,10 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../helpers'
|
10
6
|
|
11
7
|
require 'set'
|
12
8
|
require 'rspec'
|
13
|
-
require 'spec/lib/helpers'
|
14
9
|
require 'strelka/mixins'
|
15
10
|
|
16
11
|
|
@@ -92,35 +87,35 @@ describe Strelka, "mixins" do
|
|
92
87
|
end
|
93
88
|
|
94
89
|
before( :each ) do
|
95
|
-
@subobj =
|
90
|
+
@subobj = double( "delegate" )
|
96
91
|
@obj = @testclass.new( @subobj )
|
97
92
|
end
|
98
93
|
|
99
94
|
|
100
95
|
it "can be used to set up delegation through a method" do
|
101
|
-
@subobj.
|
96
|
+
expect( @subobj ).to receive( :delegated_method )
|
102
97
|
@obj.delegated_method
|
103
98
|
end
|
104
99
|
|
105
100
|
it "passes any arguments through to the delegate object's method" do
|
106
|
-
@subobj.
|
101
|
+
expect( @subobj ).to receive( :delegated_method ).with( :arg1, :arg2 )
|
107
102
|
@obj.delegated_method( :arg1, :arg2 )
|
108
103
|
end
|
109
104
|
|
110
105
|
it "allows delegation to the delegate object's method with a block" do
|
111
|
-
@subobj.
|
106
|
+
expect( @subobj ).to receive( :delegated_method ).with( :arg1 ).
|
112
107
|
and_yield( :the_block_argument )
|
113
108
|
blockarg = nil
|
114
109
|
@obj.delegated_method( :arg1 ) {|arg| blockarg = arg }
|
115
|
-
blockarg.
|
110
|
+
expect( blockarg ).to eq( :the_block_argument )
|
116
111
|
end
|
117
112
|
|
118
113
|
it "reports errors from its caller's perspective", :ruby_1_8_only => true do
|
119
114
|
begin
|
120
115
|
@obj.erroring_delegated_method
|
121
116
|
rescue NoMethodError => err
|
122
|
-
err.message.
|
123
|
-
err.backtrace.first.
|
117
|
+
expect( err.message ).to match( /nonexistant_method/ )
|
118
|
+
expect( err.backtrace.first ).to match( /#{__FILE__}/ )
|
124
119
|
rescue ::Exception => err
|
125
120
|
fail "Expected a NoMethodError, but got a %p (%s)" % [ err.class, err.message ]
|
126
121
|
else
|
@@ -146,35 +141,35 @@ describe Strelka, "mixins" do
|
|
146
141
|
end
|
147
142
|
|
148
143
|
before( :each ) do
|
149
|
-
@subobj =
|
144
|
+
@subobj = double( "delegate" )
|
150
145
|
@obj = @testclass.new( @subobj )
|
151
146
|
end
|
152
147
|
|
153
148
|
|
154
149
|
it "can be used to set up delegation through a method" do
|
155
|
-
@subobj.
|
150
|
+
expect( @subobj ).to receive( :delegated_method )
|
156
151
|
@obj.delegated_method
|
157
152
|
end
|
158
153
|
|
159
154
|
it "passes any arguments through to the delegate's method" do
|
160
|
-
@subobj.
|
155
|
+
expect( @subobj ).to receive( :delegated_method ).with( :arg1, :arg2 )
|
161
156
|
@obj.delegated_method( :arg1, :arg2 )
|
162
157
|
end
|
163
158
|
|
164
159
|
it "allows delegation to the delegate's method with a block" do
|
165
|
-
@subobj.
|
160
|
+
expect( @subobj ).to receive( :delegated_method ).with( :arg1 ).
|
166
161
|
and_yield( :the_block_argument )
|
167
162
|
blockarg = nil
|
168
163
|
@obj.delegated_method( :arg1 ) {|arg| blockarg = arg }
|
169
|
-
blockarg.
|
164
|
+
expect( blockarg ).to eq( :the_block_argument )
|
170
165
|
end
|
171
166
|
|
172
167
|
it "reports errors from its caller's perspective", :ruby_1_8_only => true do
|
173
168
|
begin
|
174
169
|
@obj.erroring_delegated_method
|
175
170
|
rescue NoMethodError => err
|
176
|
-
err.message.
|
177
|
-
err.backtrace.first.
|
171
|
+
expect( err.message ).to match( /`erroring_delegated_method' for nil/ )
|
172
|
+
expect( err.backtrace.first ).to match( /#{__FILE__}/ )
|
178
173
|
rescue ::Exception => err
|
179
174
|
fail "Expected a NoMethodError, but got a %p (%s)" % [ err.class, err.message ]
|
180
175
|
else
|
@@ -190,16 +185,26 @@ describe Strelka, "mixins" do
|
|
190
185
|
describe Strelka::DataUtilities do
|
191
186
|
|
192
187
|
it "doesn't try to dup immediate objects" do
|
193
|
-
Strelka::DataUtilities.deep_copy( nil ).
|
194
|
-
Strelka::DataUtilities.deep_copy( 112 ).
|
195
|
-
Strelka::DataUtilities.deep_copy( true ).
|
196
|
-
Strelka::DataUtilities.deep_copy( false ).
|
197
|
-
Strelka::DataUtilities.deep_copy( :a_symbol ).
|
188
|
+
expect( Strelka::DataUtilities.deep_copy( nil ) ).to be( nil )
|
189
|
+
expect( Strelka::DataUtilities.deep_copy( 112 ) ).to be( 112 )
|
190
|
+
expect( Strelka::DataUtilities.deep_copy( true ) ).to be( true )
|
191
|
+
expect( Strelka::DataUtilities.deep_copy( false ) ).to be( false )
|
192
|
+
expect( Strelka::DataUtilities.deep_copy( :a_symbol ) ).to be( :a_symbol )
|
198
193
|
end
|
199
194
|
|
200
195
|
it "doesn't try to dup modules/classes" do
|
201
196
|
klass = Class.new
|
202
|
-
Strelka::DataUtilities.deep_copy( klass ).
|
197
|
+
expect( Strelka::DataUtilities.deep_copy( klass ) ).to be( klass )
|
198
|
+
end
|
199
|
+
|
200
|
+
it "doesn't try to dup IOs" do
|
201
|
+
data = [ $stdin ]
|
202
|
+
expect( Strelka::DataUtilities.deep_copy( data[0] ) ).to be( $stdin )
|
203
|
+
end
|
204
|
+
|
205
|
+
it "doesn't try to dup Tempfiles" do
|
206
|
+
data = Tempfile.new( 'strelka_deepcopy.XXXXX' )
|
207
|
+
expect( Strelka::DataUtilities.deep_copy( data ) ).to be( data )
|
203
208
|
end
|
204
209
|
|
205
210
|
it "makes distinct copies of arrays and their members" do
|
@@ -207,14 +212,14 @@ describe Strelka, "mixins" do
|
|
207
212
|
|
208
213
|
copy = Strelka::DataUtilities.deep_copy( original )
|
209
214
|
|
210
|
-
copy.
|
211
|
-
copy.
|
212
|
-
copy[0].
|
213
|
-
copy[0].
|
214
|
-
copy[1].
|
215
|
-
copy[1].
|
216
|
-
copy[2].
|
217
|
-
copy[2].
|
215
|
+
expect( copy ).to eq( original )
|
216
|
+
expect( copy ).to_not be( original )
|
217
|
+
expect( copy[0] ).to eq( original[0] )
|
218
|
+
expect( copy[0] ).to_not be( original[0] )
|
219
|
+
expect( copy[1] ).to eq( original[1] )
|
220
|
+
expect( copy[1] ).to_not be( original[1] )
|
221
|
+
expect( copy[2] ).to eq( original[2] )
|
222
|
+
expect( copy[2] ).to be( original[2] ) # Immediate
|
218
223
|
end
|
219
224
|
|
220
225
|
it "makes recursive copies of deeply-nested Arrays" do
|
@@ -222,12 +227,12 @@ describe Strelka, "mixins" do
|
|
222
227
|
|
223
228
|
copy = Strelka::DataUtilities.deep_copy( original )
|
224
229
|
|
225
|
-
copy.
|
226
|
-
copy.
|
227
|
-
copy[1].
|
228
|
-
copy[1][2].
|
229
|
-
copy[3].
|
230
|
-
copy[3][1].
|
230
|
+
expect( copy ).to eq( original )
|
231
|
+
expect( copy ).to_not be( original )
|
232
|
+
expect( copy[1] ).to_not be( original[1] )
|
233
|
+
expect( copy[1][2] ).to_not be( original[1][2] )
|
234
|
+
expect( copy[3] ).to_not be( original[3] )
|
235
|
+
expect( copy[3][1] ).to_not be( original[3][1] )
|
231
236
|
end
|
232
237
|
|
233
238
|
it "makes distinct copies of Hashes and their members" do
|
@@ -239,13 +244,13 @@ describe Strelka, "mixins" do
|
|
239
244
|
|
240
245
|
copy = Strelka::DataUtilities.deep_copy( original )
|
241
246
|
|
242
|
-
copy.
|
243
|
-
copy.
|
244
|
-
copy[:a].
|
245
|
-
copy.key( 2 ).
|
246
|
-
copy.key( 2 ).
|
247
|
-
copy[3].
|
248
|
-
copy[3].
|
247
|
+
expect( copy ).to eq( original )
|
248
|
+
expect( copy ).to_not be( original )
|
249
|
+
expect( copy[:a] ).to eq( 1 )
|
250
|
+
expect( copy.key( 2 ) ).to eq( 'b' )
|
251
|
+
expect( copy.key( 2 ) ).to_not be( original.key(2) )
|
252
|
+
expect( copy[3] ).to eq( 'c' )
|
253
|
+
expect( copy[3] ).to_not be( original[3] )
|
249
254
|
end
|
250
255
|
|
251
256
|
it "makes distinct copies of deeply-nested Hashes" do
|
@@ -262,15 +267,15 @@ describe Strelka, "mixins" do
|
|
262
267
|
|
263
268
|
copy = Strelka::DataUtilities.deep_copy( original )
|
264
269
|
|
265
|
-
copy.
|
266
|
-
copy[:a][:b][:c].
|
267
|
-
copy[:a][:b][:c].
|
268
|
-
copy[:a][:b][:e].
|
269
|
-
copy[:a][:b][:e].
|
270
|
-
copy[:a][:g].
|
271
|
-
copy[:a][:g].
|
272
|
-
copy[:i].
|
273
|
-
copy[:i].
|
270
|
+
expect( copy ).to eq( original )
|
271
|
+
expect( copy[:a][:b][:c] ).to eq( 'd' )
|
272
|
+
expect( copy[:a][:b][:c] ).to_not be( original[:a][:b][:c] )
|
273
|
+
expect( copy[:a][:b][:e] ).to eq( 'f' )
|
274
|
+
expect( copy[:a][:b][:e] ).to_not be( original[:a][:b][:e] )
|
275
|
+
expect( copy[:a][:g] ).to eq( 'h' )
|
276
|
+
expect( copy[:a][:g] ).to_not be( original[:a][:g] )
|
277
|
+
expect( copy[:i] ).to eq( 'j' )
|
278
|
+
expect( copy[:i] ).to_not be( original[:i] )
|
274
279
|
end
|
275
280
|
|
276
281
|
it "copies the default proc of copied Hashes" do
|
@@ -278,7 +283,7 @@ describe Strelka, "mixins" do
|
|
278
283
|
|
279
284
|
copy = Strelka::DataUtilities.deep_copy( original )
|
280
285
|
|
281
|
-
copy.default_proc.
|
286
|
+
expect( copy.default_proc ).to eq( original.default_proc )
|
282
287
|
end
|
283
288
|
|
284
289
|
it "preserves taintedness of copied objects" do
|
@@ -287,8 +292,8 @@ describe Strelka, "mixins" do
|
|
287
292
|
|
288
293
|
copy = Strelka::DataUtilities.deep_copy( original )
|
289
294
|
|
290
|
-
copy.
|
291
|
-
copy.
|
295
|
+
expect( copy ).to_not be( original )
|
296
|
+
expect( copy ).to be_tainted()
|
292
297
|
end
|
293
298
|
|
294
299
|
it "preserves frozen-ness of copied objects" do
|
@@ -297,8 +302,8 @@ describe Strelka, "mixins" do
|
|
297
302
|
|
298
303
|
copy = Strelka::DataUtilities.deep_copy( original )
|
299
304
|
|
300
|
-
copy.
|
301
|
-
copy.
|
305
|
+
expect( copy ).to_not be( original )
|
306
|
+
expect( copy ).to be_frozen()
|
302
307
|
end
|
303
308
|
|
304
309
|
end
|
@@ -1,17 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
8
|
-
}
|
4
|
+
require_relative '../helpers'
|
9
5
|
|
10
6
|
require 'date'
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/multipartparser'
|
17
11
|
|
@@ -83,9 +77,9 @@ describe Strelka::MultipartParser do
|
|
83
77
|
|
84
78
|
params = parser.parse
|
85
79
|
|
86
|
-
params.
|
87
|
-
params.keys.
|
88
|
-
params['velour-fog'].
|
80
|
+
expect( params ).to have( 5 ).keys
|
81
|
+
expect( params.keys ).to include( 'x-livejournal-entry' )
|
82
|
+
expect( params['velour-fog'] ).to match( /Sweet, sweet canday/i )
|
89
83
|
end
|
90
84
|
|
91
85
|
|
@@ -96,13 +90,13 @@ describe Strelka::MultipartParser do
|
|
96
90
|
|
97
91
|
file = params['upload']
|
98
92
|
|
99
|
-
file.
|
100
|
-
file.filename.
|
101
|
-
file.content_length.
|
102
|
-
file.content_type.
|
93
|
+
expect( file ).to be_a( Tempfile )
|
94
|
+
expect( file.filename ).to eq( 'testfile.rtf' )
|
95
|
+
expect( file.content_length ).to eq( 480 )
|
96
|
+
expect( file.content_type ).to eq( 'application/rtf' )
|
103
97
|
|
104
98
|
file.open
|
105
|
-
file.read.
|
99
|
+
expect( file.read ).to match( /screaming.+anguish.+sirens/ )
|
106
100
|
end
|
107
101
|
|
108
102
|
it "strips full paths from upload filenames (e.g., from MSIE)" do
|
@@ -112,13 +106,13 @@ describe Strelka::MultipartParser do
|
|
112
106
|
|
113
107
|
file = params['upload']
|
114
108
|
|
115
|
-
file.
|
116
|
-
file.filename.
|
117
|
-
file.content_length.
|
118
|
-
file.content_type.
|
109
|
+
expect( file ).to be_a( Tempfile )
|
110
|
+
expect( file.filename ).to eq( 'testfile.rtf' )
|
111
|
+
expect( file.content_length ).to eq( 480 )
|
112
|
+
expect( file.content_type ).to eq( 'application/rtf' )
|
119
113
|
|
120
114
|
file.open
|
121
|
-
file.read.
|
115
|
+
expect( file.read ).to match( /screaming.+anguish.+sirens/ )
|
122
116
|
end
|
123
117
|
|
124
118
|
it "parses a mix of uploaded files and form data" do
|
@@ -126,23 +120,23 @@ describe Strelka::MultipartParser do
|
|
126
120
|
parser = described_class.new( socket, BOUNDARY )
|
127
121
|
params = parser.parse
|
128
122
|
|
129
|
-
params['pork'].
|
130
|
-
params['pork'].
|
131
|
-
params['pork'].
|
132
|
-
params['pork'].
|
123
|
+
expect( params['pork'] ).to be_an_instance_of( Array )
|
124
|
+
expect( params['pork'] ).to have( 2 ).members
|
125
|
+
expect( params['pork'] ).to include( 'zoot' )
|
126
|
+
expect( params['pork'] ).to include( 'fornk' )
|
133
127
|
|
134
|
-
params['namespace'].
|
135
|
-
params['rating'].
|
128
|
+
expect( params['namespace'] ).to eq( 'testing' )
|
129
|
+
expect( params['rating'] ).to eq( '5' )
|
136
130
|
|
137
131
|
file = params['upload']
|
138
132
|
|
139
|
-
file.
|
140
|
-
file.filename.
|
141
|
-
file.content_length.
|
142
|
-
file.content_type.
|
133
|
+
expect( file ).to be_an_instance_of( Tempfile )
|
134
|
+
expect( file.filename ).to eq( 'testfile.rtf' )
|
135
|
+
expect( file.content_length ).to eq( 480 )
|
136
|
+
expect( file.content_type ).to eq( 'application/rtf' )
|
143
137
|
|
144
138
|
file.open
|
145
|
-
file.read.
|
139
|
+
expect( file.read ).to match( /screaming.+anguish.+sirens/ )
|
146
140
|
end
|
147
141
|
|
148
142
|
|
@@ -155,14 +149,14 @@ describe Strelka::MultipartParser do
|
|
155
149
|
|
156
150
|
file1, file2 = params['thingfish-upload']
|
157
151
|
|
158
|
-
file1.filename.
|
159
|
-
file2.filename.
|
152
|
+
expect( file1.filename ).to eq( 'Photo 3.jpg' )
|
153
|
+
expect( file2.filename ).to eq( 'grass2.jpg' )
|
160
154
|
|
161
|
-
file1.content_type.
|
162
|
-
file2.content_type.
|
155
|
+
expect( file1.content_type ).to eq( 'image/jpeg' )
|
156
|
+
expect( file2.content_type ).to eq( 'image/jpeg' )
|
163
157
|
|
164
|
-
file1.content_length.
|
165
|
-
file2.content_length.
|
158
|
+
expect( file1.content_length ).to eq( 82143 )
|
159
|
+
expect( file2.content_length ).to eq( 439257 )
|
166
160
|
end
|
167
161
|
|
168
162
|
end
|