ettu 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +32 -17
- data/ROADMAP.md +1 -1
- data/ettu.gemspec +5 -4
- data/lib/ettu/configuration.rb +18 -28
- data/lib/ettu/fresh_when.rb +14 -4
- data/lib/ettu/railtie.rb +11 -0
- data/lib/ettu/version.rb +1 -1
- data/lib/ettu.rb +16 -4
- data/spec/{ettu/ettu_spec.rb → ettu_spec.rb} +45 -69
- data/spec/fixtures.rb +52 -0
- data/spec/fresh_when_spec.rb +46 -0
- data/spec/spec_helper.rb +10 -19
- metadata +26 -94
- data/spec/controllers/users_controller_spec.rb +0 -66
- data/spec/dummy/.gitignore +0 -3
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/javascripts/test.js +0 -1
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -11
- data/spec/dummy/app/controllers/users_controller.rb +0 -9
- data/spec/dummy/app/models/user.rb +0 -12
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/users/index.html.erb +0 -1
- data/spec/dummy/config/application.rb +0 -65
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/environment.rb +0 -9
- data/spec/dummy/config/environments/test.rb +0 -35
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -10
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/.keep +0 -0
- data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js +0 -15
- data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js.gz +0 -0
- data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css +0 -14
- data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css.gz +0 -0
- data/spec/dummy/public/assets/application.css +0 -14
- data/spec/dummy/public/assets/application.css.gz +0 -0
- data/spec/dummy/public/assets/application.js +0 -15
- data/spec/dummy/public/assets/application.js.gz +0 -0
- data/spec/dummy/public/assets/manifest.yml +0 -5
- data/spec/dummy/script/rails +0 -6
- data/spec/ettu/fresh_when_spec.rb +0 -28
- data/spec/support/fixtures.rb +0 -38
- data/spec/support/include_hash.rb +0 -5
- data/spec/support/memory_store.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc3e36dd4f21333678bb4d88ad7a963040c6545
|
4
|
+
data.tar.gz: 85d2b61d41d2b4e8e28ce2c58355beb08fb6f282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6894aba4eda3847150eacd85f0cfbd725b3689219857d83221cf6662c6c9485a9df11dfcd56e1e446d6db15ee585935b938cfdfb798b1f731bd0b029d3570787
|
7
|
+
data.tar.gz: 88edb98c24ee25bed3f4194ec6a1d8b402d2516f9d345d45553f6882fd9603d7006a7071930a1c3dfd1adc9fc6b5d89da3e4988792bc8e0b27200bbb70eafe4e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
Ettu
|
1
|
+
Ettu
|
2
2
|
====
|
3
3
|
|
4
|
-
Using Rails
|
4
|
+
Using Rails 4's `stale?` or `fresh_when`? Are your users seeing old view
|
5
5
|
code even after new deploys? The Rails way `fresh_when(@product)`
|
6
6
|
doesn't account for changes in your view code, you have to do it
|
7
7
|
yourself.
|
@@ -19,10 +19,9 @@ changes to your view code.
|
|
19
19
|
Installation
|
20
20
|
------------
|
21
21
|
|
22
|
-
Add Ettu
|
23
|
-
your Gemfile:
|
22
|
+
Add Ettu to your Gemfile:
|
24
23
|
|
25
|
-
gem 'ettu'
|
24
|
+
gem 'ettu'
|
26
25
|
|
27
26
|
And `$ bundle install`
|
28
27
|
|
@@ -46,9 +45,10 @@ end
|
|
46
45
|
```
|
47
46
|
|
48
47
|
Ettu wants you to keep using either syntax, and let it worry about the
|
49
|
-
view code. By default, it will add in the fingerprints of
|
50
|
-
|
51
|
-
into the calculation for the final ETag sent to the
|
48
|
+
view code. By default, it will add in the asset fingerprints of
|
49
|
+
`application.js` and `application.css` along with the cache digest of
|
50
|
+
the current action into the calculation for the final ETag sent to the
|
51
|
+
browser.
|
52
52
|
|
53
53
|
### Configuring
|
54
54
|
|
@@ -67,24 +67,34 @@ Of course, you can override Ettu's default behavior:
|
|
67
67
|
```ruby
|
68
68
|
# config/initializers/ettu.rb
|
69
69
|
Ettu.configure do |config|
|
70
|
+
# Set the default js file
|
71
|
+
config.js = 'app.js'
|
72
|
+
# Or don't account for javascript
|
73
|
+
# config.js = false
|
74
|
+
|
75
|
+
# Set the default css file
|
76
|
+
config.css = 'style.css'
|
77
|
+
# Or don't account for css
|
78
|
+
# config.css = false
|
79
|
+
|
70
80
|
# Add in extra assets to account for
|
71
|
-
config.assets
|
81
|
+
config.assets = ['first.js', 'second.css']
|
72
82
|
end
|
73
83
|
```
|
74
84
|
|
75
85
|
Or each can be passed on an individual basis:
|
76
86
|
|
77
|
-
fresh_when @product, assets: 'super.css'
|
87
|
+
fresh_when @product, js: 'app.js', css: 'style.css', assets: 'super.css'
|
78
88
|
|
79
89
|
Additionally, you can specify a different template to calculate with the
|
80
90
|
`view` option:
|
81
91
|
|
82
|
-
fresh_when @product, view:
|
92
|
+
fresh_when @product, view: "products/index"
|
83
93
|
|
84
94
|
You can even stop Ettu from accounting for any of them by setting the
|
85
95
|
value to `false`:
|
86
96
|
|
87
|
-
fresh_when @product,
|
97
|
+
fresh_when @product, js: false, css: false, view: false
|
88
98
|
|
89
99
|
### What about Rails' default `fresh_when`?
|
90
100
|
|
@@ -93,16 +103,21 @@ implementation. Ettu makes sure to pass all the options you specify to
|
|
93
103
|
Rails (like the `public` option). It's even coded as a drop-in gem that
|
94
104
|
won't cause problems if it's not installed.
|
95
105
|
|
96
|
-
RAILS_ENV=development
|
97
|
-
|
106
|
+
RAILS_ENV=development Issues
|
107
|
+
----------------------------
|
108
|
+
|
109
|
+
Until [rails/rails#10791](https://github.com/rails/rails/pull/10791)
|
110
|
+
gets merged in, Ettu will not be able to detect changes in templates
|
111
|
+
while in the **development** environment. This is not an issue that
|
112
|
+
affects staging or production, because the template cache will be
|
113
|
+
recreated after each deploy.
|
98
114
|
|
99
|
-
In
|
100
|
-
in the **development** environment, you must disable `cache_template_loading`.
|
115
|
+
In the mean time, you can enable a monkey-patch with:
|
101
116
|
|
102
117
|
```ruby
|
103
118
|
# config/environments/development.rb
|
104
119
|
My::Application.configure do
|
105
|
-
config.
|
120
|
+
config.ettu.development_hack = true
|
106
121
|
end
|
107
122
|
```
|
108
123
|
|
data/ROADMAP.md
CHANGED
data/ettu.gemspec
CHANGED
@@ -8,7 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Ettu::VERSION
|
9
9
|
spec.author = 'Justin Ridgewell'
|
10
10
|
spec.email = 'jridgewell@cloudspace.com'
|
11
|
-
spec.
|
11
|
+
spec.description = %q{Account for js, css, and views when using ETags.}
|
12
|
+
spec.summary = %q{Account for view code when using ETags.}
|
12
13
|
spec.homepage = 'http://github.com/cloudspace/ettu'
|
13
14
|
spec.license = 'MIT'
|
14
15
|
|
@@ -18,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
18
19
|
|
19
20
|
spec.required_ruby_version = '>= 1.9'
|
20
21
|
|
21
|
-
spec.add_dependency 'rails', '~>
|
22
|
-
spec.add_dependency 'cache_digests'
|
22
|
+
spec.add_dependency 'rails', '~> 4.0'
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
26
27
|
end
|
data/lib/ettu/configuration.rb
CHANGED
@@ -13,7 +13,9 @@ class Ettu
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def set_defaults
|
16
|
-
self.
|
16
|
+
self.js = 'application.js'
|
17
|
+
self.css = 'application.css'
|
18
|
+
self.assets = []
|
17
19
|
|
18
20
|
# Don't actually set view by default.
|
19
21
|
# This'll allow #fetch to return the real default
|
@@ -21,42 +23,30 @@ class Ettu
|
|
21
23
|
# self.view = "#{controller_name}/#{action_name}"
|
22
24
|
delete :view if key? :view
|
23
25
|
|
24
|
-
|
26
|
+
# Don't attempt to reset the template_digestor
|
27
|
+
# if one has already been found
|
28
|
+
unless self.template_digestor
|
29
|
+
self.template_digestor = LateLoadTemplateDigestor.new(self)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
|
-
class
|
28
|
-
def initialize(config
|
33
|
+
class LateLoadTemplateDigestor
|
34
|
+
def initialize(config)
|
29
35
|
@config = config
|
30
|
-
@name = name
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_missing(method, *args, &block)
|
34
|
-
late_load = defaults
|
35
|
-
@config[@name] = late_load
|
36
|
-
late_load.send method, *args, &block
|
37
36
|
end
|
38
|
-
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def digest(*args)
|
39
|
+
digestor = attempt_late_template_digestor_set
|
40
|
+
digestor.digest(*args)
|
43
41
|
end
|
44
42
|
|
45
|
-
|
46
|
-
::Rails.application.config.assets.digests.try(:keys) || []
|
47
|
-
end
|
48
|
-
end
|
43
|
+
private
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
require 'cache_digests'
|
45
|
+
def attempt_late_template_digestor_set
|
46
|
+
# Attempt to use ActionView::Digestor
|
47
|
+
if defined? ActionView::Digestor
|
48
|
+
@config.template_digestor = ActionView::Digestor
|
55
49
|
end
|
56
|
-
# Attempt to use CacheDigests::TemplateDigestor on Rails 3
|
57
|
-
::CacheDigests::TemplateDigestor
|
58
|
-
rescue LoadError
|
59
|
-
raise "Ettu requires the cache_digests gem in Rails v#{Rails::VERSION::STRING}"
|
60
50
|
end
|
61
51
|
end
|
62
52
|
end
|
data/lib/ettu/fresh_when.rb
CHANGED
@@ -2,12 +2,22 @@ class Ettu
|
|
2
2
|
module FreshWhen
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
included do
|
6
|
+
alias_method :old_fresh_when, :fresh_when
|
7
7
|
|
8
|
-
|
8
|
+
def fresh_when(record_or_options, additional_options = {})
|
9
|
+
ettu = ettu_instance(record_or_options, additional_options, self)
|
9
10
|
|
10
|
-
|
11
|
+
ettu_params = {etag: ettu.etags, last_modified: ettu.last_modified}
|
12
|
+
|
13
|
+
old_fresh_when nil, ettu.options.merge(ettu_params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ettu_instance(record_or_options, additional_options, controller)
|
20
|
+
Ettu.new record_or_options, additional_options, controller
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
data/lib/ettu/railtie.rb
CHANGED
@@ -9,6 +9,17 @@ class Ettu
|
|
9
9
|
ActiveSupport.on_load :action_controller do
|
10
10
|
ActionController::Base.send :include, FreshWhen
|
11
11
|
end
|
12
|
+
|
13
|
+
if app.config.ettu.development_hack
|
14
|
+
class BlackHole < Hash
|
15
|
+
def []=(k, v); end
|
16
|
+
end
|
17
|
+
module ::ActionView
|
18
|
+
class Digestor
|
19
|
+
@@cache = BlackHole.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
12
23
|
end
|
13
24
|
|
14
25
|
end
|
data/lib/ettu/version.rb
CHANGED
data/lib/ettu.rb
CHANGED
@@ -32,8 +32,11 @@ class Ettu
|
|
32
32
|
def etags
|
33
33
|
etags = [*response_etag]
|
34
34
|
etags << view_etag
|
35
|
+
if @controller.request.format.try(:html?)
|
36
|
+
etags << js_etag
|
37
|
+
etags << css_etag
|
38
|
+
end
|
35
39
|
etags.concat asset_etags
|
36
|
-
etags.compact
|
37
40
|
end
|
38
41
|
|
39
42
|
def last_modified
|
@@ -50,6 +53,16 @@ class Ettu
|
|
50
53
|
@view_etag ||= view_digest(view)
|
51
54
|
end
|
52
55
|
|
56
|
+
def js_etag
|
57
|
+
js = @options.fetch(:js, @@config.js)
|
58
|
+
asset_etag js
|
59
|
+
end
|
60
|
+
|
61
|
+
def css_etag
|
62
|
+
css = @options.fetch(:css, @@config.css)
|
63
|
+
asset_etag css
|
64
|
+
end
|
65
|
+
|
53
66
|
def asset_etags
|
54
67
|
assets = @options.fetch(:assets, @@config.assets)
|
55
68
|
[*assets].map { |asset| asset_etag(asset) }
|
@@ -78,11 +91,10 @@ class Ettu
|
|
78
91
|
def asset_digest(asset)
|
79
92
|
return nil unless asset.present?
|
80
93
|
# Check already computed assets (production)
|
81
|
-
|
82
|
-
if digest = manifest.try(:[], asset)
|
94
|
+
if digest = ActionView::Base.assets_manifest.assets[asset]
|
83
95
|
digest
|
84
96
|
else
|
85
|
-
# Compute it
|
97
|
+
# Compute it
|
86
98
|
Rails.application.assets[asset].digest
|
87
99
|
end
|
88
100
|
end
|
@@ -1,35 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ettu do
|
4
|
-
subject(:ettu) { Ettu.new(hash, {}, controller) }
|
5
|
-
|
6
4
|
let(:controller) { Controller.new }
|
7
5
|
let(:record) { Record.new(DateTime.now) }
|
8
6
|
let(:hash) { { etag: record, last_modified: DateTime.now } }
|
7
|
+
before(:all) do
|
8
|
+
Ettu.configure { |config| config.template_digestor = Digestor }
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let(:assets) { Rails.application.config.assets.digests }
|
14
|
-
let(:files) { assets.keys.reject { |f| f[/index/] } }
|
15
|
-
let(:digests) { assets.values }
|
11
|
+
context 'when supplied with options' do
|
12
|
+
let(:hash) { { js: 'custom.js', css: 'custom.css', assets: 'first.ext', view: 'custom/action' } }
|
13
|
+
subject(:ettu) { Ettu.new(hash, {}, controller) }
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
config.reset
|
20
|
-
config.template_digestor = Digestor
|
15
|
+
it 'will use :js option over default' do
|
16
|
+
expect(ettu.js_etag).to eq('custom.js.digest')
|
21
17
|
end
|
22
|
-
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
context 'when supplied with options' do
|
29
|
-
let(:hash) { { assets: files.first, view: 'custom/action' } }
|
19
|
+
it 'will use :css option over default' do
|
20
|
+
expect(ettu.css_etag).to eq('custom.css.digest')
|
21
|
+
end
|
30
22
|
|
31
23
|
it 'will use :asset option over default' do
|
32
|
-
expect(ettu.asset_etags).to eq([
|
24
|
+
expect(ettu.asset_etags).to eq(['first.ext.digest'])
|
33
25
|
end
|
34
26
|
|
35
27
|
it 'will use :view option over default' do
|
@@ -37,84 +29,68 @@ describe Ettu do
|
|
37
29
|
end
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# It was added AFTER running `rake assets:precompile` (which compiled
|
44
|
-
# application.js and application.css).
|
45
|
-
def hash; { assets: 'test.js' }; end
|
46
|
-
|
47
|
-
expect(ettu.asset_etags).not_to be_empty
|
48
|
-
end
|
32
|
+
describe '.configure' do
|
33
|
+
subject(:ettu) { Ettu.new(nil, {}, controller) }
|
34
|
+
after(:all) { Ettu.configure { |config| config.reset } }
|
49
35
|
|
50
|
-
|
51
|
-
|
36
|
+
context 'when no options are specified' do
|
37
|
+
before(:all) do
|
38
|
+
Ettu.configure do |config|
|
39
|
+
config.js = 'custom.js'
|
40
|
+
config.css = 'custom.css'
|
41
|
+
config.assets = ['first.ext', 'second.ext']
|
42
|
+
config.view = 'custom/view'
|
43
|
+
end
|
44
|
+
end
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
it 'will use the default js file' do
|
47
|
+
expect(ettu.js_etag).to eq('custom.js.digest')
|
48
|
+
end
|
56
49
|
|
57
|
-
|
58
|
-
|
50
|
+
it 'will use the default css file' do
|
51
|
+
expect(ettu.css_etag).to eq('custom.css.digest')
|
52
|
+
end
|
59
53
|
|
60
|
-
context 'when no options are specified' do
|
61
54
|
it 'will use the default asset files' do
|
62
|
-
expect(ettu.asset_etags).to eq(
|
55
|
+
expect(ettu.asset_etags).to eq(['first.ext.digest', 'second.ext.digest'])
|
63
56
|
end
|
64
57
|
|
65
58
|
it 'will use the default view file' do
|
66
|
-
Ettu.configure { |config| config.view = 'custom/view' }
|
67
|
-
|
68
59
|
expect(ettu.view_etag).to eq('custom/view.digest')
|
69
60
|
end
|
70
61
|
end
|
71
62
|
|
72
|
-
context '
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
63
|
+
context 'when setting default to false' do
|
64
|
+
before(:all) do
|
65
|
+
Ettu.configure do |config|
|
66
|
+
config.js = false
|
67
|
+
config.css = false
|
68
|
+
config.view = false
|
69
|
+
end
|
79
70
|
end
|
80
71
|
|
81
|
-
it '
|
82
|
-
|
83
|
-
expect(configuration.assets).to include(random_string)
|
72
|
+
it 'will disable js etag' do
|
73
|
+
expect(ettu.js_etag).to eq(nil)
|
84
74
|
end
|
85
|
-
end
|
86
75
|
|
87
|
-
|
88
|
-
|
89
|
-
Ettu.configure { |config| config.assets = false }
|
90
|
-
|
91
|
-
expect(ettu.asset_etags).to eq([nil])
|
76
|
+
it 'will disable css etag' do
|
77
|
+
expect(ettu.css_etag).to eq(nil)
|
92
78
|
end
|
93
79
|
|
94
80
|
it 'will disable view etags' do
|
95
|
-
Ettu.configure { |config| config.view = false }
|
96
|
-
|
97
81
|
expect(ettu.view_etag).to eq(nil)
|
98
82
|
end
|
99
83
|
end
|
100
84
|
end
|
101
85
|
|
102
86
|
describe '#etags' do
|
103
|
-
|
104
|
-
|
87
|
+
let(:ettu) { Ettu.new(record, {}, controller) }
|
105
88
|
it 'will collect all etags' do
|
106
|
-
expected = [record, 'controller_name/action_name.digest'
|
89
|
+
expected = [record, 'controller_name/action_name.digest', 'application.js.digest', 'application.css.digest']
|
107
90
|
result = ettu.etags
|
108
|
-
|
109
|
-
expect(result).to include(*expected)
|
91
|
+
expect(ettu.etags).to include(*expected)
|
110
92
|
expect(expected).to include(*result)
|
111
93
|
end
|
112
|
-
|
113
|
-
it 'will not allow nils' do
|
114
|
-
ettu = Ettu.new(nil, {assets: [nil, nil, nil]}, controller )
|
115
|
-
|
116
|
-
expect(ettu.etags).not_to include(nil)
|
117
|
-
end
|
118
94
|
end
|
119
95
|
|
120
96
|
context 'when given only a record' do
|
data/spec/fixtures.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
class Nester < ActiveSupport::OrderedOptions
|
2
|
+
def initialize
|
3
|
+
super { |h, k| h[k] = Nester.new }
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Controller < Nester
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
|
11
|
+
self.request.format['html?'] = true
|
12
|
+
self.controller_name = 'controller_name'
|
13
|
+
self.action_name = 'action_name'
|
14
|
+
end
|
15
|
+
|
16
|
+
def fresh_when(*args)
|
17
|
+
:old_fresh_when
|
18
|
+
end
|
19
|
+
|
20
|
+
include ::Ettu::FreshWhen
|
21
|
+
end
|
22
|
+
|
23
|
+
class Digestor
|
24
|
+
def self.method_missing(name, *args, &block)
|
25
|
+
args.first.to_s + '.digest'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Record
|
30
|
+
attr_accessor :updated_at
|
31
|
+
|
32
|
+
def initialize(updated_at)
|
33
|
+
@updated_at = updated_at
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Rails
|
38
|
+
module VERSION
|
39
|
+
MAJOR = ''
|
40
|
+
end
|
41
|
+
def self.application
|
42
|
+
@nested ||= Nester.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
Rails.application.assets['application.js'].digest = 'application.js.digest'
|
46
|
+
Rails.application.assets['application.css'].digest = 'application.css.digest'
|
47
|
+
Rails.application.assets['custom.js'].digest = 'custom.js.digest'
|
48
|
+
Rails.application.assets['custom.css'].digest = 'custom.css.digest'
|
49
|
+
Rails.application.assets['first.ext'].digest = 'first.ext.digest'
|
50
|
+
Rails.application.assets['second.ext'].digest = 'second.ext.digest'
|
51
|
+
Rails.application.config.assets.digests = nil
|
52
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Ettu::FreshWhen do
|
5
|
+
before(:all) do
|
6
|
+
Ettu.configure { |config| config.template_digestor = Digestor }
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:ettu) { double }
|
10
|
+
let(:record) { Record.new(DateTime.now) }
|
11
|
+
let(:hash) { { random: true, options: true } }
|
12
|
+
subject(:controller) { Controller.new }
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
controller.stub(ettu_instance: ettu)
|
16
|
+
ettu.stub(:etags)
|
17
|
+
ettu.stub(:last_modified)
|
18
|
+
ettu.stub(options: {})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'calls Ettu#etags' do
|
22
|
+
ettu.should_receive(:etags)
|
23
|
+
controller.fresh_when record, hash
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'calls Ettu#last_modified' do
|
27
|
+
ettu.should_receive(:last_modified)
|
28
|
+
controller.fresh_when record, hash
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'passes nil as the first argument to original fresh_when' do
|
32
|
+
controller.should_receive(:old_fresh_when) do |r, h|
|
33
|
+
r.nil?
|
34
|
+
end
|
35
|
+
controller.fresh_when record, hash
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'passes extra options to original fresh_when' do
|
39
|
+
controller.should_receive(:old_fresh_when) do |r, h|
|
40
|
+
hash.each_pair.all? do |k, v|
|
41
|
+
h[k] == v
|
42
|
+
end
|
43
|
+
end
|
44
|
+
controller.fresh_when record, hash
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,29 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
5
8
|
require 'date'
|
6
9
|
require 'active_support/ordered_options'
|
7
|
-
require 'securerandom'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
Dir[File.join(File.expand_path('..', __FILE__), 'support/**/*.rb')].each { |f| require f }
|
11
|
+
require 'simplecov'
|
12
|
+
SimpleCov.start { add_filter '/spec/' }
|
12
13
|
|
13
14
|
require 'ettu'
|
14
|
-
|
15
|
+
require 'fixtures'
|
15
16
|
|
16
17
|
RSpec.configure do |config|
|
17
18
|
config.run_all_when_everything_filtered = true
|
18
|
-
|
19
|
-
# If true, the base class of anonymous controllers will be inferred
|
20
|
-
# automatically. This will be the default behavior in future versions of
|
21
|
-
# rspec-rails.
|
22
|
-
config.infer_base_class_for_anonymous_controllers = false
|
23
|
-
|
24
|
-
# Run specs in random order to surface order dependencies. If you find an
|
25
|
-
# order dependency and want to debug it, you can fix the order by providing
|
26
|
-
# the seed, which is printed after each run.
|
27
|
-
# --seed 1234
|
28
19
|
config.order = 'random'
|
29
20
|
end
|