cache_debugging 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +3 -0
- data/Gemfile +29 -0
- data/LICENSE +20 -0
- data/README.md +104 -0
- data/Rakefile +32 -0
- data/cache_debugging.gemspec +20 -0
- data/lib/cache_debugging.rb +18 -0
- data/lib/cache_debugging/cache_blocks.rb +44 -0
- data/lib/cache_debugging/digestor.rb +3 -0
- data/lib/cache_debugging/railtie.rb +19 -0
- data/lib/cache_debugging/strict_dependencies.rb +47 -0
- data/lib/cache_debugging/utils.rb +40 -0
- data/lib/cache_debugging/version.rb +3 -0
- data/lib/cache_debugging/view_sampling.rb +80 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +10 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/workers_controller.rb +7 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/contract.rb +5 -0
- data/test/dummy/app/models/electrician.rb +3 -0
- data/test/dummy/app/models/gardener.rb +3 -0
- data/test/dummy/app/models/plumber.rb +3 -0
- data/test/dummy/app/models/tweet.rb +6 -0
- data/test/dummy/app/models/worker.rb +7 -0
- data/test/dummy/app/views/electricians/_electrician.html.erb +1 -0
- data/test/dummy/app/views/gardeners/_gardener.html.erb +1 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/plumbers/_plumber.html.erb +1 -0
- data/test/dummy/app/views/workers/_tweets.html.erb +5 -0
- data/test/dummy/app/views/workers/_worker.html.erb +12 -0
- data/test/dummy/app/views/workers/index.html.erb +17 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/caching.rb +32 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +16 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/migrate/20130910001826_create_workers.rb +36 -0
- data/test/dummy/db/schema.rb +55 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/electricians.yml +2 -0
- data/test/dummy/test/fixtures/gardeners.yml +2 -0
- data/test/dummy/test/fixtures/plumbers.yml +2 -0
- data/test/dummy/test/fixtures/workers.yml +17 -0
- data/test/integration/cache_debugging_test.rb +81 -0
- data/test/test_helper.rb +17 -0
- metadata +146 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CacheDebuggingTest < ActionDispatch::IntegrationTest
|
4
|
+
self.use_transactional_fixtures = true
|
5
|
+
fixtures :all
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Rails.cache.clear
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'basic caching' do
|
17
|
+
with_view_sampling(false) do
|
18
|
+
with_template_dependencies(false) do
|
19
|
+
get workers_path
|
20
|
+
assert_response :success
|
21
|
+
assert_template partial: "workers/_tweets", count: Worker.count
|
22
|
+
|
23
|
+
# second visit, everything should be cached
|
24
|
+
get workers_path
|
25
|
+
assert_template partial: "workers/_tweets", count: Worker.count
|
26
|
+
|
27
|
+
# modify a worker
|
28
|
+
assert Worker.first.touch
|
29
|
+
get workers_path
|
30
|
+
assert_template partial: "workers/_tweets", count: Worker.count + 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'template dependencies' do
|
36
|
+
with_view_sampling(false) do
|
37
|
+
with_template_dependencies(true) do
|
38
|
+
get workers_path
|
39
|
+
assert_response :error
|
40
|
+
assert response.body.match("not in template cache dependency tree")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'view_sampling' do
|
46
|
+
# set sample rate to 1
|
47
|
+
with_view_sampling(1) do
|
48
|
+
with_template_dependencies(false) do
|
49
|
+
get workers_path
|
50
|
+
assert_response :success
|
51
|
+
|
52
|
+
# fake a dependency change that does not touch the cache key
|
53
|
+
Tweet.create!({
|
54
|
+
worker: Worker.first,
|
55
|
+
message: "Test message"
|
56
|
+
})
|
57
|
+
|
58
|
+
# second request, should double check the cache
|
59
|
+
get workers_path
|
60
|
+
assert_response :error
|
61
|
+
assert response.body.match("Cache mismatch")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def with_view_sampling(val)
|
69
|
+
old_val = Rails.application.config.cache_debugging.view_sampling
|
70
|
+
Rails.application.config.cache_debugging.view_sampling = val
|
71
|
+
yield
|
72
|
+
Rails.application.config.cache_debugging.view_sampling = old_val
|
73
|
+
end
|
74
|
+
|
75
|
+
def with_template_dependencies(val)
|
76
|
+
old_val = Rails.application.config.cache_debugging.strict_dependencies
|
77
|
+
Rails.application.config.cache_debugging.strict_dependencies = val
|
78
|
+
yield
|
79
|
+
Rails.application.config.cache_debugging.strict_dependencies = old_val
|
80
|
+
end
|
81
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
13
|
+
|
14
|
+
# Load fixtures from the engine
|
15
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
16
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cache_debugging
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Ching
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Verify cache key dependencies
|
42
|
+
email: ching.jeff@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- .travis.yml
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- cache_debugging.gemspec
|
54
|
+
- lib/cache_debugging.rb
|
55
|
+
- lib/cache_debugging/cache_blocks.rb
|
56
|
+
- lib/cache_debugging/digestor.rb
|
57
|
+
- lib/cache_debugging/railtie.rb
|
58
|
+
- lib/cache_debugging/strict_dependencies.rb
|
59
|
+
- lib/cache_debugging/utils.rb
|
60
|
+
- lib/cache_debugging/version.rb
|
61
|
+
- lib/cache_debugging/view_sampling.rb
|
62
|
+
- test/dummy/README.rdoc
|
63
|
+
- test/dummy/Rakefile
|
64
|
+
- test/dummy/app/assets/images/.keep
|
65
|
+
- test/dummy/app/assets/javascripts/application.js
|
66
|
+
- test/dummy/app/assets/stylesheets/application.css
|
67
|
+
- test/dummy/app/controllers/application_controller.rb
|
68
|
+
- test/dummy/app/controllers/concerns/.keep
|
69
|
+
- test/dummy/app/controllers/workers_controller.rb
|
70
|
+
- test/dummy/app/helpers/application_helper.rb
|
71
|
+
- test/dummy/app/mailers/.keep
|
72
|
+
- test/dummy/app/models/.keep
|
73
|
+
- test/dummy/app/models/concerns/.keep
|
74
|
+
- test/dummy/app/models/contract.rb
|
75
|
+
- test/dummy/app/models/electrician.rb
|
76
|
+
- test/dummy/app/models/gardener.rb
|
77
|
+
- test/dummy/app/models/plumber.rb
|
78
|
+
- test/dummy/app/models/tweet.rb
|
79
|
+
- test/dummy/app/models/worker.rb
|
80
|
+
- test/dummy/app/views/electricians/_electrician.html.erb
|
81
|
+
- test/dummy/app/views/gardeners/_gardener.html.erb
|
82
|
+
- test/dummy/app/views/layouts/application.html.erb
|
83
|
+
- test/dummy/app/views/plumbers/_plumber.html.erb
|
84
|
+
- test/dummy/app/views/workers/_tweets.html.erb
|
85
|
+
- test/dummy/app/views/workers/_worker.html.erb
|
86
|
+
- test/dummy/app/views/workers/index.html.erb
|
87
|
+
- test/dummy/bin/bundle
|
88
|
+
- test/dummy/bin/rails
|
89
|
+
- test/dummy/bin/rake
|
90
|
+
- test/dummy/config.ru
|
91
|
+
- test/dummy/config/application.rb
|
92
|
+
- test/dummy/config/boot.rb
|
93
|
+
- test/dummy/config/database.yml
|
94
|
+
- test/dummy/config/environment.rb
|
95
|
+
- test/dummy/config/environments/development.rb
|
96
|
+
- test/dummy/config/environments/production.rb
|
97
|
+
- test/dummy/config/environments/test.rb
|
98
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
99
|
+
- test/dummy/config/initializers/caching.rb
|
100
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
101
|
+
- test/dummy/config/initializers/inflections.rb
|
102
|
+
- test/dummy/config/initializers/mime_types.rb
|
103
|
+
- test/dummy/config/initializers/secret_token.rb
|
104
|
+
- test/dummy/config/initializers/session_store.rb
|
105
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
106
|
+
- test/dummy/config/locales/en.yml
|
107
|
+
- test/dummy/config/routes.rb
|
108
|
+
- test/dummy/db/migrate/20130910001826_create_workers.rb
|
109
|
+
- test/dummy/db/schema.rb
|
110
|
+
- test/dummy/lib/assets/.keep
|
111
|
+
- test/dummy/log/.keep
|
112
|
+
- test/dummy/public/404.html
|
113
|
+
- test/dummy/public/422.html
|
114
|
+
- test/dummy/public/500.html
|
115
|
+
- test/dummy/public/favicon.ico
|
116
|
+
- test/dummy/test/fixtures/electricians.yml
|
117
|
+
- test/dummy/test/fixtures/gardeners.yml
|
118
|
+
- test/dummy/test/fixtures/plumbers.yml
|
119
|
+
- test/dummy/test/fixtures/workers.yml
|
120
|
+
- test/integration/cache_debugging_test.rb
|
121
|
+
- test/test_helper.rb
|
122
|
+
homepage: http://github.com/chingor13/cache_debugging
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.0.3
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Verify cache key dependencies via random sampling
|
146
|
+
test_files: []
|