racket-mvc 0.4.0 → 0.5.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/lib/racket.rb +25 -7
  4. data/lib/racket/application.rb +70 -136
  5. data/lib/racket/controller.rb +95 -38
  6. data/lib/racket/current.rb +1 -1
  7. data/lib/racket/helpers/file.rb +7 -5
  8. data/lib/racket/helpers/routing.rb +5 -5
  9. data/lib/racket/helpers/sass.rb +11 -11
  10. data/lib/racket/helpers/view.rb +8 -5
  11. data/lib/racket/plugins/base.rb +1 -1
  12. data/lib/racket/plugins/sass.rb +1 -1
  13. data/lib/racket/request.rb +3 -3
  14. data/lib/racket/response.rb +1 -1
  15. data/lib/racket/router.rb +31 -12
  16. data/lib/racket/session.rb +3 -3
  17. data/lib/racket/settings/application.rb +27 -33
  18. data/lib/racket/settings/base.rb +19 -8
  19. data/lib/racket/settings/controller.rb +9 -7
  20. data/lib/racket/settings/defaults.rb +81 -0
  21. data/lib/racket/utils.rb +19 -15
  22. data/lib/racket/utils/application.rb +4 -114
  23. data/lib/racket/utils/application/handler_stack.rb +163 -0
  24. data/lib/racket/utils/application/logger.rb +72 -0
  25. data/lib/racket/utils/application/registry_builder.rb +88 -0
  26. data/lib/racket/utils/application/stateless_services.rb +73 -0
  27. data/lib/racket/utils/exceptions.rb +3 -3
  28. data/lib/racket/utils/file_system.rb +75 -47
  29. data/lib/racket/utils/helpers.rb +35 -13
  30. data/lib/racket/utils/routing.rb +62 -46
  31. data/lib/racket/utils/views.rb +19 -187
  32. data/lib/racket/utils/views/renderer.rb +75 -0
  33. data/lib/racket/utils/views/template_cache.rb +126 -0
  34. data/lib/racket/utils/views/template_locator.rb +83 -0
  35. data/lib/racket/utils/views/template_resolver.rb +112 -0
  36. data/lib/racket/version.rb +2 -2
  37. data/lib/racket/view_manager.rb +12 -4
  38. data/rake/utils.rb +5 -5
  39. data/spec/_custom.rb +69 -19
  40. data/spec/_default.rb +60 -44
  41. data/spec/_plugin.rb +12 -14
  42. data/spec/_template_cache.rb +176 -0
  43. data/spec/racket.rb +10 -13
  44. data/spec/test_custom_app/controllers/sub1/custom_sub_controller_1.rb +1 -1
  45. data/spec/test_custom_app/controllers/sub3/custom_sub_controller_3.rb +19 -1
  46. data/spec/test_custom_app/controllers/sub5/custom_sub_controller_5.rb +8 -0
  47. data/spec/test_custom_app/files/stuff.rb +3 -0
  48. data/spec/test_custom_app/files/triplet.erb +5 -0
  49. data/spec/test_custom_app/templates/sub5/text.erb +3 -0
  50. data/spec/test_default_app/controllers/default_root_controller.rb +3 -0
  51. data/spec/test_default_app/controllers/sub1/default_sub_controller_1.rb +1 -1
  52. metadata +52 -11
@@ -6,17 +6,36 @@ describe 'A custom Racket test application' do
6
6
  logger: nil,
7
7
  my_custom_secret: 42,
8
8
  mode: :dev,
9
- view_dir: 'templates'
9
+ view_dir: 'templates',
10
+ warmup_urls: ['/sub1', '/sub2', '/sub3']
10
11
  )
11
12
  end
12
13
 
14
+ it 'should be able to locate a resource' do
15
+ get '/' # Ensures that app is loaded, otherwise Racket.resource_path may pick up settings from previously run test suites.
16
+ resource_path = Racket.resource_path('files', 'stuff.rb')
17
+ resource_path.should.equal(Pathname.new("files/stuff.rb").cleanpath.expand_path)
18
+ end
19
+
20
+ it 'should be able to require a resource' do
21
+ get '/' # Ensures that app is loaded, otherwise Racket.resource_path may pick up settings from previously run test suites.
22
+ Racket.require('files', 'stuff.rb')
23
+ stuff.should.equal('Stuff That Dreams Are Made of')
24
+ end
25
+
26
+ it 'should run in dev mode when requested' do
27
+ app.dev_mode?.should.equal(true)
28
+ end
29
+
13
30
  it 'should set requested settings' do
14
- app.settings.default_layout.should.equal('zebra.*')
15
- app.settings.view_dir.should.equal(Racket::Utils.build_path('templates'))
31
+ settings = app.instance_variable_get(:@registry).application_settings
32
+ settings.default_layout.should.equal('zebra.*')
33
+ view_dir = Pathname.new('templates').cleanpath.expand_path
34
+ settings.view_dir.should.equal(view_dir)
16
35
  end
17
36
 
18
37
  it 'should get the correct middleware' do
19
- middleware = app.settings.middleware
38
+ middleware = app.instance_variable_get(:@registry).application_settings.middleware
20
39
  middleware.length.should.equal(3)
21
40
  middleware[0].class.should.equal(Array)
22
41
  middleware[0].length.should.equal(1)
@@ -55,10 +74,10 @@ describe 'A custom Racket test application' do
55
74
 
56
75
  it 'should be able to require custom files' do
57
76
  Module.constants.should.not.include(:Blob)
58
- Racket.require 'extra/blob'
77
+ app.require 'extra/blob'
59
78
  Module.constants.should.include(:Blob)
60
79
  Module.constants.should.not.include(:InnerBlob)
61
- Racket.require 'extra', 'blob', 'inner_blob'
80
+ app.require 'extra', 'blob', 'inner_blob'
62
81
  Module.constants.should.include(:InnerBlob)
63
82
  end
64
83
 
@@ -84,6 +103,20 @@ describe 'A custom Racket test application' do
84
103
  last_response.body.should.equal("The secret is 42!\n")
85
104
  end
86
105
 
106
+ it 'should be able to render custom files with controller' do
107
+ get '/sub3/render_a_file_with_controller'
108
+ last_response.status.should.equal(200)
109
+ last_response.headers['Content-Type'].should.equal('text/html')
110
+ last_response.body.should.equal("123")
111
+ end
112
+
113
+ it 'should be able to render custom files with settings' do
114
+ get '/sub3/render_a_file_with_settings'
115
+ last_response.status.should.equal(200)
116
+ last_response.headers['Content-Type'].should.equal('text/html')
117
+ last_response.body.should.equal("\n1\n2\n3\n")
118
+ end
119
+
87
120
  it 'should be able to send files with auto mime type' do
88
121
  get '/sub1/send_existing_file_auto_mime'
89
122
  last_response.status.should.equal(200)
@@ -136,19 +169,36 @@ describe 'A custom Racket test application' do
136
169
  last_response.body.should.equal("LAYOUT: default: BAZ\n\n")
137
170
  end
138
171
 
172
+ it 'should be able to set template settings' do
173
+ get '/sub5/text'
174
+ last_response.status.should.equal(200)
175
+ last_response.body.should.equal("Hello World!")
176
+ end
177
+
139
178
  it 'should handle changes to global settings' do
140
- app.settings.fetch(:my_custom_secret).should.equal(42)
141
- app.settings.store(:my_custom_secret, '9Lazy9')
142
- app.settings.fetch(:my_custom_secret).should.equal('9Lazy9')
143
- app.settings.delete(:my_custom_secret)
144
- app.settings.fetch(:my_custom_secret).should.equal(nil)
145
- app.settings.default_content_type.should.equal('text/html')
146
- app.settings.fetch(:default_content_type).should.equal('text/html')
147
- app.settings.default_content_type = 'text/plain'
148
- app.settings.default_content_type.should.equal('text/plain')
149
- app.settings.fetch(:default_content_type).should.equal('text/plain')
150
- app.settings.default_content_type = 'text/html'
151
- app.settings.default_content_type.should.equal('text/html')
152
- app.settings.fetch(:default_content_type).should.equal('text/html')
179
+ settings = app.instance_variable_get(:@registry).application_settings
180
+ settings.fetch(:my_custom_secret).should.equal(42)
181
+ settings.store(:my_custom_secret, '9Lazy9')
182
+ settings.fetch(:my_custom_secret).should.equal('9Lazy9')
183
+ settings.delete(:my_custom_secret)
184
+ settings.fetch(:my_custom_secret).should.equal(nil)
185
+ settings.default_content_type.should.equal('text/html')
186
+ settings.fetch(:default_content_type).should.equal('text/html')
187
+ settings.default_content_type = 'text/plain'
188
+ settings.default_content_type.should.equal('text/plain')
189
+ settings.fetch(:default_content_type).should.equal('text/plain')
190
+ settings.default_content_type = 'text/html'
191
+ settings.default_content_type.should.equal('text/html')
192
+ settings.fetch(:default_content_type).should.equal('text/html')
193
+ end
194
+
195
+ it 'should return nil on settings without a default' do
196
+ settings = app.instance_variable_get(:@registry).application_settings
197
+ Racket::Settings::Application.setting(:nonexisting)
198
+ settings.nonexisting.should.equal(nil)
199
+ Racket::Settings::Application.instance_eval do
200
+ remove_method(:nonexisting)
201
+ remove_method(:nonexisting=)
202
+ end
153
203
  end
154
204
  end
@@ -10,31 +10,36 @@ describe 'A default Racket test application' do
10
10
  end
11
11
 
12
12
  it 'has mapped controllers correctly' do
13
- app.router.routes.length.should.equal(5)
14
- app.router.routes[DefaultRootController].should.equal('/')
15
- app.router.routes[DefaultSubController1].should.equal('/sub1')
16
- app.router.routes[DefaultSubController2].should.equal('/sub2')
17
- app.router.routes[DefaultSubController3].should.equal('/sub3')
18
- app.router.routes[DefaultInheritedController].should.equal('/sub3/inherited')
19
-
20
- app.router.action_cache.items[DefaultRootController].length.should.equal(5)
21
- app.router.action_cache.items[DefaultRootController].include?(:index).should.equal(true)
22
- app.router.action_cache.items[DefaultRootController].include?(:my_first_route)
23
- .should.equal(true)
24
- app.router.action_cache.items[DefaultRootController].include?(:my_second_route)
25
- .should.equal(true)
26
- app.router.action_cache.items[DefaultSubController1].length.should.equal(4)
27
- app.router.action_cache.items[DefaultSubController1].include?(:route_to_root).should.equal(true)
28
- app.router.action_cache.items[DefaultSubController1].include?(:route_to_nonexisting)
29
- .should.equal(true)
30
- app.router.action_cache.items[DefaultSubController2].length.should.equal(5)
31
- app.router.action_cache.items[DefaultSubController2].include?(:index).should.equal(true)
32
- app.router.action_cache.items[DefaultSubController2].include?(:current_action)
33
- .should.equal(true)
34
- app.router.action_cache.items[DefaultSubController2].include?(:current_params)
35
- .should.equal(true)
36
- app.router.action_cache.items[DefaultSubController3].should.equal([:index])
37
- app.router.action_cache.items[DefaultInheritedController].should.equal([:index])
13
+ router = app.instance_variable_get(:@registry).router
14
+ router.routes.length.should.equal(5)
15
+ router.routes[DefaultRootController].should.equal('/')
16
+ router.routes[DefaultSubController1].should.equal('/sub1')
17
+ router.routes[DefaultSubController2].should.equal('/sub2')
18
+ router.routes[DefaultSubController3].should.equal('/sub3')
19
+ router.routes[DefaultInheritedController].should.equal('/sub3/inherited')
20
+
21
+ router.action_cache.items[DefaultRootController].length.should.equal(6)
22
+ router.action_cache.items[DefaultRootController].include?(:index).should.equal(true)
23
+ router.action_cache.items[DefaultRootController].include?(:my_first_route)
24
+ .should.equal(true)
25
+ router.action_cache.items[DefaultRootController].include?(:my_second_route)
26
+ .should.equal(true)
27
+ router.action_cache.items[DefaultSubController1].length.should.equal(4)
28
+ router.action_cache.items[DefaultSubController1].include?(:route_to_root).should.equal(true)
29
+ router.action_cache.items[DefaultSubController1].include?(:route_to_nonexisting)
30
+ .should.equal(true)
31
+ router.action_cache.items[DefaultSubController2].length.should.equal(5)
32
+ router.action_cache.items[DefaultSubController2].include?(:index).should.equal(true)
33
+ router.action_cache.items[DefaultSubController2].include?(:current_action)
34
+ .should.equal(true)
35
+ router.action_cache.items[DefaultSubController2].include?(:current_params)
36
+ .should.equal(true)
37
+ router.action_cache.items[DefaultSubController3].should.equal([:index])
38
+ router.action_cache.items[DefaultInheritedController].should.equal([:index])
39
+ end
40
+
41
+ it 'should run in live mode by default' do
42
+ app.dev_mode?.should.equal(false)
38
43
  end
39
44
 
40
45
  it 'should set rack variables correctly' do
@@ -48,7 +53,7 @@ describe 'A default Racket test application' do
48
53
  end
49
54
 
50
55
  it 'should get the correct middleware' do
51
- middleware = app.settings.middleware
56
+ middleware = app.instance_variable_get(:@registry).application_settings.middleware
52
57
  middleware.length.should.equal(2)
53
58
  middleware[0].class.should.equal(Array)
54
59
  middleware[0].length.should.equal(2)
@@ -59,7 +64,7 @@ describe 'A default Racket test application' do
59
64
  true.should.equal(true)
60
65
  end
61
66
 
62
- it 'returns the correct respnse when calling index action' do
67
+ it 'returns the correct response when calling index action' do
63
68
  # RootController
64
69
  get '/'
65
70
  last_response.status.should.equal(200)
@@ -96,6 +101,12 @@ describe 'A default Racket test application' do
96
101
  last_response.body.should.equal('404 Not Found')
97
102
  end
98
103
 
104
+ it 'should return a valid response on empty action' do
105
+ get '/empty'
106
+ last_response.status.should.equal(200)
107
+ last_response.body.should.equal('')
108
+ end
109
+
99
110
  it 'should be able to find routes within the same controller' do
100
111
  get '/my_first_route'
101
112
  last_response.status.should.equal(200)
@@ -117,27 +128,34 @@ describe 'A default Racket test application' do
117
128
  end
118
129
 
119
130
  it 'should be able to log messages to everybody' do
120
- original_logger = app.settings.logger
131
+ registry = app.registry
132
+ original_logger = registry.application_logger
121
133
  sio = StringIO.new
122
- app.settings.logger = Logger.new(sio)
134
+ new_logger = Racket::Utils::Application::Logger.new(Logger.new(sio), :live)
135
+ registry.forget(:application_logger)
136
+ registry.singleton(:application_logger) { new_logger }
123
137
  app.inform_all('Informational message')
124
138
  sio.string.should.match(/Informational message/)
125
- app.settings.logger = original_logger
139
+ registry.forget(:application_logger)
140
+ registry.singleton(:application_logger) { original_logger }
126
141
  end
127
142
 
128
143
  it 'should be able to log messages to developer' do
129
- original_logger = app.settings.logger
130
- original_mode = app.settings.mode
144
+ registry = app.registry
145
+ original_logger = registry.application_logger
131
146
  sio = StringIO.new
132
- app.settings.logger = Logger.new(sio)
133
- app.settings.mode = :live
147
+ live_logger = Racket::Utils::Application::Logger.new(Logger.new(sio), :live)
148
+ registry.forget(:application_logger)
149
+ registry.singleton(:application_logger) { live_logger }
134
150
  app.inform_dev('Development message')
135
151
  sio.string.should.be.empty
136
- app.settings.mode = :dev
152
+ dev_logger = Racket::Utils::Application::Logger.new(Logger.new(sio), :dev)
153
+ registry.forget(:application_logger)
154
+ registry.singleton(:application_logger) { dev_logger }
137
155
  app.inform_dev('Hey, listen up!')
138
156
  sio.string.should.match(/Hey, listen up!/)
139
- app.settings.mode = original_mode
140
- app.settings.logger = original_logger
157
+ registry.forget(:application_logger)
158
+ registry.singleton(:application_logger) { original_logger }
141
159
  end
142
160
 
143
161
  it 'should be able to set and clear session variables' do
@@ -175,13 +193,6 @@ describe 'A default Racket test application' do
175
193
  response.each { |elem| elem.should.match(/Racket::Session/) }
176
194
  end
177
195
 
178
- it 'should be able to build paths correctly' do
179
- Racket::Utils.build_path.should.equal(Pathname.pwd)
180
- Racket::Utils.build_path('foo', 'bar', 'baz').should.equal(
181
- Pathname.pwd.join('foo').join('bar').join('baz')
182
- )
183
- end
184
-
185
196
  it 'should handle GET parameters correctly' do
186
197
  get '/sub2/some_get_data/?data1=foo&data3=bar'
187
198
  last_response.status.should.equal(200)
@@ -217,4 +228,9 @@ describe 'A default Racket test application' do
217
228
  last_response.headers['Content-Type'].should.equal('text/plain')
218
229
  last_response.body.should.equal('500 Internal Server Error')
219
230
  end
231
+
232
+ it 'should be able to resolve paths using the file system utilities' do
233
+ utils = app.instance_variable_get(:@registry).utils
234
+ utils.build_path.should.equal(Pathname.pwd)
235
+ end
220
236
  end
@@ -26,19 +26,17 @@ describe 'A Racket application with plugins' do
26
26
  last_response.body.should.equal('/css/sub/bar.css')
27
27
  end
28
28
 
29
- =begin
30
- it 'should render a SASS based stylesheet for the default controller' do
31
- get '/css/test.css'
32
- last_response.status.should.equal(200)
33
- last_response.headers['Content-Type'].should.equal('text/css')
34
- last_response.body.should.equal("body{background-color:snow;color:black}\n")
35
- end
29
+ # it 'should render a SASS based stylesheet for the default controller' do
30
+ # get '/css/test.css'
31
+ # last_response.status.should.equal(200)
32
+ # last_response.headers['Content-Type'].should.equal('text/css')
33
+ # last_response.body.should.equal("body{background-color:snow;color:black}\n")
34
+ # end
36
35
 
37
- it 'should render a SASS based stylesheet for a subcontroller' do
38
- get '/css/sub/test.css'
39
- last_response.status.should.equal(200)
40
- last_response.headers['Content-Type'].should.equal('text/css')
41
- last_response.body.should.equal("body{background-color:steelblue;color:gray}\n")
42
- end
43
- =end
36
+ # it 'should render a SASS based stylesheet for a subcontroller' do
37
+ # get '/css/sub/test.css'
38
+ # last_response.status.should.equal(200)
39
+ # last_response.headers['Content-Type'].should.equal('text/css')
40
+ # last_response.body.should.equal("body{background-color:steelblue;color:gray}\n")
41
+ # end
44
42
  end
@@ -0,0 +1,176 @@
1
+ describe 'Racket::Utils::Vievs::TemplateCache should adhere to Moneta::Cache interface' do
2
+ templates = {
3
+ 'template_1' => nil,
4
+ 'template_2' => 'template.haml',
5
+ 'template_3' => :template,
6
+ 'template_4' => ->(action) { action.to_s }
7
+ }.freeze
8
+
9
+ describe 'API compliance' do
10
+ cache = Racket::Utils::Views::TemplateCache.new({})
11
+ it 'should respond to all methods in the Moneta API' do
12
+ [:[], :load, :fetch, :[]=, :store, :delete, :key?, :increment, :decrement, :create, :clear,
13
+ :close, :features, :supports?].each do |meth|
14
+ cache.should.respond_to?(meth)
15
+ end
16
+ end
17
+
18
+ it 'should raise NotImplementedError on call to create' do
19
+ cache.supports?(:create).should.equal(false)
20
+ -> { cache.create('foo', 'bar') }
21
+ .should.raise(NotImplementedError)
22
+ end
23
+
24
+ it 'should raise NotImplementedError on call to decrement' do
25
+ cache.supports?(:decrement).should.equal(false)
26
+ -> { cache.decrement('foo') }
27
+ .should.raise(NotImplementedError)
28
+ end
29
+
30
+ it 'should raise NotImplementedError on call to increment' do
31
+ cache.supports?(:increment).should.equal(false)
32
+ -> { cache.increment('foo') }
33
+ .should.raise(NotImplementedError)
34
+ end
35
+
36
+ it 'should return an empty list of features' do
37
+ cache.features.length.should.equal(0)
38
+ end
39
+ end
40
+
41
+ describe 'Cache without default expiration' do
42
+ it 'should not expire items set with []= by default' do
43
+ cache = Racket::Utils::Views::TemplateCache.new({})
44
+ templates.each_pair do |key, val|
45
+ cache[key] = val
46
+ end
47
+ sleep(2)
48
+ templates.each_pair do |key, val|
49
+ cache[key].should.equal(val)
50
+ end
51
+ end
52
+ it 'should not expire items set with store by default' do
53
+ cache = Racket::Utils::Views::TemplateCache.new({})
54
+ templates.each_pair do |key, val|
55
+ cache.store(key, val)
56
+ end
57
+ sleep(2)
58
+ templates.each_pair do |key, val|
59
+ cache.fetch(key).should.equal(val)
60
+ end
61
+ end
62
+ it 'should expire items set with store and an explicit expire time' do
63
+ cache = Racket::Utils::Views::TemplateCache.new({})
64
+ templates.each_pair do |key, val|
65
+ cache.store(key, val, expires: 3)
66
+ end
67
+ sleep(2)
68
+ templates.each_pair do |key, val|
69
+ cache.fetch(key).should.equal(val)
70
+ end
71
+ templates.each_pair do |key, val|
72
+ cache.fetch(key, :foobar).should.equal(val)
73
+ end
74
+ templates.each_pair do |key, val|
75
+ cache.fetch(key) { 'out of space' }.should.equal(val)
76
+ end
77
+ sleep(2)
78
+ templates.each_key do |key|
79
+ cache.fetch(key).should.equal(nil)
80
+ end
81
+ templates.each_key do |key|
82
+ cache.fetch(key, :foobar).should.equal(:foobar)
83
+ end
84
+ templates.each_key do |key|
85
+ cache.fetch(key) { 'out of space' }.should.equal('out of space')
86
+ end
87
+ end
88
+ it 'should handle deletes correctly' do
89
+ cache = Racket::Utils::Views::TemplateCache.new({})
90
+ cache['number'] = 'one'
91
+ cache['number'].should.equal('one')
92
+ cache.delete('number')
93
+ cache['number'].should.equal(nil)
94
+ cache['number'] = 'two'
95
+ cache['number'].should.equal('two')
96
+ cache.clear
97
+ cache['number'].should.equal(nil)
98
+ cache['number'] = 'three'
99
+ cache['number'].should.equal('three')
100
+ cache.close
101
+ cache['number'].should.equal(nil)
102
+ end
103
+ end
104
+
105
+ describe 'Cache with default expiration' do
106
+ it 'should expire items set with []= by default' do
107
+ cache = Racket::Utils::Views::TemplateCache.new(expires: 3)
108
+ templates.each_pair do |key, val|
109
+ cache[key] = val
110
+ end
111
+ sleep(2)
112
+ templates.each_pair do |key, val|
113
+ cache[key].should.equal(val)
114
+ end
115
+ sleep(2)
116
+ templates.each_key do |key|
117
+ cache[key].should.equal(nil)
118
+ end
119
+ end
120
+ it 'should expire items set with store by default' do
121
+ cache = Racket::Utils::Views::TemplateCache.new(expires: 3)
122
+ templates.each_pair do |key, val|
123
+ cache.store(key, val)
124
+ end
125
+ sleep(2)
126
+ templates.each_pair do |key, val|
127
+ cache.fetch(key).should.equal(val)
128
+ end
129
+ sleep(2)
130
+ templates.each_key do |key|
131
+ cache.fetch(key).should.equal(nil)
132
+ end
133
+ end
134
+ it 'should not expire items set with a longer expire time' do
135
+ cache = Racket::Utils::Views::TemplateCache.new(expires: 3)
136
+ templates.each_pair do |key, val|
137
+ cache.store(key, val, expires: 5)
138
+ end
139
+ sleep(4)
140
+ templates.each_pair do |key, val|
141
+ cache.fetch(key).should.equal(val)
142
+ end
143
+ templates.each_pair do |key, val|
144
+ cache.fetch(key, :foobar).should.equal(val)
145
+ end
146
+ templates.each_pair do |key, val|
147
+ cache.fetch(key) { 'out of space' }.should.equal(val)
148
+ end
149
+ sleep(2)
150
+ templates.each_key do |key|
151
+ cache.fetch(key).should.equal(nil)
152
+ end
153
+ templates.each_key do |key|
154
+ cache.fetch(key, :foobar).should.equal(:foobar)
155
+ end
156
+ templates.each_key do |key|
157
+ cache.fetch(key) { 'out of space' }.should.equal('out of space')
158
+ end
159
+ end
160
+ it 'should handle deletes correctly' do
161
+ cache = Racket::Utils::Views::TemplateCache.new(expires: 60)
162
+ cache['number'] = 'one'
163
+ cache['number'].should.equal('one')
164
+ cache.delete('number')
165
+ cache['number'].should.equal(nil)
166
+ cache['number'] = 'two'
167
+ cache['number'].should.equal('two')
168
+ cache.clear
169
+ cache['number'].should.equal(nil)
170
+ cache['number'] = 'three'
171
+ cache['number'].should.equal('three')
172
+ cache.close
173
+ cache['number'].should.equal(nil)
174
+ end
175
+ end
176
+ end