rack-cache 1.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/cache_test.rb DELETED
@@ -1,38 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/spec_setup"
2
-
3
- def dumb_app(env)
4
- body = block_given? ? [yield] : ['Hi']
5
- [ 200, {'Content-Type' => 'text/plain'}, body ]
6
- end
7
-
8
- describe 'Rack::Cache::new' do
9
- before { @app = method(:dumb_app) }
10
-
11
- it 'takes a backend and returns a middleware component' do
12
- Rack::Cache.new(@app).
13
- should.respond_to :call
14
- end
15
-
16
- it 'takes an options Hash' do
17
- lambda { Rack::Cache.new(@app, {}) }.
18
- should.not.raise(ArgumentError)
19
- end
20
-
21
- it 'sets options provided in the options Hash' do
22
- object = Rack::Cache.new(@app, :foo => 'bar', 'foo.bar' => 'bling')
23
- object.options['foo.bar'].should.equal 'bling'
24
- object.options['rack-cache.foo'].should.equal 'bar'
25
- end
26
-
27
- it 'takes a block; executes it during initialization' do
28
- state, object = 'not invoked', nil
29
- instance =
30
- Rack::Cache.new @app do |cache|
31
- object = cache
32
- state = 'invoked'
33
- cache.should.respond_to :set
34
- end
35
- state.should.equal 'invoked'
36
- object.should.be.same_as instance
37
- end
38
- end
@@ -1,145 +0,0 @@
1
- require "#{File.dirname(__FILE__)}/spec_setup"
2
- require 'rack/cache/cachecontrol'
3
-
4
- describe 'Rack::Cache::CacheControl' do
5
- it 'takes no args and initializes with an empty set of values' do
6
- cache_control = Rack::Cache::CacheControl.new
7
- cache_control.should.be.empty
8
- cache_control.to_s.should.equal ''
9
- end
10
-
11
- it 'takes a String and parses it into a Hash when created' do
12
- cache_control = Rack::Cache::CacheControl.new('max-age=600, foo')
13
- cache_control['max-age'].should.equal '600'
14
- cache_control['foo'].should.be.true
15
- end
16
-
17
- it 'takes a String with a single name=value pair' do
18
- cache_control = Rack::Cache::CacheControl.new('max-age=600')
19
- cache_control['max-age'].should.equal '600'
20
- end
21
-
22
- it 'takes a String with multiple name=value pairs' do
23
- cache_control = Rack::Cache::CacheControl.new('max-age=600, max-stale=300, min-fresh=570')
24
- cache_control['max-age'].should.equal '600'
25
- cache_control['max-stale'].should.equal '300'
26
- cache_control['min-fresh'].should.equal '570'
27
- end
28
-
29
- it 'takes a String with a single flag value' do
30
- cache_control = Rack::Cache::CacheControl.new('no-cache')
31
- cache_control.should.include 'no-cache'
32
- cache_control['no-cache'].should.be.true
33
- end
34
-
35
- it 'takes a String with a bunch of all kinds of stuff' do
36
- cache_control =
37
- Rack::Cache::CacheControl.new('max-age=600,must-revalidate,min-fresh=3000,foo=bar,baz')
38
- cache_control['max-age'].should.equal '600'
39
- cache_control['must-revalidate'].should.be.true
40
- cache_control['min-fresh'].should.equal '3000'
41
- cache_control['foo'].should.equal 'bar'
42
- cache_control['baz'].should.be.true
43
- end
44
-
45
- it 'strips leading and trailing spaces from header value' do
46
- cache_control = Rack::Cache::CacheControl.new(' public, max-age = 600 ')
47
- cache_control.should.include 'public'
48
- cache_control.should.include 'max-age'
49
- cache_control['max-age'].should.equal '600'
50
- end
51
-
52
- it 'strips blank segments' do
53
- cache_control = Rack::Cache::CacheControl.new('max-age=600,,max-stale=300')
54
- cache_control['max-age'].should.equal '600'
55
- cache_control['max-stale'].should.equal '300'
56
- end
57
-
58
- it 'removes all directives with #clear' do
59
- cache_control = Rack::Cache::CacheControl.new('max-age=600, must-revalidate')
60
- cache_control.clear
61
- cache_control.should.be.empty
62
- end
63
-
64
- it 'converts self into header String with #to_s' do
65
- cache_control = Rack::Cache::CacheControl.new
66
- cache_control['public'] = true
67
- cache_control['max-age'] = '600'
68
- cache_control.to_s.split(', ').sort.should.equal ['max-age=600', 'public']
69
- end
70
-
71
- it 'sorts alphabetically with boolean directives before value directives' do
72
- cache_control = Rack::Cache::CacheControl.new('foo=bar, z, x, y, bling=baz, zoom=zib, b, a')
73
- cache_control.to_s.should.equal 'a, b, x, y, z, bling=baz, foo=bar, zoom=zib'
74
- end
75
-
76
- it 'responds to #max_age with an integer when max-age directive present' do
77
- cache_control = Rack::Cache::CacheControl.new('public, max-age=600')
78
- cache_control.max_age.should.equal 600
79
- end
80
-
81
- it 'responds to #max_age with nil when no max-age directive present' do
82
- cache_control = Rack::Cache::CacheControl.new('public')
83
- cache_control.max_age.should.be.nil
84
- end
85
-
86
- it 'responds to #shared_max_age with an integer when s-maxage directive present' do
87
- cache_control = Rack::Cache::CacheControl.new('public, s-maxage=600')
88
- cache_control.shared_max_age.should.equal 600
89
- end
90
-
91
- it 'responds to #shared_max_age with nil when no s-maxage directive present' do
92
- cache_control = Rack::Cache::CacheControl.new('public')
93
- cache_control.shared_max_age.should.be.nil
94
- end
95
-
96
- it 'responds to #public? truthfully when public directive present' do
97
- cache_control = Rack::Cache::CacheControl.new('public')
98
- cache_control.should.be.public
99
- end
100
-
101
- it 'responds to #public? non-truthfully when no public directive present' do
102
- cache_control = Rack::Cache::CacheControl.new('private')
103
- cache_control.should.not.be.public
104
- end
105
-
106
- it 'responds to #private? truthfully when private directive present' do
107
- cache_control = Rack::Cache::CacheControl.new('private')
108
- cache_control.should.be.private
109
- end
110
-
111
- it 'responds to #private? non-truthfully when no private directive present' do
112
- cache_control = Rack::Cache::CacheControl.new('public')
113
- cache_control.should.not.be.private
114
- end
115
-
116
- it 'responds to #no_cache? truthfully when no-cache directive present' do
117
- cache_control = Rack::Cache::CacheControl.new('no-cache')
118
- cache_control.should.be.no_cache
119
- end
120
-
121
- it 'responds to #no_cache? non-truthfully when no no-cache directive present' do
122
- cache_control = Rack::Cache::CacheControl.new('max-age=600')
123
- cache_control.should.not.be.no_cache
124
- end
125
-
126
- it 'responds to #must_revalidate? truthfully when must-revalidate directive present' do
127
- cache_control = Rack::Cache::CacheControl.new('must-revalidate')
128
- cache_control.should.be.must_revalidate
129
- end
130
-
131
- it 'responds to #must_revalidate? non-truthfully when no must-revalidate directive present' do
132
- cache_control = Rack::Cache::CacheControl.new('max-age=600')
133
- cache_control.should.not.be.no_cache
134
- end
135
-
136
- it 'responds to #proxy_revalidate? truthfully when proxy-revalidate directive present' do
137
- cache_control = Rack::Cache::CacheControl.new('proxy-revalidate')
138
- cache_control.should.be.proxy_revalidate
139
- end
140
-
141
- it 'responds to #proxy_revalidate? non-truthfully when no proxy-revalidate directive present' do
142
- cache_control = Rack::Cache::CacheControl.new('max-age=600')
143
- cache_control.should.not.be.no_cache
144
- end
145
- end