strelka 0.0.1.pre129 → 0.0.1.pre148

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/IDEAS.rdoc +26 -32
  2. data/Manifest.txt +27 -12
  3. data/README.rdoc +29 -33
  4. data/Rakefile +2 -1
  5. data/bin/leash +2 -1
  6. data/contrib/hoetemplate/README.rdoc.erb +18 -0
  7. data/contrib/hoetemplate/data/{file_name → project}/apps/file_name_app +0 -0
  8. data/contrib/hoetemplate/data/{file_name → project}/templates/layout.tmpl.erb +0 -0
  9. data/contrib/hoetemplate/data/{file_name → project}/templates/top.tmpl.erb +0 -0
  10. data/examples/config.yml +3 -0
  11. data/examples/gen-config.rb +48 -0
  12. data/examples/sessions-demo.rb +43 -0
  13. data/lib/strelka/app/errors.rb +59 -17
  14. data/lib/strelka/app/filters.rb +3 -1
  15. data/lib/strelka/app/negotiation.rb +5 -3
  16. data/lib/strelka/app/parameters.rb +33 -31
  17. data/lib/strelka/app/plugins.rb +14 -8
  18. data/lib/strelka/app/restresources.rb +3 -1
  19. data/lib/strelka/app/routing.rb +9 -7
  20. data/lib/strelka/app/sessions.rb +175 -0
  21. data/lib/strelka/app/templating.rb +6 -3
  22. data/lib/strelka/app.rb +19 -11
  23. data/lib/strelka/behavior/plugin.rb +4 -2
  24. data/lib/strelka/constants.rb +9 -0
  25. data/lib/strelka/cookie.rb +357 -0
  26. data/lib/strelka/cookieset.rb +117 -0
  27. data/lib/strelka/httprequest/acceptparams.rb +12 -10
  28. data/lib/strelka/httprequest/negotiation.rb +4 -2
  29. data/lib/strelka/httprequest/session.rb +71 -0
  30. data/lib/strelka/httprequest.rb +19 -7
  31. data/lib/strelka/httpresponse/negotiation.rb +17 -15
  32. data/lib/strelka/httpresponse/session.rb +101 -0
  33. data/lib/strelka/httpresponse.rb +26 -4
  34. data/lib/strelka/logging.rb +3 -1
  35. data/lib/strelka/mixins.rb +174 -2
  36. data/lib/strelka/{app/paramvalidator.rb → paramvalidator.rb} +25 -22
  37. data/lib/strelka/{app/defaultrouter.rb → router/default.rb} +6 -4
  38. data/lib/strelka/{app/exclusiverouter.rb → router/exclusive.rb} +6 -4
  39. data/lib/strelka/{app/router.rb → router.rb} +9 -7
  40. data/lib/strelka/session/default.rb +209 -0
  41. data/lib/strelka/session.rb +178 -0
  42. data/lib/strelka.rb +6 -4
  43. data/spec/lib/constants.rb +3 -1
  44. data/spec/lib/helpers.rb +7 -0
  45. data/spec/strelka/app/errors_spec.rb +32 -52
  46. data/spec/strelka/app/filters_spec.rb +3 -1
  47. data/spec/strelka/app/negotiation_spec.rb +3 -1
  48. data/spec/strelka/app/parameters_spec.rb +5 -3
  49. data/spec/strelka/app/plugins_spec.rb +5 -3
  50. data/spec/strelka/app/restresources_spec.rb +3 -1
  51. data/spec/strelka/app/routing_spec.rb +6 -4
  52. data/spec/strelka/app/sessions_spec.rb +109 -0
  53. data/spec/strelka/app/templating_spec.rb +3 -1
  54. data/spec/strelka/app_spec.rb +11 -2
  55. data/spec/strelka/cookie_spec.rb +194 -0
  56. data/spec/strelka/cookieset_spec.rb +159 -0
  57. data/spec/strelka/exceptions_spec.rb +3 -1
  58. data/spec/strelka/httprequest/acceptparams_spec.rb +3 -1
  59. data/spec/strelka/httprequest/negotiation_spec.rb +3 -1
  60. data/spec/strelka/httprequest/session_spec.rb +43 -0
  61. data/spec/strelka/httprequest_spec.rb +28 -1
  62. data/spec/strelka/httpresponse/negotiation_spec.rb +3 -3
  63. data/spec/strelka/httpresponse_spec.rb +13 -0
  64. data/spec/strelka/logging_spec.rb +3 -1
  65. data/spec/strelka/mixins_spec.rb +125 -1
  66. data/spec/strelka/{app/paramvalidator_spec.rb → paramvalidator_spec.rb} +4 -4
  67. data/spec/strelka/{app/defaultrouter_spec.rb → router/default_spec.rb} +6 -4
  68. data/spec/strelka/{app/exclusiverouter_spec.rb → router/exclusive_spec.rb} +6 -4
  69. data/spec/strelka/{app/router_spec.rb → router_spec.rb} +9 -7
  70. data/spec/strelka/session/default_spec.rb +210 -0
  71. data/spec/strelka/session_spec.rb +101 -0
  72. data.tar.gz.sig +1 -1
  73. metadata +64 -47
  74. metadata.gz.sig +0 -0
  75. data/contrib/hoetemplate/.autotest.erb +0 -23
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
6
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
7
+ }
8
+
9
+ require 'rspec'
10
+
11
+ require 'spec/lib/helpers'
12
+
13
+ require 'strelka'
14
+ require 'strelka/app/plugins'
15
+ require 'strelka/app/sessions'
16
+
17
+ require 'strelka/behavior/plugin'
18
+
19
+
20
+ #####################################################################
21
+ ### C O N T E X T S
22
+ #####################################################################
23
+
24
+ describe Strelka::App::Sessions do
25
+
26
+ before( :all ) do
27
+ setup_logging( :fatal )
28
+ @request_factory = Mongrel2::RequestFactory.new( route: '' )
29
+ end
30
+
31
+ after( :all ) do
32
+ reset_logging()
33
+ end
34
+
35
+
36
+ it_should_behave_like( "A Strelka::App Plugin" )
37
+
38
+
39
+ it "has an associated session class" do
40
+ Strelka::App::Sessions.session_class.should be_a( Class )
41
+ Strelka::App::Sessions.session_class.should < Strelka::Session
42
+ end
43
+
44
+ it "is can be configured to use a different session class" do
45
+ # First, hook the anonymous class up to the 'testing' name using the PluginFactory API
46
+ test_session_class = Class.new( Strelka::Session )
47
+ Strelka::Session.derivatives[ 'testing' ] = test_session_class
48
+
49
+ # Now configuring it to use the 'testing' session type should set it to use the
50
+ # anonymous class
51
+ Strelka::App::Sessions.configure( :session_class => 'testing' )
52
+
53
+ Strelka::App::Sessions.session_class.should == test_session_class
54
+ end
55
+
56
+
57
+ describe "an including App" do
58
+
59
+ before( :each ) do
60
+ @app = Class.new( Strelka::App ) do
61
+ Strelka.log.info "Anonymous App class: %p" % [ self ]
62
+ Strelka.log.info "ID constant is: %p" % [ const_defined?(:ID) ? const_get(:ID) : "(not defined)" ]
63
+
64
+ self::ID = 'monkeyshines'
65
+ # Guard against ID leakage
66
+ unless const_defined?( :ID, false )
67
+ raise ScriptError, "Awwww, damn. Apparently ID got defined in a parent class?"
68
+ end
69
+ plugin :sessions
70
+
71
+ def initialize( appid='params-test', sspec=TEST_SEND_SPEC, rspec=TEST_RECV_SPEC )
72
+ super
73
+ end
74
+
75
+ def handle( req )
76
+ req.session[ :test ] = 'session data'
77
+ return req.response
78
+ end
79
+ end
80
+ end
81
+
82
+ after( :each ) do
83
+ @app = nil
84
+
85
+ # Guard against ID leaking up into the base class
86
+ if Strelka::App.const_defined?( :ID )
87
+ raise ScriptError, "Awww crap. Somehow ID got defined in Strelka::App"
88
+ end
89
+ end
90
+
91
+
92
+ it "has a default session key that's the same as its appid" do
93
+ @app.session_namespace.should == @app.default_appid
94
+ end
95
+
96
+ it "can set its session namespace to something else" do
97
+ @app.class_eval do
98
+ session_namespace :findizzle
99
+ end
100
+
101
+ @app.session_namespace.should == :findizzle
102
+ end
103
+
104
+
105
+ end
106
+
107
+
108
+ end
109
+
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -29,7 +31,8 @@ describe Strelka::App do
29
31
  Mongrel2::Config.init_database
30
32
 
31
33
  # Skip loading the 'strelka' gem, which probably doesn't exist in the right version
32
- strelkaspec = make_gemspec( 'strelka', '0.0.1', false )
34
+ # in the dev environment
35
+ strelkaspec = make_gemspec( 'strelka', Strelka::VERSION, false )
33
36
  loaded_specs = Gem.instance_variable_get( :@loaded_specs )
34
37
  loaded_specs['strelka'] = strelkaspec
35
38
 
@@ -97,6 +100,8 @@ describe Strelka::App do
97
100
  rabbit_path = specs[:rabbit_new].full_gem_path
98
101
  giraffe_path = specs[:giraffe].full_gem_path
99
102
 
103
+ Dir.should_receive( :glob ).with( Pathname('data/strelka/{apps,handlers}/**/*') ).
104
+ and_return( [] )
100
105
  Dir.should_receive( :glob ).with( "#{giraffe_path}/data/giraffe/{apps,handlers}/**/*" ).
101
106
  and_return([ "#{giraffe_path}/data/giraffe/apps/app" ])
102
107
  Dir.should_receive( :glob ).with( "#{rabbit_path}/data/rabbit/{apps,handlers}/**/*" ).
@@ -120,6 +125,8 @@ describe Strelka::App do
120
125
  gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
121
126
  Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
122
127
 
128
+ Dir.should_receive( :glob ).with( Pathname('data/strelka/{apps,handlers}/**/*') ).
129
+ and_return( [] )
123
130
  Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
124
131
  and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
125
132
 
@@ -140,6 +147,8 @@ describe Strelka::App do
140
147
  gemspec = make_gemspec( 'blood-orgy', '0.0.3' )
141
148
  Gem::Specification.should_receive( :each ).and_yield( gemspec ).at_least( :once )
142
149
 
150
+ Dir.should_receive( :glob ).with( Pathname('data/strelka/{apps,handlers}/**/*') ).
151
+ and_return( [] )
143
152
  Dir.should_receive( :glob ).with( "#{gemspec.full_gem_path}/data/blood-orgy/{apps,handlers}/**/*" ).
144
153
  and_return([ "#{gemspec.full_gem_path}/data/blood-orgy/apps/kurzweil" ])
145
154
 
@@ -0,0 +1,194 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
4
+
5
+ BEGIN {
6
+ require 'pathname'
7
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ }
11
+
12
+ require 'uri'
13
+ require 'rspec'
14
+ require 'spec/lib/helpers'
15
+ require 'strelka/cookie'
16
+
17
+
18
+ #####################################################################
19
+ ### C O N T E X T S
20
+ #####################################################################
21
+
22
+ describe Strelka::Cookie do
23
+
24
+ before( :all ) do
25
+ setup_logging( :fatal )
26
+ end
27
+
28
+ after( :all ) do
29
+ reset_logging()
30
+ end
31
+
32
+ it "parses a 'nil' Cookie header field as an empty Hash" do
33
+ Strelka::Cookie.parse( nil ).should == {}
34
+ end
35
+
36
+ it "parses an empty string Cookie header field as an empty Hash" do
37
+ Strelka::Cookie.parse( '' ).should == {}
38
+ end
39
+
40
+ it "parses a cookie header field with a single value as a cookie with a single value" do
41
+ result = Strelka::Cookie.parse( 'a=b' )
42
+
43
+ result.should be_a( Hash )
44
+ result.should have(1).member
45
+ result['a'].should be_a( Strelka::Cookie )
46
+ result['a'].name.should == 'a'
47
+ result['a'].value.should == 'b'
48
+ result['a'].values.should == ['b']
49
+ end
50
+
51
+ it "parses a cookie header field with a cookie with multiple values as a cookie with multiple values" do
52
+ result = Strelka::Cookie.parse( 'a=b&c' )
53
+
54
+ result.should be_a( Hash )
55
+ result.should have(1).member
56
+ result['a'].should be_a( Strelka::Cookie )
57
+ result['a'].name.should == 'a'
58
+ result['a'].value.should == 'b'
59
+ result['a'].values.should == ['b', 'c']
60
+ end
61
+
62
+ it "parses a cookie header field with multiple cookies and multiple values correctly" do
63
+ result = Strelka::Cookie.parse( 'a=b&c; f=o&o' )
64
+
65
+ result.should be_a( Hash )
66
+ result.should have(2).members
67
+
68
+ result['a'].should be_a( Strelka::Cookie )
69
+ result['a'].name.should == 'a'
70
+ result['a'].value.should == 'b'
71
+ result['a'].values.should == ['b', 'c']
72
+
73
+ result['f'].should be_a( Strelka::Cookie )
74
+ result['f'].name.should == 'f'
75
+ result['f'].value.should == 'o'
76
+ result['f'].values.should == ['o', 'o']
77
+ end
78
+
79
+ it "parses a cookie header field with an empty value as a cookie with a nil value" do
80
+ result = Strelka::Cookie.parse( 'a=' )
81
+
82
+ result.should have( 1 ).member
83
+ result['a'].should be_a( Strelka::Cookie )
84
+ result['a'].name.should == 'a'
85
+ result['a'].value.should be_nil()
86
+ result['a'].values.should == []
87
+ end
88
+
89
+ it "parses a cookie header field with a version as a cookie with a version" do
90
+ result = Strelka::Cookie.parse( %{$Version=1; a="b"} )
91
+
92
+ result.should be_a( Hash )
93
+ result.should have( 1 ).member
94
+
95
+ result['a'].should be_a( Strelka::Cookie )
96
+ result['a'].name.should == 'a'
97
+ result['a'].value.should == 'b'
98
+ result['a'].values.should == ['b']
99
+ result['a'].version.should == 1
100
+ end
101
+
102
+ it "parses a cookie header field with a path as a cookie with a path" do
103
+ result = Strelka::Cookie.parse( %{a=b; $Path=/Strelka} )
104
+
105
+ result.should be_a( Hash )
106
+ result.should have( 1 ).member
107
+
108
+ result['a'].should be_a( Strelka::Cookie )
109
+ result['a'].name.should == 'a'
110
+ result['a'].value.should == 'b'
111
+ result['a'].values.should == ['b']
112
+
113
+ result['a'].path.should == "/Strelka"
114
+ end
115
+
116
+ it "parses a cookie header field with a domain as a cookie with a domain" do
117
+ result = Strelka::Cookie.parse( %{a=b; $domain=rubycrafters.com} )
118
+
119
+ result.should be_a( Hash )
120
+ result.should have( 1 ).member
121
+
122
+ result['a'].should be_a( Strelka::Cookie )
123
+ result['a'].name.should == 'a'
124
+ result['a'].value.should == 'b'
125
+ result['a'].values.should == ['b']
126
+
127
+ result['a'].domain.should == '.rubycrafters.com'
128
+ end
129
+
130
+ it "doesn't raise an error if asked to parse an invalid cookie header" do
131
+ result = Strelka::Cookie.parse( "{a}=foo" )
132
+ result.should == {}
133
+ end
134
+
135
+
136
+ context "instance" do
137
+
138
+ before( :each ) do
139
+ @cookie = Strelka::Cookie.new( :by_rickirac, '9917eb' )
140
+ end
141
+
142
+ it "stringifies as a valid header value" do
143
+ @cookie.to_s.should == 'by_rickirac=9917eb'
144
+ end
145
+
146
+ it "still stringifies correctly with two values" do
147
+ @cookie.values += ['brer lapin']
148
+ @cookie.to_s.should == "by_rickirac=9917eb&brer+lapin"
149
+ end
150
+
151
+ it "stringifies with a version number if its version is set to something other than 0" do
152
+ @cookie.version = 1
153
+ @cookie.to_s.should == %{by_rickirac=9917eb; Version=1}
154
+ end
155
+
156
+ it "stringifies with a domain if one is set" do
157
+ @cookie.domain = '.example.com'
158
+ @cookie.to_s.should == %{by_rickirac=9917eb; Domain=.example.com}
159
+ end
160
+
161
+ it "stringifies with a dot prepended to the domain if the set doesn't have one" do
162
+ @cookie.domain = 'example.com'
163
+ @cookie.to_s.should == %{by_rickirac=9917eb; Domain=.example.com}
164
+ end
165
+
166
+ it "stringifies correctly even if one of its values contains a semicolon" do
167
+ @cookie.values += [%{"modern technology"; ain't it a paradox?}]
168
+ @cookie.to_s.should ==
169
+ "by_rickirac=9917eb&%22modern+technology%22%3B+ain%27t+it+a+paradox%3F"
170
+ end
171
+
172
+ it "stringifies with an expires date if one is set" do
173
+ @cookie.expires = Time.at( 1331761184 )
174
+ @cookie.to_s.should == 'by_rickirac=9917eb; Expires=Wed, 14-Mar-2012 21:39:44 GMT'
175
+ end
176
+
177
+ it "hashes the same as another cookie with the same name, regardless of value" do
178
+ @cookie.hash.should == Strelka::Cookie.new('by_rickirac', 'something_else').hash
179
+ end
180
+
181
+
182
+ it "sets its expiration time to a time in the past if it's told to expire" do
183
+ @cookie.expire!
184
+ @cookie.expires.should < Time.now
185
+ end
186
+
187
+ it "uses the hash of its name as its hash value" do
188
+ @cookie.hash.should == @cookie.name.to_s.hash
189
+ end
190
+ end
191
+
192
+
193
+ end
194
+
@@ -0,0 +1,159 @@
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
4
+
5
+ BEGIN {
6
+ require 'pathname'
7
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
8
+
9
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
+ }
11
+
12
+ require 'uri'
13
+ require 'rspec'
14
+ require 'spec/lib/helpers'
15
+ require 'strelka/cookie'
16
+ require 'strelka/cookieset'
17
+
18
+
19
+ #####################################################################
20
+ ### C O N T E X T S
21
+ #####################################################################
22
+
23
+ describe Strelka::CookieSet do
24
+
25
+ before( :each ) do
26
+ @cookieset = Strelka::CookieSet.new
27
+ end
28
+
29
+
30
+ it "is able to enummerate over each cookie in the set" do
31
+ pants_cookie = Strelka::Cookie.new( 'pants', 'baggy' )
32
+ shirt_cookie = Strelka::Cookie.new( 'shirt', 'pirate' )
33
+ @cookieset << shirt_cookie << pants_cookie
34
+
35
+ cookies = []
36
+ @cookieset.each do |cookie|
37
+ cookies << cookie
38
+ end
39
+
40
+ cookies.length.should == 2
41
+ cookies.should include( pants_cookie )
42
+ cookies.should include( shirt_cookie )
43
+ end
44
+
45
+ it "is able to add a cookie referenced symbolically" do
46
+ pants_cookie = Strelka::Cookie.new( 'pants', 'denim' )
47
+ @cookieset[:pants] = pants_cookie
48
+ @cookieset['pants'].should == pants_cookie
49
+ end
50
+
51
+
52
+ it "autos-create a cookie for a non-cookie passed to the index setter" do
53
+ lambda { @cookieset['bar'] = 'badgerbadgerbadgerbadger' }.should_not raise_error()
54
+
55
+ @cookieset['bar'].should be_an_instance_of( Strelka::Cookie )
56
+ @cookieset['bar'].value.should == 'badgerbadgerbadgerbadger'
57
+ end
58
+
59
+ it "raises an exception if the name of a cookie being set doesn't agree with the key it being set with" do
60
+ pants_cookie = Strelka::Cookie.new( 'pants', 'corduroy' )
61
+ lambda { @cookieset['shirt'] = pants_cookie }.should raise_error( ArgumentError )
62
+ end
63
+
64
+ it "implements Enumerable" do
65
+ Enumerable.instance_methods( false ).each do |meth|
66
+ @cookieset.should respond_to( meth )
67
+ end
68
+ end
69
+
70
+ it "is able to set a cookie's value symbolically to something other than a String" do
71
+ @cookieset[:wof] = Digest::MD5.hexdigest( Time.now.to_s )
72
+ end
73
+
74
+ it "is able to set a cookie with a Symbol key" do
75
+ @cookieset[:wof] = Strelka::Cookie.new( :wof, "something" )
76
+ end
77
+
78
+
79
+ describe "created with an Array of cookies" do
80
+ it "should flatten the array" do
81
+ cookie_array = []
82
+ cookie_array << Strelka::Cookie.new( 'foo', 'bar' )
83
+ cookie_array << [Strelka::Cookie.new( 'shmoop', 'torgo!' )]
84
+
85
+ cookieset = nil
86
+ lambda {cookieset = Strelka::CookieSet.new(cookie_array)}.should_not raise_error()
87
+ cookieset.length.should == 2
88
+ end
89
+ end
90
+
91
+
92
+ describe "with a 'foo' cookie" do
93
+ before(:each) do
94
+ @cookie = Strelka::Cookie.new( 'foo', 'bar' )
95
+ @cookieset = Strelka::CookieSet.new( @cookie )
96
+ end
97
+
98
+ it "contains only one cookie" do
99
+ @cookieset.length.should == 1
100
+ end
101
+
102
+ it "is able to return the 'foo' Strelka::Cookie via its index operator" do
103
+ @cookieset[ 'foo' ].should == @cookie
104
+ end
105
+
106
+
107
+ it "is able to return the 'foo' Strelka::Cookie via its symbolic name" do
108
+ @cookieset[ :foo ].should == @cookie
109
+ end
110
+
111
+ it "knows if it includes a cookie named 'foo'" do
112
+ @cookieset.should include( 'foo' )
113
+ end
114
+
115
+ it "knows if it includes a cookie referenced by :foo" do
116
+ @cookieset.should include( :foo )
117
+ end
118
+
119
+ it "knows that it doesn't contain a cookie named 'lollypop'" do
120
+ @cookieset.should_not include( 'lollypop' )
121
+ end
122
+
123
+ it "knows that it includes the 'foo' cookie object" do
124
+ @cookieset.should include( @cookie )
125
+ end
126
+
127
+
128
+ it "adds a cookie to the set if it has a different name" do
129
+ new_cookie = Strelka::Cookie.new( 'bar', 'foo' )
130
+ @cookieset << new_cookie
131
+
132
+ @cookieset.length.should == 2
133
+ @cookieset.should include( new_cookie )
134
+ end
135
+
136
+
137
+ it "replaces any existing same-named cookie added via appending" do
138
+ new_cookie = Strelka::Cookie.new( 'foo', 'giant scallops of doom' )
139
+ @cookieset << new_cookie
140
+
141
+ @cookieset.length.should == 1
142
+ @cookieset.should include( new_cookie )
143
+ @cookieset['foo'].should equal( new_cookie )
144
+ end
145
+
146
+ it "replaces any existing same-named cookie set via the index operator" do
147
+ new_cookie = Strelka::Cookie.new( 'foo', 'giant scallops of doom' )
148
+ @cookieset[:foo] = new_cookie
149
+
150
+ @cookieset.length.should == 1
151
+ @cookieset.should include( new_cookie )
152
+ @cookieset['foo'].should equal( new_cookie )
153
+ end
154
+
155
+ end
156
+
157
+ end
158
+
159
+ # vim: set nosta noet ts=4 sw=4:
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -0,0 +1,43 @@
1
+ # -*- rspec -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+
4
+ BEGIN {
5
+ require 'pathname'
6
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
7
+
8
+ libdir = basedir + "lib"
9
+
10
+ $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
11
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
12
+ }
13
+
14
+ require 'rspec'
15
+
16
+ require 'spec/lib/helpers'
17
+
18
+ require 'strelka'
19
+ require 'strelka/httprequest/session'
20
+
21
+
22
+ #####################################################################
23
+ ### C O N T E X T S
24
+ #####################################################################
25
+
26
+ describe Strelka::HTTPRequest::Session do
27
+
28
+ before( :all ) do
29
+ setup_logging( :fatal )
30
+ @request_factory = Mongrel2::RequestFactory.new( route: '/service/user' )
31
+ end
32
+
33
+ after( :all ) do
34
+ reset_logging()
35
+ end
36
+
37
+ before( :each ) do
38
+ @req = @request_factory.get( '/service/user/estark' )
39
+ @req.extend( described_class )
40
+ end
41
+
42
+
43
+ end
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'
@@ -11,6 +13,7 @@ require 'uri'
11
13
  require 'rspec'
12
14
  require 'spec/lib/helpers'
13
15
  require 'strelka/httprequest'
16
+ require 'strelka/cookie'
14
17
 
15
18
 
16
19
  #####################################################################
@@ -240,5 +243,29 @@ describe Strelka::HTTPRequest do
240
243
 
241
244
  end
242
245
 
246
+
247
+ describe "cookie support" do
248
+
249
+ before( :each ) do
250
+ @req = @request_factory.get( '/directory/userinfo/ged' )
251
+ end
252
+
253
+
254
+ it "parses a single cookie into a cookieset with the cookie in it" do
255
+ @req.header.cookie = 'foom=chuckUfarly'
256
+ @req.cookies.should have( 1 ).member
257
+ @req.cookies['foom'].value.should == 'chuckUfarly'
258
+ end
259
+
260
+ it "parses multiple cookies into a cookieset with multiple cookies in it" do
261
+ @req.header.cookie = 'foom=chuckUfarly; glarn=hotchinfalcheck'
262
+
263
+ @req.cookies.should have( 2 ).members
264
+ @req.cookies['foom'].value.should == 'chuckUfarly'
265
+ @req.cookies['glarn'].value.should == 'hotchinfalcheck'
266
+ end
267
+
268
+ end
269
+
243
270
  end
244
271
 
@@ -433,7 +433,7 @@ describe Strelka::HTTPResponse::Negotiation do
433
433
  @res.should_not have_acceptable_encoding()
434
434
  end
435
435
 
436
- it "knows that it is not acceptable if it doesn't have any explicit content codings " +
436
+ it "knows that it is not acceptable if it doesn't have any explicit content codings " +
437
437
  "and 'identity' is explicitly not accepted in its originating request" do
438
438
  @req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
439
439
  @res.encodings.clear
@@ -441,7 +441,7 @@ describe Strelka::HTTPResponse::Negotiation do
441
441
  @res.should_not have_acceptable_encoding()
442
442
  end
443
443
 
444
- it "knows that it is not acceptable if it doesn't have any explicit content codings " +
444
+ it "knows that it is not acceptable if it doesn't have any explicit content codings " +
445
445
  "and 'identity' is explicitly not accepted in its originating request" do
446
446
  @req.headers.accept_encoding = 'gzip;q=1.0, identity; q=0'
447
447
  @res.encodings.clear
@@ -449,7 +449,7 @@ describe Strelka::HTTPResponse::Negotiation do
449
449
  @res.should_not have_acceptable_encoding()
450
450
  end
451
451
 
452
- it "knows that it is not acceptable if it doesn't have any explicit content codings, " +
452
+ it "knows that it is not acceptable if it doesn't have any explicit content codings, " +
453
453
  "the wildcard content-coding is disallowed, and 'identity' is not explicitly accepted" do
454
454
  @req.headers.accept_encoding = 'gzip;q=1.0, *;q=0'
455
455
  @res.encodings.clear
@@ -110,5 +110,18 @@ describe Strelka::HTTPResponse do
110
110
  @res.header_data.should =~ /content-language: en, sv-chef\s*$/i
111
111
  end
112
112
 
113
+
114
+ it "allows cookies to be set via a Hash-like interface" do
115
+ @res.cookies[:foom] = 'chuckUfarly'
116
+ @res.header_data.should =~ /set-cookie: foom=chuckufarly/i
117
+ end
118
+
119
+ it "allows cookies to appended" do
120
+ @res.cookies << Strelka::Cookie.new( 'session', '64a3a92eb7403a8199301e03e8b83810' )
121
+ @res.cookies << Strelka::Cookie.new( 'cn', '18', :expires => '+1d' )
122
+ @res.header_data.should =~ /set-cookie: session=64a3a92eb7403a8199301e03e8b83810/i
123
+ @res.header_data.should =~ /set-cookie: cn=18; expires=/i
124
+ end
125
+
113
126
  end
114
127
 
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
+ # vim: set nosta noet ts=4 sw=4:
3
+ # encoding: utf-8
2
4
 
3
5
  BEGIN {
4
6
  require 'pathname'