ettu 4.1.6 → 4.1.7
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -1
- data/Appraisals +7 -0
- data/README.md +6 -13
- data/Rakefile +2 -0
- data/ettu.gemspec +3 -4
- data/gemfiles/4.0.gemfile +7 -0
- data/gemfiles/4.1.gemfile +7 -0
- data/lib/ettu/configuration.rb +7 -8
- data/lib/ettu/version.rb +1 -1
- data/spec/controllers/users_controller_spec.rb +66 -0
- data/spec/dummy/.gitignore +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/test.js +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +13 -0
- data/spec/dummy/app/controllers/users_controller.rb +9 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/users/index.html.erb +1 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/.keep +0 -0
- data/spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js +15 -0
- data/spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js.gz +0 -0
- data/spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css +14 -0
- data/spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css.gz +0 -0
- data/spec/dummy/public/assets/manifest-1b849aba8a84c4520cb7bc4fafa638c3.json +1 -0
- data/spec/{ettu_spec.rb → ettu/ettu_spec.rb} +51 -36
- data/spec/{fresh_when_spec.rb → ettu/fresh_when_spec.rb} +4 -0
- data/spec/spec_helper.rb +18 -17
- data/spec/support/fixtures.rb +38 -0
- data/spec/support/include_hash.rb +5 -0
- metadata +70 -13
- data/spec/fixtures.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd89c40045ea90c43db793ad2f85e69d2b62ba19
|
4
|
+
data.tar.gz: 7767fc54271d478182c3fa0f4969a07cc2336f53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05afbf54e850686a647f82999d4232792b985f8a27cbea0942e5bdebd9fc77bb9981f4a101a11a55ccbfd81c5e9c803e061aa3c05a432f24cb450a8c25d293ac
|
7
|
+
data.tar.gz: 284bccf8fd752796bcbe84d5c5c88ac447727e2a81d98d536011e9c87aad70def0a55fc23aa7987663a6118b76f4e7dc8947dccbc3c2a93039ceb549e96e4319
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
Ettu
|
1
|
+
Ettu [](https://travis-ci.org/cloudspace/ettu)
|
2
2
|
====
|
3
3
|
|
4
|
-
[](https://travis-ci.org/cloudspace/ettu)
|
5
|
-
|
6
4
|
Using Rails 4's `stale?` or `fresh_when`? Are your users seeing old view
|
7
5
|
code even after new deploys? The Rails way `fresh_when(@product)`
|
8
6
|
doesn't account for changes in your view code, you have to do it
|
@@ -100,21 +98,16 @@ implementation. Ettu makes sure to pass all the options you specify to
|
|
100
98
|
Rails (like the `public` option). It's even coded as a drop-in gem that
|
101
99
|
won't cause problems if it's not installed.
|
102
100
|
|
103
|
-
RAILS_ENV=development
|
104
|
-
|
105
|
-
|
106
|
-
Until [rails/rails#11768](https://github.com/rails/rails/pull/11768)
|
107
|
-
gets merged in, Ettu will not be able to detect changes in templates
|
108
|
-
while in the **development** environment. This is not an issue that
|
109
|
-
affects staging or production, because the template cache will be
|
110
|
-
flushed after each deploy.
|
101
|
+
RAILS_ENV=development Gotchas
|
102
|
+
-----------------------------
|
111
103
|
|
112
|
-
In
|
104
|
+
In order for Rails to detect changes to templates when testing `perform_caching`
|
105
|
+
in the **development** environment, you must disable `cache_template_loading`.
|
113
106
|
|
114
107
|
```ruby
|
115
108
|
# config/environments/development.rb
|
116
109
|
My::Application.configure do
|
117
|
-
config.
|
110
|
+
config.action_view.cache_template_loading = false
|
118
111
|
end
|
119
112
|
```
|
120
113
|
|
data/Rakefile
CHANGED
data/ettu.gemspec
CHANGED
@@ -8,8 +8,7 @@ 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.
|
12
|
-
spec.summary = %q{Account for view code when using ETags.}
|
11
|
+
spec.summary = %q{Add Assets and Views into the Rails ETag Equation.}
|
13
12
|
spec.homepage = 'http://github.com/cloudspace/ettu'
|
14
13
|
spec.license = 'MIT'
|
15
14
|
|
@@ -22,6 +21,6 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.add_dependency 'rails', '~> 4.0'
|
23
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
23
|
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency '
|
24
|
+
spec.add_development_dependency 'rspec-rails'
|
25
|
+
spec.add_development_dependency 'appraisal'
|
27
26
|
end
|
data/lib/ettu/configuration.rb
CHANGED
@@ -21,7 +21,7 @@ class Ettu
|
|
21
21
|
# self.view = "#{controller_name}/#{action_name}"
|
22
22
|
delete :view if key? :view
|
23
23
|
|
24
|
-
self.template_digestor =
|
24
|
+
self.template_digestor = LateLoadTemplateDigestor.new(self, :template_digestor)
|
25
25
|
end
|
26
26
|
|
27
27
|
class LateLoad
|
@@ -37,14 +37,7 @@ class Ettu
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
class LateLoadTempalteDigestor < LateLoad
|
41
|
-
def defaults
|
42
|
-
::ActionView::Digestor
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
40
|
class LateLoadAssets < LateLoad
|
47
|
-
|
48
41
|
def to_a
|
49
42
|
super
|
50
43
|
end
|
@@ -53,5 +46,11 @@ class Ettu
|
|
53
46
|
::ActionView::Base.assets_manifest.assets.keys
|
54
47
|
end
|
55
48
|
end
|
49
|
+
|
50
|
+
class LateLoadTemplateDigestor < LateLoad
|
51
|
+
def defaults
|
52
|
+
::ActionView::Digestor
|
53
|
+
end
|
54
|
+
end
|
56
55
|
end
|
57
56
|
end
|
data/lib/ettu/version.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
#
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
19
|
+
# that an instance is receiving a specific message.
|
20
|
+
|
21
|
+
describe UsersController do
|
22
|
+
|
23
|
+
describe 'Integration Test' do
|
24
|
+
before(:each) { get :index }
|
25
|
+
subject(:hash) { assigns(:user) }
|
26
|
+
subject(:user) { User.instance }
|
27
|
+
|
28
|
+
it 'returns fresh_when hash' do
|
29
|
+
expect(hash).to be_a(Hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'hash[:etag]' do
|
33
|
+
subject(:etags) { hash[:etag] }
|
34
|
+
|
35
|
+
it 'sets :etag to array' do
|
36
|
+
expect(etags).to be_a(Array)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'includes records cache_key' do
|
40
|
+
expect(etags).to include(user.cache_key)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'includes all views digest' do
|
44
|
+
path = controller.request.path_parameters
|
45
|
+
page = ::ActionView::Digestor.cache.keys.first
|
46
|
+
|
47
|
+
expect(page).to match(/#{path['controller']}\/#{path['action']}/)
|
48
|
+
expect(etags).to include(::ActionView::Digestor.cache[page])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'includes all asset digests' do
|
52
|
+
expect(etags).to include(*(::ActionView::Base.assets_manifest.assets.values))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'hash[:last_modified]' do
|
57
|
+
subject(:last_modified) { hash[:last_modified] }
|
58
|
+
|
59
|
+
it 'sets last_modified to records updated_at' do
|
60
|
+
expect(last_modified).to eq(user.updated_at)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
14
|
+
|
15
|
+
var test = true;
|
@@ -0,0 +1 @@
|
|
1
|
+
var test2 = true;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
end
|
6
|
+
|
7
|
+
module ::ActionController
|
8
|
+
module ConditionalGet
|
9
|
+
def fresh_when(*args)
|
10
|
+
[*args].last
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Users Index</h1>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
# require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
# require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
Bundler.require(*Rails.groups)
|
11
|
+
require "ettu"
|
12
|
+
|
13
|
+
module Dummy
|
14
|
+
class Application < Rails::Application
|
15
|
+
# Settings in config/environments/* take precedence over those specified here.
|
16
|
+
# Application configuration should go into files in config/initializers
|
17
|
+
# -- all .rb files in that directory are automatically loaded.
|
18
|
+
|
19
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
20
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
21
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
22
|
+
|
23
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
24
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
25
|
+
# config.i18n.default_locale = :de
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_assets = true
|
17
|
+
config.static_cache_control = "public, max-age=3600"
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
+
# The :test delivery method accumulates sent emails in the
|
31
|
+
# ActionMailer::Base.deliveries array.
|
32
|
+
config.action_mailer.delivery_method = :test
|
33
|
+
|
34
|
+
# Print deprecation notices to the stderr.
|
35
|
+
config.active_support.deprecation = :stderr
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure your secret_key_base is kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
Dummy::Application.config.secret_key_base = 'aaf99661e9b1020f700b99f4be4677c0d2d0afeecebbcadb665bc71eb9fe9a9fdd710ba84a3c5467c0a6432feda39eafa6901e987ef6bc18678c3c1cb1f982bf'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
data/spec/dummy/db/.keep
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
|
14
|
+
|
15
|
+
var test = true;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
|
12
|
+
|
13
|
+
*/
|
14
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
{"files":{"application-90b1f92061b701bdbc2f2c364a42eed3.js":{"logical_path":"application.js","mtime":"2014-03-12T14:36:29-04:00","size":599,"digest":"90b1f92061b701bdbc2f2c364a42eed3"},"application-a029bd03bea21da7d02c0e9d272edc3a.css":{"logical_path":"application.css","mtime":"2014-03-12T14:17:39-04:00","size":513,"digest":"a029bd03bea21da7d02c0e9d272edc3a"}},"assets":{"application.js":"application-90b1f92061b701bdbc2f2c364a42eed3.js","application.css":"application-a029bd03bea21da7d02c0e9d272edc3a.css"}}
|
@@ -1,19 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ettu do
|
4
|
+
subject(:ettu) { Ettu.new(hash, {}, controller) }
|
5
|
+
|
4
6
|
let(:controller) { Controller.new }
|
5
7
|
let(:record) { Record.new(DateTime.now) }
|
6
8
|
let(:hash) { { etag: record, last_modified: DateTime.now } }
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
# NOTE: assets were created by running `rake assets:precompile`.
|
11
|
+
# It compiled application.js and application.css (but NOT
|
12
|
+
# test.js)
|
13
|
+
let(:assets) { ::ActionView::Base.assets_manifest.assets }
|
14
|
+
let(:files) { assets.keys }
|
15
|
+
let(:digests) { assets.values }
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
Ettu.configure do |config|
|
19
|
+
config.reset
|
20
|
+
config.template_digestor = Digestor
|
11
21
|
end
|
12
|
-
|
13
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:all) do
|
25
|
+
Ettu.configure { |config| config.reset }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when supplied with options' do
|
29
|
+
let(:hash) { { assets: files.first, view: 'custom/action' } }
|
14
30
|
|
15
31
|
it 'will use :asset option over default' do
|
16
|
-
expect(ettu.asset_etags).to eq([
|
32
|
+
expect(ettu.asset_etags).to eq([digests.first])
|
17
33
|
end
|
18
34
|
|
19
35
|
it 'will use :view option over default' do
|
@@ -21,26 +37,34 @@ describe Ettu do
|
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
40
|
+
context 'when given asset that is not precompiled' do
|
41
|
+
it 'will digest the file if it exists' do
|
42
|
+
# NOTE: test.js is located at dummy/app/assets/javascripts/test.js
|
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
|
28
48
|
end
|
29
|
-
after(:all) { Ettu.configure { |config| config.reset } }
|
30
49
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
50
|
+
it 'will throw error if file does not exist' do
|
51
|
+
def hash; { assets: 'does_not_exist' }; end
|
52
|
+
|
53
|
+
expect{ ettu.asset_etags }.to raise_error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.configure' do
|
58
|
+
let(:hash) { nil }
|
38
59
|
|
60
|
+
context 'when no options are specified' do
|
39
61
|
it 'will use the default asset files' do
|
40
|
-
expect(ettu.asset_etags).to eq(
|
62
|
+
expect(ettu.asset_etags).to eq(digests)
|
41
63
|
end
|
42
64
|
|
43
65
|
it 'will use the default view file' do
|
66
|
+
Ettu.configure { |config| config.view = 'custom/view' }
|
67
|
+
|
44
68
|
expect(ettu.view_etag).to eq('custom/view.digest')
|
45
69
|
end
|
46
70
|
end
|
@@ -61,43 +85,34 @@ describe Ettu do
|
|
61
85
|
end
|
62
86
|
|
63
87
|
context 'when setting default to false' do
|
64
|
-
before(:all) do
|
65
|
-
Ettu.configure do |config|
|
66
|
-
config.assets = false
|
67
|
-
config.view = false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
88
|
it 'will disable asset etags' do
|
89
|
+
Ettu.configure { |config| config.assets = false }
|
90
|
+
|
72
91
|
expect(ettu.asset_etags).to eq([nil])
|
73
92
|
end
|
74
93
|
|
75
94
|
it 'will disable view etags' do
|
95
|
+
Ettu.configure { |config| config.view = false }
|
96
|
+
|
76
97
|
expect(ettu.view_etag).to eq(nil)
|
77
98
|
end
|
78
99
|
end
|
79
100
|
end
|
80
101
|
|
81
102
|
describe '#etags' do
|
82
|
-
|
83
|
-
Ettu.configure { |config| config.template_digestor = Digestor }
|
84
|
-
end
|
85
|
-
let(:ettu) { Ettu.new(record, {}, controller) }
|
103
|
+
subject(:ettu) { Ettu.new(record, {}, controller) }
|
86
104
|
|
87
105
|
it 'will collect all etags' do
|
88
|
-
expected = [
|
89
|
-
record, 'controller_name/action_name.digest',
|
90
|
-
'application.js.manifest', 'application.css.manifest',
|
91
|
-
'custom.js.manifest', 'custom.css.manifest',
|
92
|
-
'first.ext.manifest', 'second.ext.manifest'
|
93
|
-
]
|
106
|
+
expected = [record, 'controller_name/action_name.digest'] | digests
|
94
107
|
result = ettu.etags
|
108
|
+
|
95
109
|
expect(result).to include(*expected)
|
96
110
|
expect(expected).to include(*result)
|
97
111
|
end
|
98
112
|
|
99
113
|
it 'will not allow nils' do
|
100
114
|
ettu = Ettu.new(nil, {assets: [nil, nil, nil]}, controller )
|
115
|
+
|
101
116
|
expect(ettu.etags).not_to include(nil)
|
102
117
|
end
|
103
118
|
end
|
@@ -6,6 +6,10 @@ describe Ettu::FreshWhen do
|
|
6
6
|
Ettu.configure { |config| config.template_digestor = Digestor }
|
7
7
|
end
|
8
8
|
|
9
|
+
after(:all) do
|
10
|
+
Ettu.configure { |config| config.reset }
|
11
|
+
end
|
12
|
+
|
9
13
|
let(:record) { Record.new(DateTime.now) }
|
10
14
|
let(:hash) { { random: true, options: true } }
|
11
15
|
subject(:controller) { Controller.new }
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
-
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
3
|
+
require 'rspec/rails'
|
4
|
+
require 'rspec/autorun'
|
8
5
|
require 'date'
|
9
6
|
require 'active_support/ordered_options'
|
10
7
|
require 'securerandom'
|
11
|
-
RSpec::Matchers.define :include_hash do |expected|
|
12
|
-
match do |actual|
|
13
|
-
!actual.nil? &&
|
14
|
-
!actual.empty? &&
|
15
|
-
(actual.to_a & expected.to_a) == expected.to_a
|
16
|
-
end
|
17
|
-
end
|
18
8
|
|
19
|
-
|
20
|
-
|
9
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
10
|
+
# in spec/support/ and its subdirectories.
|
11
|
+
Dir[File.join(File.expand_path('..', __FILE__), 'support/**/*.rb')].each { |f| require f }
|
21
12
|
|
22
13
|
require 'ettu'
|
23
|
-
|
14
|
+
|
24
15
|
|
25
16
|
RSpec.configure do |config|
|
26
17
|
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
|
27
28
|
config.order = 'random'
|
28
29
|
end
|
@@ -0,0 +1,38 @@
|
|
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'
|
12
|
+
self.controller_name = 'controller_name'
|
13
|
+
self.action_name = 'action_name'
|
14
|
+
end
|
15
|
+
|
16
|
+
module Freshness
|
17
|
+
def fresh_when(*args)
|
18
|
+
[*args]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
include Freshness
|
22
|
+
|
23
|
+
include ::Ettu::FreshWhen
|
24
|
+
end
|
25
|
+
|
26
|
+
class Digestor
|
27
|
+
def self.method_missing(name, *args, &block)
|
28
|
+
args.first.to_s + '.digest'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Record
|
33
|
+
attr_accessor :updated_at
|
34
|
+
|
35
|
+
def initialize(updated_at)
|
36
|
+
@updated_at = updated_at
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ettu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ridgewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
56
|
+
name: rspec-rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: appraisal
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email: jridgewell@cloudspace.com
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
@@ -89,21 +89,51 @@ files:
|
|
89
89
|
- .gitignore
|
90
90
|
- .rspec
|
91
91
|
- .travis.yml
|
92
|
+
- Appraisals
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
95
96
|
- ROADMAP.md
|
96
97
|
- Rakefile
|
97
98
|
- ettu.gemspec
|
99
|
+
- gemfiles/4.0.gemfile
|
100
|
+
- gemfiles/4.1.gemfile
|
98
101
|
- lib/ettu.rb
|
99
102
|
- lib/ettu/configuration.rb
|
100
103
|
- lib/ettu/fresh_when.rb
|
101
104
|
- lib/ettu/railtie.rb
|
102
105
|
- lib/ettu/version.rb
|
103
|
-
- spec/
|
104
|
-
- spec/
|
105
|
-
- spec/
|
106
|
+
- spec/controllers/users_controller_spec.rb
|
107
|
+
- spec/dummy/.gitignore
|
108
|
+
- spec/dummy/Rakefile
|
109
|
+
- spec/dummy/app/assets/javascripts/application.js
|
110
|
+
- spec/dummy/app/assets/javascripts/test.js
|
111
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
112
|
+
- spec/dummy/app/controllers/application_controller.rb
|
113
|
+
- spec/dummy/app/controllers/users_controller.rb
|
114
|
+
- spec/dummy/app/models/user.rb
|
115
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
116
|
+
- spec/dummy/app/views/users/index.html.erb
|
117
|
+
- spec/dummy/config.ru
|
118
|
+
- spec/dummy/config/application.rb
|
119
|
+
- spec/dummy/config/boot.rb
|
120
|
+
- spec/dummy/config/environment.rb
|
121
|
+
- spec/dummy/config/environments/test.rb
|
122
|
+
- spec/dummy/config/initializers/secret_token.rb
|
123
|
+
- spec/dummy/config/initializers/session_store.rb
|
124
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
125
|
+
- spec/dummy/config/routes.rb
|
126
|
+
- spec/dummy/db/.keep
|
127
|
+
- spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js
|
128
|
+
- spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js.gz
|
129
|
+
- spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css
|
130
|
+
- spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css.gz
|
131
|
+
- spec/dummy/public/assets/manifest-1b849aba8a84c4520cb7bc4fafa638c3.json
|
132
|
+
- spec/ettu/ettu_spec.rb
|
133
|
+
- spec/ettu/fresh_when_spec.rb
|
106
134
|
- spec/spec_helper.rb
|
135
|
+
- spec/support/fixtures.rb
|
136
|
+
- spec/support/include_hash.rb
|
107
137
|
homepage: http://github.com/cloudspace/ettu
|
108
138
|
licenses:
|
109
139
|
- MIT
|
@@ -124,12 +154,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
154
|
version: '0'
|
125
155
|
requirements: []
|
126
156
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.0.
|
157
|
+
rubygems_version: 2.0.2
|
128
158
|
signing_key:
|
129
159
|
specification_version: 4
|
130
|
-
summary:
|
160
|
+
summary: Add Assets and Views into the Rails ETag Equation.
|
131
161
|
test_files:
|
132
|
-
- spec/
|
133
|
-
- spec/
|
134
|
-
- spec/
|
162
|
+
- spec/controllers/users_controller_spec.rb
|
163
|
+
- spec/dummy/.gitignore
|
164
|
+
- spec/dummy/Rakefile
|
165
|
+
- spec/dummy/app/assets/javascripts/application.js
|
166
|
+
- spec/dummy/app/assets/javascripts/test.js
|
167
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
168
|
+
- spec/dummy/app/controllers/application_controller.rb
|
169
|
+
- spec/dummy/app/controllers/users_controller.rb
|
170
|
+
- spec/dummy/app/models/user.rb
|
171
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
172
|
+
- spec/dummy/app/views/users/index.html.erb
|
173
|
+
- spec/dummy/config.ru
|
174
|
+
- spec/dummy/config/application.rb
|
175
|
+
- spec/dummy/config/boot.rb
|
176
|
+
- spec/dummy/config/environment.rb
|
177
|
+
- spec/dummy/config/environments/test.rb
|
178
|
+
- spec/dummy/config/initializers/secret_token.rb
|
179
|
+
- spec/dummy/config/initializers/session_store.rb
|
180
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
181
|
+
- spec/dummy/config/routes.rb
|
182
|
+
- spec/dummy/db/.keep
|
183
|
+
- spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js
|
184
|
+
- spec/dummy/public/assets/application-90b1f92061b701bdbc2f2c364a42eed3.js.gz
|
185
|
+
- spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css
|
186
|
+
- spec/dummy/public/assets/application-a029bd03bea21da7d02c0e9d272edc3a.css.gz
|
187
|
+
- spec/dummy/public/assets/manifest-1b849aba8a84c4520cb7bc4fafa638c3.json
|
188
|
+
- spec/ettu/ettu_spec.rb
|
189
|
+
- spec/ettu/fresh_when_spec.rb
|
135
190
|
- spec/spec_helper.rb
|
191
|
+
- spec/support/fixtures.rb
|
192
|
+
- spec/support/include_hash.rb
|
data/spec/fixtures.rb
DELETED
@@ -1,66 +0,0 @@
|
|
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
|
-
module Freshness
|
17
|
-
def fresh_when(*args)
|
18
|
-
[*args]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
include Freshness
|
22
|
-
|
23
|
-
include ::Ettu::FreshWhen
|
24
|
-
end
|
25
|
-
|
26
|
-
class Digestor
|
27
|
-
def self.method_missing(name, *args, &block)
|
28
|
-
args.first.to_s + '.digest'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Record
|
33
|
-
attr_accessor :updated_at
|
34
|
-
|
35
|
-
def initialize(updated_at)
|
36
|
-
@updated_at = updated_at
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
module Rails
|
41
|
-
module VERSION
|
42
|
-
MAJOR = ''
|
43
|
-
end
|
44
|
-
def self.application
|
45
|
-
@nested ||= Nester.new
|
46
|
-
end
|
47
|
-
end
|
48
|
-
Rails.application.assets['application.js'].digest = 'application.js.digest'
|
49
|
-
Rails.application.assets['application.css'].digest = 'application.css.digest'
|
50
|
-
Rails.application.assets['custom.js'].digest = 'custom.js.digest'
|
51
|
-
Rails.application.assets['custom.css'].digest = 'custom.css.digest'
|
52
|
-
Rails.application.assets['first.ext'].digest = 'first.ext.digest'
|
53
|
-
Rails.application.assets['second.ext'].digest = 'second.ext.digest'
|
54
|
-
Rails.application.config.assets.digests = nil
|
55
|
-
|
56
|
-
module ActionView
|
57
|
-
class Base
|
58
|
-
def self.assets_manifest
|
59
|
-
@nested ||= Nester.new
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
ActionView::Base.assets_manifest.assets = Rails.application.assets.keys.reduce({}) do |hash, asset|
|
64
|
-
hash[asset] = asset.to_s + '.manifest'
|
65
|
-
hash
|
66
|
-
end
|