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:
- 5652 Bytes
1 | # coding: utf-8 |
2 | require "#{File.dirname(__FILE__)}/spec_setup" |
3 | require 'rack/cache/entitystore' |
4 | |
5 | class Object |
6 | def sha_like? |
7 | length == 40 && self =~ /^[0-9a-z]+$/ |
8 | end |
9 | end |
10 | |
11 | describe_shared 'A Rack::Cache::EntityStore Implementation' do |
12 | |
13 | it 'responds to all required messages' do |
14 | %w[read open write exist?].each do |message| |
15 | @store.should.respond_to message |
16 | end |
17 | end |
18 | |
19 | it 'stores bodies with #write' do |
20 | key, size = @store.write(['My wild love went riding,']) |
21 | key.should.not.be.nil |
22 | key.should.be.sha_like |
23 | |
24 | data = @store.read(key) |
25 | data.should.equal 'My wild love went riding,' |
26 | end |
27 | |
28 | it 'correctly determines whether cached body exists for key with #exist?' do |
29 | key, size = @store.write(['She rode to the devil,']) |
30 | @store.should.exist key |
31 | @store.should.not.exist '938jasddj83jasdh4438021ksdfjsdfjsdsf' |
32 | end |
33 | |
34 | it 'can read data written with #write' do |
35 | key, size = @store.write(['And asked him to pay.']) |
36 | data = @store.read(key) |
37 | data.should.equal 'And asked him to pay.' |
38 | end |
39 | |
40 | it 'gives a 40 character SHA1 hex digest from #write' do |
41 | key, size = @store.write(['she rode to the sea;']) |
42 | key.should.not.be.nil |
43 | key.length.should.equal 40 |
44 | key.should.be =~ /^[0-9a-z]+$/ |
45 | key.should.equal '90a4c84d51a277f3dafc34693ca264531b9f51b6' |
46 | end |
47 | |
48 | it 'returns the entire body as a String from #read' do |
49 | key, size = @store.write(['She gathered together']) |
50 | @store.read(key).should.equal 'She gathered together' |
51 | end |
52 | |
53 | it 'returns nil from #read when key does not exist' do |
54 | @store.read('87fe0a1ae82a518592f6b12b0183e950b4541c62').should.be.nil |
55 | end |
56 | |
57 | it 'returns a Rack compatible body from #open' do |
58 | key, size = @store.write(['Some shells for her hair.']) |
59 | body = @store.open(key) |
60 | body.should.respond_to :each |
61 | buf = '' |
62 | body.each { |part| buf << part } |
63 | buf.should.equal 'Some shells for her hair.' |
64 | end |
65 | |
66 | it 'returns nil from #open when key does not exist' do |
67 | @store.open('87fe0a1ae82a518592f6b12b0183e950b4541c62').should.be.nil |
68 | end |
69 | |
70 | it 'can store largish bodies with binary data' do |
71 | pony = File.open(File.dirname(__FILE__) + '/pony.jpg', 'rb') { |f| f.read } |
72 | key, size = @store.write([pony]) |
73 | key.should.equal 'd0f30d8659b4d268c5c64385d9790024c2d78deb' |
74 | data = @store.read(key) |
75 | data.length.should.equal pony.length |
76 | data.hash.should.equal pony.hash |
77 | end |
78 | |
79 | it 'deletes stored entries with #purge' do |
80 | key, size = @store.write(['My wild love went riding,']) |
81 | @store.purge(key).should.be.nil |
82 | @store.read(key).should.be.nil |
83 | end |
84 | end |
85 | |
86 | describe 'Rack::Cache::EntityStore' do |
87 | |
88 | describe 'Heap' do |
89 | it_should_behave_like 'A Rack::Cache::EntityStore Implementation' |
90 | before { @store = Rack::Cache::EntityStore::Heap.new } |
91 | it 'takes a Hash to ::new' do |
92 | @store = Rack::Cache::EntityStore::Heap.new('foo' => ['bar']) |
93 | @store.read('foo').should.equal 'bar' |
94 | end |
95 | it 'uses its own Hash with no args to ::new' do |
96 | @store.read('foo').should.be.nil |
97 | end |
98 | end |
99 | |
100 | describe 'Disk' do |
101 | it_should_behave_like 'A Rack::Cache::EntityStore Implementation' |
102 | before do |
103 | @temp_dir = create_temp_directory |
104 | @store = Rack::Cache::EntityStore::Disk.new(@temp_dir) |
105 | end |
106 | after do |
107 | @store = nil |
108 | remove_entry_secure @temp_dir |
109 | end |
110 | it 'takes a path to ::new and creates the directory' do |
111 | path = @temp_dir + '/foo' |
112 | @store = Rack::Cache::EntityStore::Disk.new(path) |
113 | File.should.be.a.directory path |
114 | end |
115 | it 'produces a body that responds to #to_path' do |
116 | key, size = @store.write(['Some shells for her hair.']) |
117 | body = @store.open(key) |
118 | body.should.respond_to :to_path |
119 | path = "#{@temp_dir}/#{key[0..1]}/#{key[2..-1]}" |
120 | body.to_path.should.equal path |
121 | end |
122 | it 'spreads data over a 36² hash radius' do |
123 | (<<-PROSE).each_line { |line| @store.write([line]).first.should.be.sha_like } |
124 | My wild love went riding, |
125 | She rode all the day; |
126 | She rode to the devil, |
127 | And asked him to pay. |
128 | |
129 | The devil was wiser |
130 | It's time to repent; |
131 | He asked her to give back |
132 | The money she spent |
133 | |
134 | My wild love went riding, |
135 | She rode to sea; |
136 | She gathered together |
137 | Some shells for her hair |
138 | |
139 | She rode on to Christmas, |
140 | She rode to the farm; |
141 | She rode to Japan |
142 | And re-entered a town |
143 | |
144 | My wild love is crazy |
145 | She screams like a bird; |
146 | She moans like a cat |
147 | When she wants to be heard |
148 | |
149 | She rode and she rode on |
150 | She rode for a while, |
151 | Then stopped for an evening |
152 | And laid her head down |
153 | |
154 | By this time the weather |
155 | Had changed one degree, |
156 | She asked for the people |
157 | To let her go free |
158 | |
159 | My wild love went riding, |
160 | She rode for an hour; |
161 | She rode and she rested, |
162 | And then she rode on |
163 | My wild love went riding, |
164 | PROSE |
165 | subdirs = Dir["#{@temp_dir}/*"] |
166 | subdirs.each do |subdir| |
167 | File.basename(subdir).should.be =~ /^[0-9a-z]{2}$/ |
168 | files = Dir["#{subdir}/*"] |
169 | files.each do |filename| |
170 | File.basename(filename).should.be =~ /^[0-9a-z]{38}$/ |
171 | end |
172 | files.length.should.be > 0 |
173 | end |
174 | subdirs.length.should.equal 28 |
175 | end |
176 | end |
177 | |
178 | need_memcached 'entity store tests' do |
179 | describe 'MemCache' do |
180 | it_should_behave_like 'A Rack::Cache::EntityStore Implementation' |
181 | before do |
182 | @store = Rack::Cache::EntityStore::MemCache.new($memcached) |
183 | end |
184 | after do |
185 | @store = nil |
186 | end |
187 | end |
188 | end |
189 | end |