Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 6392 Bytes
1 | require "#{File.dirname(__FILE__)}/spec_setup" |
2 | |
3 | describe 'Rack::Cache::Response' do |
4 | before :each do |
5 | @now = Time.httpdate(Time.now.httpdate) |
6 | @one_hour_ago = Time.httpdate((Time.now - (60**2)).httpdate) |
7 | @one_hour_later = Time.httpdate((Time.now + (60**2)).httpdate) |
8 | @res = Rack::Cache::Response.new(200, {'Date' => @now.httpdate}, []) |
9 | end |
10 | |
11 | after :each do |
12 | @now, @res, @one_hour_ago = nil |
13 | end |
14 | |
15 | it 'responds to #to_a with a Rack response tuple' do |
16 | @res.should.respond_to :to_a |
17 | @res.to_a.should.equal [200, {'Date' => @now.httpdate}, []] |
18 | end |
19 | |
20 | describe '#cache_control' do |
21 | it 'handles multiple name=value pairs' do |
22 | @res.headers['Cache-Control'] = 'max-age=600, max-stale=300, min-fresh=570' |
23 | @res.cache_control['max-age'].should.equal '600' |
24 | @res.cache_control['max-stale'].should.equal '300' |
25 | @res.cache_control['min-fresh'].should.equal '570' |
26 | end |
27 | it 'removes the header when given an empty hash' do |
28 | @res.headers['Cache-Control'] = 'max-age=600, must-revalidate' |
29 | @res.cache_control['max-age'].should.equal '600' |
30 | @res.cache_control = {} |
31 | @res.headers.should.not.include 'Cache-Control' |
32 | end |
33 | end |
34 | |
35 | describe '#validateable?' do |
36 | it 'is true when Last-Modified header present' do |
37 | @res = Rack::Cache::Response.new(200, {'Last-Modified' => @one_hour_ago.httpdate}, []) |
38 | @res.should.be.validateable |
39 | end |
40 | it 'is true when ETag header present' do |
41 | @res = Rack::Cache::Response.new(200, {'ETag' => '"12345"'}, []) |
42 | @res.should.be.validateable |
43 | end |
44 | it 'is false when no validator is present' do |
45 | @res = Rack::Cache::Response.new(200, {}, []) |
46 | @res.should.not.be.validateable |
47 | end |
48 | end |
49 | |
50 | describe '#date' do |
51 | it 'uses the Date header if present' do |
52 | @res = Rack::Cache::Response.new(200, {'Date' => @one_hour_ago.httpdate}, []) |
53 | @res.date.should.equal @one_hour_ago |
54 | end |
55 | it 'uses the current time when no Date header present' do |
56 | @res = Rack::Cache::Response.new(200, {}, []) |
57 | @res.date.should.be.close Time.now, 1 |
58 | end |
59 | it 'returns the correct date when the header is modified directly' do |
60 | @res = Rack::Cache::Response.new(200, { 'Date' => @one_hour_ago.httpdate }, []) |
61 | @res.date.should.equal @one_hour_ago |
62 | @res.headers['Date'] = @now.httpdate |
63 | @res.date.should.equal @now |
64 | end |
65 | end |
66 | |
67 | describe '#max_age' do |
68 | it 'uses s-maxage cache control directive when present' do |
69 | @res.headers['Cache-Control'] = 's-maxage=600, max-age=0' |
70 | @res.max_age.should.equal 600 |
71 | end |
72 | it 'falls back to max-age when no s-maxage directive present' do |
73 | @res.headers['Cache-Control'] = 'max-age=600' |
74 | @res.max_age.should.equal 600 |
75 | end |
76 | it 'falls back to Expires when no max-age or s-maxage directive present' do |
77 | @res.headers['Cache-Control'] = 'must-revalidate' |
78 | @res.headers['Expires'] = @one_hour_later.httpdate |
79 | @res.max_age.should.equal 60 ** 2 |
80 | end |
81 | it 'gives a #max_age of nil when no freshness information available' do |
82 | @res.max_age.should.be.nil |
83 | end |
84 | end |
85 | |
86 | describe '#private=' do |
87 | it 'adds the private Cache-Control directive when set true' do |
88 | @res.headers['Cache-Control'] = 'max-age=100' |
89 | @res.private = true |
90 | @res.headers['Cache-Control'].split(', ').sort. |
91 | should.equal ['max-age=100', 'private'] |
92 | end |
93 | it 'removes the public Cache-Control directive' do |
94 | @res.headers['Cache-Control'] = 'public, max-age=100' |
95 | @res.private = true |
96 | @res.headers['Cache-Control'].split(', ').sort. |
97 | should.equal ['max-age=100', 'private'] |
98 | end |
99 | end |
100 | |
101 | describe '#expire!' do |
102 | it 'sets the Age to be equal to the max-age' do |
103 | @res.headers['Cache-Control'] = 'max-age=100' |
104 | @res.expire! |
105 | @res.headers['Age'].should.equal '100' |
106 | end |
107 | it 'sets the Age to be equal to the s-maxage when both max-age and s-maxage present' do |
108 | @res.headers['Cache-Control'] = 'max-age=100, s-maxage=500' |
109 | @res.expire! |
110 | @res.headers['Age'].should.equal '500' |
111 | end |
112 | it 'does nothing when the response is already stale/expired' do |
113 | @res.headers['Cache-Control'] = 'max-age=5, s-maxage=500' |
114 | @res.headers['Age'] = '1000' |
115 | @res.expire! |
116 | @res.headers['Age'].should.equal '1000' |
117 | end |
118 | it 'does nothing when the response does not include freshness information' do |
119 | @res.expire! |
120 | @res.headers.should.not.include 'Age' |
121 | end |
122 | end |
123 | |
124 | describe '#ttl' do |
125 | it 'is nil when no Expires or Cache-Control headers present' do |
126 | @res.ttl.should.be.nil |
127 | end |
128 | it 'uses the Expires header when no max-age is present' do |
129 | @res.headers['Expires'] = (@res.now + (60**2)).httpdate |
130 | @res.ttl.should.be.close(60**2, 1) |
131 | end |
132 | it 'returns negative values when Expires is in part' do |
133 | @res.ttl.should.be.nil |
134 | @res.headers['Expires'] = @one_hour_ago.httpdate |
135 | @res.ttl.should.be < 0 |
136 | end |
137 | it 'uses the Cache-Control max-age value when present' do |
138 | @res.headers['Cache-Control'] = 'max-age=60' |
139 | @res.ttl.should.be.close(60, 1) |
140 | end |
141 | end |
142 | |
143 | describe '#vary' do |
144 | it 'is nil when no Vary header is present' do |
145 | @res.vary.should.be.nil |
146 | end |
147 | it 'returns the literal value of the Vary header' do |
148 | @res.headers['Vary'] = 'Foo Bar Baz' |
149 | @res.vary.should.equal 'Foo Bar Baz' |
150 | end |
151 | it 'can be checked for existence using the #vary? method' do |
152 | @res.should.respond_to :vary? |
153 | @res.should.not.vary |
154 | @res.headers['Vary'] = '*' |
155 | @res.should.vary |
156 | end |
157 | end |
158 | |
159 | describe '#vary_header_names' do |
160 | it 'returns an empty Array when no Vary header is present' do |
161 | @res.vary_header_names.should.be.empty |
162 | end |
163 | it 'parses a single header name value' do |
164 | @res.headers['Vary'] = 'Accept-Language' |
165 | @res.vary_header_names.should.equal ['Accept-Language'] |
166 | end |
167 | it 'parses multiple header name values separated by spaces' do |
168 | @res.headers['Vary'] = 'Accept-Language User-Agent X-Foo' |
169 | @res.vary_header_names.should.equal \ |
170 | ['Accept-Language', 'User-Agent', 'X-Foo'] |
171 | end |
172 | it 'parses multiple header name values separated by commas' do |
173 | @res.headers['Vary'] = 'Accept-Language,User-Agent, X-Foo' |
174 | @res.vary_header_names.should.equal \ |
175 | ['Accept-Language', 'User-Agent', 'X-Foo'] |
176 | end |
177 | end |
178 | end |