sinatra-cache 0.2.3 → 0.3.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.
- data/.gitignore +14 -7
- data/LICENSE +1 -1
- data/README.rdoc +394 -0
- data/Rakefile +66 -23
- data/VERSION +1 -0
- data/lib/sinatra/cache.rb +10 -136
- data/lib/sinatra/cache/helpers.rb +663 -0
- data/lib/sinatra/output.rb +147 -0
- data/lib/sinatra/templates.rb +55 -0
- data/sinatra-cache.gemspec +30 -20
- data/spec/fixtures/apps/base/views/css.sass +2 -0
- data/spec/fixtures/apps/base/views/fragments.erb +11 -0
- data/spec/fixtures/apps/base/views/fragments_shared.erb +11 -0
- data/{test/fixtures → spec/fixtures/apps/base}/views/index.erb +0 -0
- data/spec/fixtures/apps/base/views/layout.erb +9 -0
- data/spec/fixtures/apps/base/views/params.erb +3 -0
- data/spec/sinatra/cache_spec.rb +593 -0
- data/spec/spec_helper.rb +62 -0
- metadata +73 -24
- data/README.md +0 -121
- data/VERSION.yml +0 -4
- data/test/SPECS.rdoc +0 -95
- data/test/cache_test.rb +0 -434
- data/test/fixtures/classic.rb +0 -25
- data/test/fixtures/myapp.rb +0 -36
- data/test/fixtures/myapp_default.rb +0 -37
- data/test/helper.rb +0 -62
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
::APP_ROOT = "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
|
7
|
+
ENV['RACK_ENV'] = 'test'
|
8
|
+
|
9
|
+
#--
|
10
|
+
# DEPENDENCIES
|
11
|
+
#++
|
12
|
+
%w(
|
13
|
+
sinatra/base
|
14
|
+
fileutils
|
15
|
+
sass
|
16
|
+
ostruct
|
17
|
+
yaml
|
18
|
+
json
|
19
|
+
).each {|lib| require lib }
|
20
|
+
|
21
|
+
#--
|
22
|
+
## SINATRA EXTENSIONS
|
23
|
+
#++
|
24
|
+
%w(
|
25
|
+
sinatra/tests
|
26
|
+
sinatra/cache
|
27
|
+
).each {|ext| require ext }
|
28
|
+
|
29
|
+
|
30
|
+
Spec::Runner.configure do |config|
|
31
|
+
config.include RspecHpricotMatchers
|
32
|
+
config.include Sinatra::Tests::TestCase
|
33
|
+
config.include Sinatra::Tests::RSpec::SharedSpecs
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# quick convenience methods..
|
38
|
+
|
39
|
+
def fixtures_path
|
40
|
+
"#{File.dirname(File.expand_path(__FILE__))}/fixtures"
|
41
|
+
end
|
42
|
+
|
43
|
+
def public_fixtures_path
|
44
|
+
"#{fixtures_path}/public"
|
45
|
+
end
|
46
|
+
|
47
|
+
class MyTestApp < Sinatra::Base
|
48
|
+
|
49
|
+
set :app_dir, "#{APP_ROOT}/apps/base"
|
50
|
+
set :public, "#{fixtures_path}/public"
|
51
|
+
set :views, "#{app_dir}/views"
|
52
|
+
|
53
|
+
register(Sinatra::Tests)
|
54
|
+
|
55
|
+
enable :raise_errors
|
56
|
+
|
57
|
+
end #/class MyTestApp
|
58
|
+
|
59
|
+
|
60
|
+
class Test::Unit::TestCase
|
61
|
+
Sinatra::Base.set :environment, :test
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- kematzy
|
@@ -9,11 +14,52 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-02-
|
17
|
+
date: 2010-02-25 00:00:00 +08:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: sinatra
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- a
|
31
|
+
version: 1.0.a
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: sinatra-tests
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 1
|
44
|
+
- 6
|
45
|
+
version: 0.1.6
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 3
|
58
|
+
- 0
|
59
|
+
version: 1.3.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: A Sinatra Extension that makes Page and Fragment Caching easy.
|
17
63
|
email: kematzy@gmail.com
|
18
64
|
executables: []
|
19
65
|
|
@@ -21,22 +67,26 @@ extensions: []
|
|
21
67
|
|
22
68
|
extra_rdoc_files:
|
23
69
|
- LICENSE
|
24
|
-
- README.
|
70
|
+
- README.rdoc
|
25
71
|
files:
|
26
72
|
- .gitignore
|
27
73
|
- LICENSE
|
28
|
-
- README.
|
74
|
+
- README.rdoc
|
29
75
|
- Rakefile
|
30
|
-
- VERSION
|
76
|
+
- VERSION
|
31
77
|
- lib/sinatra/cache.rb
|
78
|
+
- lib/sinatra/cache/helpers.rb
|
79
|
+
- lib/sinatra/output.rb
|
80
|
+
- lib/sinatra/templates.rb
|
32
81
|
- sinatra-cache.gemspec
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
82
|
+
- spec/fixtures/apps/base/views/css.sass
|
83
|
+
- spec/fixtures/apps/base/views/fragments.erb
|
84
|
+
- spec/fixtures/apps/base/views/fragments_shared.erb
|
85
|
+
- spec/fixtures/apps/base/views/index.erb
|
86
|
+
- spec/fixtures/apps/base/views/layout.erb
|
87
|
+
- spec/fixtures/apps/base/views/params.erb
|
88
|
+
- spec/sinatra/cache_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
40
90
|
has_rdoc: true
|
41
91
|
homepage: http://github.com/kematzy/sinatra-cache
|
42
92
|
licenses: []
|
@@ -50,24 +100,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
100
|
requirements:
|
51
101
|
- - ">="
|
52
102
|
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
53
105
|
version: "0"
|
54
|
-
version:
|
55
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
107
|
requirements:
|
57
108
|
- - ">="
|
58
109
|
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
59
112
|
version: "0"
|
60
|
-
version:
|
61
113
|
requirements: []
|
62
114
|
|
63
115
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.6
|
65
117
|
signing_key:
|
66
118
|
specification_version: 3
|
67
|
-
summary:
|
119
|
+
summary: A Sinatra Extension that makes Page and Fragment Caching easy.
|
68
120
|
test_files:
|
69
|
-
-
|
70
|
-
-
|
71
|
-
- test/fixtures/myapp.rb
|
72
|
-
- test/cache_test.rb
|
73
|
-
- test/helper.rb
|
121
|
+
- spec/sinatra/cache_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
data/README.md
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
Sinatra::Cache
|
2
|
-
==============
|
3
|
-
|
4
|
-
Adds a very *simple* Page Caching functionality to [Sinatra](http://www.sinatrarb.com/)
|
5
|
-
|
6
|
-
Docunext did not write this code. This is a fork from the original: [kematzy/sinatra-cache](http://github.com/kematzy/sinatra-cache)
|
7
|
-
|
8
|
-
<hr />
|
9
|
-
|
10
|
-
### Status
|
11
|
-
|
12
|
-
This is *unfinished work*, so use with care.
|
13
|
-
|
14
|
-
If you find it lacking or badly coded, please feel free to fork and improve. I'll be very happy :)
|
15
|
-
|
16
|
-
<hr />
|
17
|
-
|
18
|
-
|
19
|
-
### TODO's
|
20
|
-
|
21
|
-
|
22
|
-
* Make caching an option of the normal <tt>erb()/haml()/sass()</tt> methods, sort of like this:
|
23
|
-
|
24
|
-
<pre class="sh_ruby">
|
25
|
-
erb(:index, :cache => true/false)
|
26
|
-
|
27
|
-
# alternatively enable caching by setting a global config like this
|
28
|
-
set :cache_enabled_for :all || :only/except => ['/','/contact',...]
|
29
|
-
</pre>
|
30
|
-
|
31
|
-
|
32
|
-
* Improve the logging output to the standard Sinatra output (if we are having :logging enabled )
|
33
|
-
|
34
|
-
* Add fragment caching...
|
35
|
-
|
36
|
-
* Enable the options functionality for the <b>:cache</b> & <b>:cache_expire</b> methods, so that they can take custom extensions and more
|
37
|
-
|
38
|
-
|
39
|
-
<hr />
|
40
|
-
|
41
|
-
|
42
|
-
### CONFIGURATION
|
43
|
-
|
44
|
-
**Example 1: Sinatra 'classic' app.**
|
45
|
-
|
46
|
-
<pre class="sh_ruby">
|
47
|
-
require 'sinatra/cache'
|
48
|
-
|
49
|
-
# toggle for the cache functionality.
|
50
|
-
set :cache_enabled, true
|
51
|
-
# sets the default extension for cached files
|
52
|
-
set :cache_page_extension, '.html'
|
53
|
-
# sets the Cache dir to the root of the /public directory.
|
54
|
-
set :cache_output_dir, '' # was :cache_dir
|
55
|
-
</pre>
|
56
|
-
|
57
|
-
**Example 2: Sinatra 'sub-classed' app.**
|
58
|
-
|
59
|
-
<pre class="sh_ruby">
|
60
|
-
require 'sinatra/cache'
|
61
|
-
|
62
|
-
class MyApp < Sinatra::Base
|
63
|
-
|
64
|
-
register Sinatra::Cache
|
65
|
-
|
66
|
-
# toggle for the cache functionality.
|
67
|
-
set :cache_enabled, true
|
68
|
-
# sets the default extension for cached files
|
69
|
-
set :cache_page_extension, '.html'
|
70
|
-
# sets the Cache output dir to the root of the /public directory.
|
71
|
-
set :cache_output_dir, '' # was :cache_dir
|
72
|
-
</pre>
|
73
|
-
|
74
|
-
|
75
|
-
<hr />
|
76
|
-
|
77
|
-
|
78
|
-
### USAGE
|
79
|
-
|
80
|
-
Basic Page Caching into static HTML files
|
81
|
-
|
82
|
-
<pre class="sh_ruby">
|
83
|
-
get '/contact' do
|
84
|
-
# NB! options is currently not working
|
85
|
-
cache( erb( :contact ), :options => 'should go here' )
|
86
|
-
end
|
87
|
-
</pre>
|
88
|
-
|
89
|
-
Expiring old pages (ie: after POST or PUT events)
|
90
|
-
|
91
|
-
<pre class="sh_ruby">
|
92
|
-
# not very good example
|
93
|
-
post '/contact' do
|
94
|
-
cache_expire( '/contact', options )
|
95
|
-
end
|
96
|
-
</pre>
|
97
|
-
|
98
|
-
See the "test":test/ and "test/fixtures":test/fixtures/ directories for more examples.
|
99
|
-
|
100
|
-
|
101
|
-
<hr />
|
102
|
-
|
103
|
-
|
104
|
-
### DEFAULT OPTIONS
|
105
|
-
|
106
|
-
* <tt>:cache_enabled</tt> => toggle for the cache functionality. Default is: <tt>true</tt>
|
107
|
-
* <tt>:cache_page_extension</tt> => sets the default extension for cached files. Default is: <tt>.html</tt>
|
108
|
-
* <tt>:cache_output_dir</tt> => sets cache directory where cached files are stored. Default is: ''(empty) == root of /public.<br>
|
109
|
-
set to empty, since the ideal 'system/cache/' does not currently work with Passenger & mod_rewrite :(
|
110
|
-
* <tt>:cache_logging</tt> => toggle for logging the cache calls. Default is: <tt>true</tt>
|
111
|
-
* <tt>:cache_logging_level</tt> => sets the level of the cache logger. Default is: <tt>:info</tt>.<br />
|
112
|
-
Options:(unused atm) [:info, :warn, :debug]
|
113
|
-
|
114
|
-
<hr />
|
115
|
-
|
116
|
-
### Credits
|
117
|
-
|
118
|
-
A big *Thank You!* goes to [rtomayko](http://github.com/rtomayko/), [blakemizerany](http://github.com/blakemizerany/) and others working on the Sinatra framework.
|
119
|
-
|
120
|
-
Inspired by code from [Rails](http://rubyonrails.com/) & [Merb](http://merbivore.com/)
|
121
|
-
and [sinatra-mailer](http://github.com/foca/sinatra-mailer/tree/master)
|
data/VERSION.yml
DELETED
data/test/SPECS.rdoc
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
Test Suite for [Sinatra::Cache v0.2.0] produced on [2009-25-02 at 00:37]
|
2
|
-
|
3
|
-
== Sinatra::Cache
|
4
|
-
=== ClassMethods
|
5
|
-
==== the :version method
|
6
|
-
* should have a :version method that returns a String with the version number in it
|
7
|
-
* should not interfere with the normal Sinatra VERSION
|
8
|
-
=== Instance Methods
|
9
|
-
==== Private
|
10
|
-
===== :cache_file_name method
|
11
|
-
====== when using default options
|
12
|
-
* should handle '/' and return 'index.html'
|
13
|
-
* should handle top level URI's and return the URI plus '.html'
|
14
|
-
* should handle sub level URIs and return the directory/file format
|
15
|
-
====== when using customized options
|
16
|
-
* should handle '/' and return 'index.html'
|
17
|
-
* should handle top level URI's and return the URI plus '.html'
|
18
|
-
* should handle sub level URIs and return the directory/file format
|
19
|
-
===== :cache_page_path method
|
20
|
-
====== when using default options
|
21
|
-
* should handle '/' and return the full path to 'index.html'
|
22
|
-
* should handle top level URI's and return the full path to the URI plus '.html'
|
23
|
-
* should handle sub level URIs and return the full path to the URI
|
24
|
-
====== when using customized options
|
25
|
-
* should handle '/' and return the full path to 'index.html'
|
26
|
-
* should handle top level URI's and return the full path to the URI plus '.html'
|
27
|
-
* should handle sub level URIs and return the full path to the URI
|
28
|
-
===== :log method
|
29
|
-
* MISSING TESTS =>
|
30
|
-
==== Public
|
31
|
-
===== :cache method
|
32
|
-
====== when using default options
|
33
|
-
* is tested below in the Page Caching section
|
34
|
-
====== when using customized options
|
35
|
-
* is tested below in the Page Caching section
|
36
|
-
=== configuration methods
|
37
|
-
==== when using default options
|
38
|
-
* the :cache_enabled option should be correct (true)
|
39
|
-
* the :cache_page_extension option should be correct (.html)
|
40
|
-
* the :cache_dir option should be correct ('')
|
41
|
-
* the :cache_logging option should be correct (true)
|
42
|
-
* the :cache_logging_level option should be correct (:info)
|
43
|
-
==== when using customized options
|
44
|
-
* the :cache_enabled option should be correct (false)
|
45
|
-
* the :cache_page_extension option should be correct (.cache.html)
|
46
|
-
* the :cache_dir option should be correct ('system/cache')
|
47
|
-
* the :cache_logging option should be correct (true)
|
48
|
-
* the :cache_logging_level option should be correct (:info)
|
49
|
-
=== Page Caching
|
50
|
-
==== when using default options
|
51
|
-
* should NOT cache the un-cached index page
|
52
|
-
* should cache the /cache page
|
53
|
-
* should expire the /cache page
|
54
|
-
==== when using customized options
|
55
|
-
* should NOT cache the un-cached index page
|
56
|
-
* should NOT cache the /cache page since :cache_enabled => false
|
57
|
-
===== and setting cache_enabled => true
|
58
|
-
* should cache the /cache page
|
59
|
-
* should expire the /cache page
|
60
|
-
=== Sinatra::Base
|
61
|
-
==== should respond to
|
62
|
-
* the :cache_dir method
|
63
|
-
* the :cache_dir= method
|
64
|
-
* the :cache_dir? method
|
65
|
-
* the :cache_enabled method
|
66
|
-
* the :cache_enabled= method
|
67
|
-
* the :cache_enabled? method
|
68
|
-
* the :cache_logging method
|
69
|
-
* the :cache_logging= method
|
70
|
-
* the :cache_logging? method
|
71
|
-
* the :cache_logging_level method
|
72
|
-
* the :cache_logging_level= method
|
73
|
-
* the :cache_logging_level? method
|
74
|
-
* the :cache_page_extension method
|
75
|
-
* the :cache_page_extension= method
|
76
|
-
* the :cache_page_extension? method
|
77
|
-
=== Sinatra::Default
|
78
|
-
==== should respond to
|
79
|
-
* the :cache_dir method
|
80
|
-
* the :cache_dir= method
|
81
|
-
* the :cache_dir? method
|
82
|
-
* the :cache_enabled method
|
83
|
-
* the :cache_enabled= method
|
84
|
-
* the :cache_enabled? method
|
85
|
-
* the :cache_logging method
|
86
|
-
* the :cache_logging= method
|
87
|
-
* the :cache_logging? method
|
88
|
-
* the :cache_logging_level method
|
89
|
-
* the :cache_logging_level= method
|
90
|
-
* the :cache_logging_level? method
|
91
|
-
* the :cache_page_extension method
|
92
|
-
* the :cache_page_extension= method
|
93
|
-
* the :cache_page_extension? method
|
94
|
-
|
95
|
-
64 specifications (84 requirements), 0 failures
|
data/test/cache_test.rb
DELETED
@@ -1,434 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/lib/sinatra/cache"
|
3
|
-
|
4
|
-
class Sinatra::Base
|
5
|
-
# include Sinatra::Cache
|
6
|
-
end #/class Sinatra::Base
|
7
|
-
|
8
|
-
puts "Test Suite for [#{Sinatra::Cache.version}] produced on [#{ Time.now.strftime("%Y-%d-%m at %H:%M") }]"
|
9
|
-
|
10
|
-
describe "Sinatra::Cache" do
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
|
14
|
-
default_app = mock_app do
|
15
|
-
register Sinatra::Cache
|
16
|
-
|
17
|
-
set :public, "#{File.dirname(File.expand_path(__FILE__))}/fixtures/public"
|
18
|
-
set :views, "#{File.dirname(File.expand_path(__FILE__))}/fixtures/views"
|
19
|
-
|
20
|
-
get '/' do
|
21
|
-
erb(:index)
|
22
|
-
end
|
23
|
-
|
24
|
-
get '/cache' do
|
25
|
-
# "Hello World from Sinatra Version=[#{Sinatra::VERSION}]"
|
26
|
-
cache("Hello World from Sinatra Version=[#{Sinatra::VERSION}]")
|
27
|
-
end
|
28
|
-
# YES, I know this is NOT ideal, but it's only test ;-)
|
29
|
-
get '/cache_expire' do
|
30
|
-
cache_expire("/cache")
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
custom_app = mock_app do
|
36
|
-
register Sinatra::Cache
|
37
|
-
|
38
|
-
set :public, "#{File.dirname(__FILE__)}/fixtures/public"
|
39
|
-
set :views, "#{File.dirname(__FILE__)}/fixtures/views"
|
40
|
-
|
41
|
-
set :cache_enabled, false
|
42
|
-
set :cache_page_extension, '.cache.html'
|
43
|
-
set :cache_output_dir, 'system/cache'
|
44
|
-
set :cache_logging, false
|
45
|
-
set :cache_logging_level, :info
|
46
|
-
|
47
|
-
get '/' do
|
48
|
-
erb :index
|
49
|
-
end
|
50
|
-
|
51
|
-
get '/cache' do
|
52
|
-
cache("Hello World from Sinatra Version=[#{Sinatra::VERSION}]")
|
53
|
-
end
|
54
|
-
# YES, I know this is NOT ideal, but it's only test ;-)
|
55
|
-
get '/cache_expire' do
|
56
|
-
cache_expire("/cache")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
@default_app = default_app.new
|
61
|
-
@custom_app = custom_app.new
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "ClassMethods" do
|
65
|
-
|
66
|
-
describe "the :version method" do
|
67
|
-
|
68
|
-
it "should have a :version method that returns a String with the version number in it" do
|
69
|
-
v = Sinatra::Cache.version
|
70
|
-
assert_not_nil(v)
|
71
|
-
assert_kind_of(String, v)
|
72
|
-
assert_match(/Sinatra::Cache v\d\.\d\.\d/, v)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should not interfere with the normal Sinatra VERSION" do
|
76
|
-
assert_not_equal(Sinatra::Cache.version, Sinatra::VERSION)
|
77
|
-
end
|
78
|
-
|
79
|
-
end #/the :version method
|
80
|
-
|
81
|
-
end #/ClassMethods
|
82
|
-
|
83
|
-
|
84
|
-
describe "Instance Methods" do
|
85
|
-
|
86
|
-
describe "Private" do
|
87
|
-
|
88
|
-
describe ":cache_file_name method" do
|
89
|
-
|
90
|
-
# temporary monkeypatch to enable testing
|
91
|
-
module Sinatra::Cache::Helpers
|
92
|
-
public :cache_file_name
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "when using default options" do
|
96
|
-
|
97
|
-
it "should handle '/' and return 'index.html'" do
|
98
|
-
expected = "index.html"
|
99
|
-
assert_equal(expected, @default_app.cache_file_name("/"))
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should handle top level URI's and return the URI plus '.html'" do
|
103
|
-
expected = "cache.html"
|
104
|
-
assert_equal(expected, @default_app.cache_file_name("/cache"))
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should handle sub level URIs and return the directory/file format" do
|
108
|
-
expected = "cache/test.html"
|
109
|
-
assert_equal(expected, @default_app.cache_file_name("/cache/test"))
|
110
|
-
end
|
111
|
-
|
112
|
-
end #/when using default options
|
113
|
-
|
114
|
-
describe "when using customized options" do
|
115
|
-
|
116
|
-
it "should handle '/' and return 'index.html'" do
|
117
|
-
expected = "index.cache.html"
|
118
|
-
assert_equal(expected, @custom_app.cache_file_name("/"))
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should handle top level URI's and return the URI plus '.html'" do
|
122
|
-
expected = "cache.cache.html"
|
123
|
-
assert_equal(expected, @custom_app.cache_file_name("/cache"))
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should handle sub level URIs and return the directory/file format" do
|
127
|
-
expected = "cache/test.cache.html"
|
128
|
-
assert_equal(expected, @custom_app.cache_file_name("/cache/test"))
|
129
|
-
end
|
130
|
-
|
131
|
-
end #/when using customized options
|
132
|
-
|
133
|
-
end #/:cache_page_path method
|
134
|
-
|
135
|
-
describe ":cache_page_path method" do
|
136
|
-
|
137
|
-
# temporary monkeypatch to enable testing
|
138
|
-
module Sinatra::Cache::Helpers
|
139
|
-
public :cache_page_path
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "when using default options" do
|
143
|
-
|
144
|
-
it "should handle '/' and return the full path to 'index.html'" do
|
145
|
-
expected = "#{public_fixtures_path}/index.html"
|
146
|
-
assert_equal(expected, @default_app.cache_page_path("/"))
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should handle top level URI's and return the full path to the URI plus '.html'" do
|
150
|
-
expected = "#{public_fixtures_path}/cache.html"
|
151
|
-
assert_equal(expected, @default_app.cache_page_path("/cache"))
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should handle sub level URIs and return the full path to the URI" do
|
155
|
-
expected = "#{public_fixtures_path}/cache/test.html"
|
156
|
-
assert_equal(expected, @default_app.cache_page_path("/cache/test"))
|
157
|
-
end
|
158
|
-
|
159
|
-
end #/when using default options
|
160
|
-
|
161
|
-
describe "when using customized options" do
|
162
|
-
|
163
|
-
it "should handle '/' and return the full path to 'index.html'" do
|
164
|
-
expected = "#{public_fixtures_path}/system/cache/index.cache.html"
|
165
|
-
assert_equal(expected, @custom_app.cache_page_path("/"))
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should handle top level URI's and return the full path to the URI plus '.html'" do
|
169
|
-
expected = "#{public_fixtures_path}/system/cache/cache.cache.html"
|
170
|
-
assert_equal(expected, @custom_app.cache_page_path("/cache"))
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should handle sub level URIs and return the full path to the URI" do
|
174
|
-
expected = "#{public_fixtures_path}/system/cache/cache/test.cache.html"
|
175
|
-
assert_equal(expected, @custom_app.cache_page_path("/cache/test"))
|
176
|
-
end
|
177
|
-
|
178
|
-
end #/when using customized options
|
179
|
-
|
180
|
-
end #/:cache_page_path method
|
181
|
-
|
182
|
-
describe ":log method" do
|
183
|
-
|
184
|
-
it "MISSING TESTS =>" do
|
185
|
-
assert(true)
|
186
|
-
end
|
187
|
-
|
188
|
-
end #/:log method
|
189
|
-
|
190
|
-
end #/Private
|
191
|
-
|
192
|
-
describe "Public" do
|
193
|
-
|
194
|
-
describe ":cache method" do
|
195
|
-
|
196
|
-
describe "when using default options" do
|
197
|
-
|
198
|
-
it "is tested below in the Page Caching section" do
|
199
|
-
assert true
|
200
|
-
end
|
201
|
-
|
202
|
-
end #/when using default options
|
203
|
-
|
204
|
-
describe "when using customized options" do
|
205
|
-
|
206
|
-
it "is tested below in the Page Caching section" do
|
207
|
-
assert true
|
208
|
-
end
|
209
|
-
|
210
|
-
end #/when using customized options
|
211
|
-
|
212
|
-
end #/:cache method
|
213
|
-
|
214
|
-
end #/Public
|
215
|
-
|
216
|
-
end #/Instance Methods
|
217
|
-
|
218
|
-
|
219
|
-
describe "configuration methods" do
|
220
|
-
|
221
|
-
describe "when using default options" do
|
222
|
-
|
223
|
-
it "the :cache_enabled option should be correct (true)" do
|
224
|
-
assert_equal(true, @default_app.options.cache_enabled)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "the :cache_page_extension option should be correct (.html)" do
|
228
|
-
assert_equal('.html', @default_app.options.cache_page_extension)
|
229
|
-
end
|
230
|
-
|
231
|
-
it "the :cache_output_dir option should be correct ('') " do
|
232
|
-
assert_equal('', @default_app.options.cache_output_dir)
|
233
|
-
end
|
234
|
-
|
235
|
-
it "the :cache_logging option should be correct (true)" do
|
236
|
-
assert_equal(true, @default_app.options.cache_logging)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "the :cache_logging_level option should be correct (:info)" do
|
240
|
-
assert_equal(:info, @default_app.options.cache_logging_level)
|
241
|
-
end
|
242
|
-
|
243
|
-
end #/default options
|
244
|
-
|
245
|
-
describe "when using customized options" do
|
246
|
-
|
247
|
-
it "the :cache_enabled option should be correct (false)" do
|
248
|
-
assert_equal(false, @custom_app.options.cache_enabled)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "the :cache_page_extension option should be correct (.cache.html)" do
|
252
|
-
assert_equal('.cache.html', @custom_app.options.cache_page_extension)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "the :cache_output_dir option should be correct ('system/cache') " do
|
256
|
-
assert_equal('system/cache', @custom_app.options.cache_output_dir)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "the :cache_logging option should be correct (true)" do
|
260
|
-
assert_equal(false, @custom_app.options.cache_logging)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "the :cache_logging_level option should be correct (:info)" do
|
264
|
-
assert_equal(:info, @custom_app.options.cache_logging_level)
|
265
|
-
end
|
266
|
-
|
267
|
-
end #/when using customized options
|
268
|
-
|
269
|
-
end #/configuration methods
|
270
|
-
|
271
|
-
|
272
|
-
describe "Page Caching" do
|
273
|
-
after(:each) do
|
274
|
-
# FileUtils.rm_r(Dir["#{public_fixtures_path}/*"])
|
275
|
-
end
|
276
|
-
|
277
|
-
describe "when using default options" do
|
278
|
-
|
279
|
-
it "should NOT cache the un-cached index page" do
|
280
|
-
request = Rack::MockRequest.new(@default_app)
|
281
|
-
response = request.get('/')
|
282
|
-
assert response
|
283
|
-
assert_equal '<h1>HOME</h1>', response.body
|
284
|
-
assert_equal(false, test(?f, "#{public_fixtures_path}/index.html"))
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should cache the /cache page" do
|
288
|
-
request = Rack::MockRequest.new(@default_app)
|
289
|
-
response = request.get('/cache')
|
290
|
-
assert response
|
291
|
-
assert_match(/^Hello World from Sinatra Version=\[\d\.\d\.\d(\.\d)?\]\n/, response.body)
|
292
|
-
assert(test(?f, "#{public_fixtures_path}/cache.html"))
|
293
|
-
assert_match(/^Hello World from Sinatra Version=\[\d\.\d\.\d(\.\d)?\]\n/, File.read("#{public_fixtures_path}/cache.html"))
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should expire the /cache page" do
|
297
|
-
assert(test(?f, "#{public_fixtures_path}/cache.html"))
|
298
|
-
request = Rack::MockRequest.new(@default_app)
|
299
|
-
response = request.get('/cache_expire')
|
300
|
-
assert response
|
301
|
-
# TODO:: this is dodgy stuff, rework
|
302
|
-
assert_not_equal('', response.body)
|
303
|
-
assert_equal(false, test(?f, "#{public_fixtures_path}/cache.html"))
|
304
|
-
end
|
305
|
-
|
306
|
-
end #/when using default options
|
307
|
-
|
308
|
-
describe "when using customized options" do
|
309
|
-
|
310
|
-
it "should NOT cache the un-cached index page" do
|
311
|
-
request = Rack::MockRequest.new(@custom_app)
|
312
|
-
response = request.get('/')
|
313
|
-
assert response
|
314
|
-
assert_equal '<h1>HOME</h1>', response.body
|
315
|
-
assert_equal(false, test(?f, "#{public_fixtures_path}/index.html"))
|
316
|
-
end
|
317
|
-
|
318
|
-
it "should NOT cache the /cache page since :cache_enabled => false" do
|
319
|
-
request = Rack::MockRequest.new(@custom_app)
|
320
|
-
response = request.get('/cache')
|
321
|
-
assert response
|
322
|
-
assert_match(/^Hello World from Sinatra Version=\[\d\.\d\.\d(\.\d)?\]/, response.body)
|
323
|
-
assert_equal(false, test(?f, "#{public_fixtures_path}/cache.cache.html"))
|
324
|
-
end
|
325
|
-
|
326
|
-
describe "and setting cache_enabled => true" do
|
327
|
-
|
328
|
-
before(:each) do
|
329
|
-
custom_enabled_app = mock_app do
|
330
|
-
register Sinatra::Cache
|
331
|
-
|
332
|
-
set :public, "#{File.dirname(File.expand_path(__FILE__))}/fixtures/public"
|
333
|
-
set :views, "#{File.dirname(File.expand_path(__FILE__))}/fixtures/views"
|
334
|
-
|
335
|
-
set :cache_enabled, true
|
336
|
-
set :cache_page_extension, '.cache.html'
|
337
|
-
set :cache_output_dir, 'system/cache'
|
338
|
-
set :cache_logging, true
|
339
|
-
set :cache_logging_level, :info
|
340
|
-
|
341
|
-
get '/' do
|
342
|
-
erb :index
|
343
|
-
end
|
344
|
-
|
345
|
-
get '/cache' do
|
346
|
-
cache("Hello World from Sinatra Version=[#{Sinatra::VERSION}]")
|
347
|
-
end
|
348
|
-
|
349
|
-
# YES, I know this is NOT ideal, but it's only test ;-)
|
350
|
-
get '/cache_expire' do
|
351
|
-
cache_expire("/cache")
|
352
|
-
end
|
353
|
-
|
354
|
-
end
|
355
|
-
|
356
|
-
@custom_enabled_app = custom_enabled_app.new
|
357
|
-
end
|
358
|
-
|
359
|
-
it "should cache the /cache page" do
|
360
|
-
request = Rack::MockRequest.new(@custom_enabled_app)
|
361
|
-
response = request.get('/cache')
|
362
|
-
assert response
|
363
|
-
assert_match(/^Hello World from Sinatra Version=\[\d\.\d\.\d(\.\d)?\]\n<!-- page cached: \d+-\d+-\d+ \d+:\d+:\d+ -->\n$/, response.body)
|
364
|
-
assert(test(?f, "#{public_fixtures_path}/system/cache/cache.cache.html"))
|
365
|
-
assert_match(/^Hello World from Sinatra Version=\[\d\.\d\.\d(\.\d)?\]\n<!-- page cached: \d+-\d+-\d+ \d+:\d+:\d+ -->\n$/, File.read("#{public_fixtures_path}/system/cache/cache.cache.html"))
|
366
|
-
end
|
367
|
-
|
368
|
-
it "should expire the /cache page" do
|
369
|
-
assert(test(?f, "#{public_fixtures_path}/system/cache/cache.cache.html"))
|
370
|
-
request = Rack::MockRequest.new(@custom_enabled_app)
|
371
|
-
response = request.get('/cache_expire')
|
372
|
-
assert response
|
373
|
-
# TODO:: this is dodgy stuff, rework
|
374
|
-
assert_not_equal('', response.body)
|
375
|
-
assert_equal(false, test(?f, "#{public_fixtures_path}/system/cache/cache.cache.html"))
|
376
|
-
end
|
377
|
-
|
378
|
-
end #/and setting cache_enabled => true
|
379
|
-
|
380
|
-
end #/when using customized options
|
381
|
-
|
382
|
-
|
383
|
-
end #/Page Caching
|
384
|
-
|
385
|
-
|
386
|
-
describe "Sinatra::Base" do
|
387
|
-
|
388
|
-
before do
|
389
|
-
Sinatra::Base.register(Sinatra::Cache)
|
390
|
-
end
|
391
|
-
|
392
|
-
describe "should respond to" do
|
393
|
-
|
394
|
-
[
|
395
|
-
"cache_output_dir", "cache_output_dir=","cache_output_dir?", "cache_enabled","cache_enabled=", "cache_enabled?",
|
396
|
-
"cache_logging","cache_logging=","cache_logging?","cache_logging_level","cache_logging_level=","cache_logging_level?",
|
397
|
-
"cache_page_extension","cache_page_extension=","cache_page_extension?"
|
398
|
-
].each do |m|
|
399
|
-
|
400
|
-
it "the :#{m} method" do
|
401
|
-
assert_respond_to(Sinatra::Base, m.to_sym)
|
402
|
-
end
|
403
|
-
|
404
|
-
end
|
405
|
-
|
406
|
-
end #/should respond to
|
407
|
-
|
408
|
-
end #/Sinatra::Base
|
409
|
-
|
410
|
-
describe "Sinatra::Default" do
|
411
|
-
|
412
|
-
before do
|
413
|
-
Sinatra::Base.register(Sinatra::Cache)
|
414
|
-
end
|
415
|
-
|
416
|
-
describe "should respond to" do
|
417
|
-
|
418
|
-
[
|
419
|
-
"cache_output_dir", "cache_output_dir=","cache_output_dir?", "cache_enabled","cache_enabled=", "cache_enabled?",
|
420
|
-
"cache_logging","cache_logging=","cache_logging?","cache_logging_level","cache_logging_level=","cache_logging_level?",
|
421
|
-
"cache_page_extension","cache_page_extension=","cache_page_extension?"
|
422
|
-
].each do |m|
|
423
|
-
|
424
|
-
it "the :#{m} method" do
|
425
|
-
assert_respond_to(Sinatra::Default, m.to_sym)
|
426
|
-
end
|
427
|
-
|
428
|
-
end
|
429
|
-
|
430
|
-
end #/should respond to
|
431
|
-
|
432
|
-
end #/Sinatra::Default
|
433
|
-
|
434
|
-
end #/Sinatra::Cache
|