ettu 3.1.1 → 3.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -3
- data/ettu.gemspec +1 -2
- data/lib/ettu.rb +3 -2
- 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 +7 -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 +11 -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 +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +9 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/.keep +0 -0
- data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js +15 -0
- data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js.gz +0 -0
- data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css +14 -0
- data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css.gz +0 -0
- data/spec/dummy/public/assets/application.css +14 -0
- data/spec/dummy/public/assets/application.css.gz +0 -0
- data/spec/dummy/public/assets/application.js +15 -0
- data/spec/dummy/public/assets/application.js.gz +0 -0
- data/spec/dummy/public/assets/manifest.yml +5 -0
- data/spec/dummy/script/rails +6 -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
- data/spec/support/memory_store.rb +9 -0
- metadata +78 -24
- data/spec/fixtures.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1a5e5a4fa5edd6f0599a6fc900eae50f7cf25c0
|
4
|
+
data.tar.gz: bacdad06438bbc50ae3fb847a6f649dba2fa7b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b195b10a8128e2d0ac5fd5449e95c51f4c4ac7fee5a2f14bf7560ed72d6bed06205d2a5d755213ea3fe82f6281c4f64518be10d16d489be92aa4856fd52c3e7
|
7
|
+
data.tar.gz: b6f133486cdc146eefd50ec7a788045e9547e032e95d8553674eb31fd85038b12d3325e12e1f2b3e289f29b1d7b084a794bbf4ef2b51d6acd88cfae6dc20cd98
|
data/.travis.yml
CHANGED
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 3'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
|
data/ettu.gemspec
CHANGED
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency 'cache_digests'
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'simplecov'
|
25
|
+
spec.add_development_dependency 'rspec-rails'
|
27
26
|
end
|
data/lib/ettu.rb
CHANGED
@@ -78,8 +78,9 @@ class Ettu
|
|
78
78
|
def asset_digest(asset)
|
79
79
|
return nil unless asset.present?
|
80
80
|
# Check already computed assets (production)
|
81
|
-
|
82
|
-
|
81
|
+
manifest = Rails.application.config.assets.digests
|
82
|
+
if digest = manifest.try(:[], asset)
|
83
|
+
digest
|
83
84
|
else
|
84
85
|
# Compute it in
|
85
86
|
Rails.application.assets[asset].digest
|
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 = ::CacheDigests::TemplateDigestor.cache.keys.first
|
46
|
+
|
47
|
+
expect(page).to match(/#{path['controller']}\/#{path['action']}/)
|
48
|
+
expect(etags).to include(::CacheDigests::TemplateDigestor.cache.fetch(page))
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'includes all asset digests' do
|
52
|
+
expect(etags).to include(*(Rails.application.config.assets.digests.values.uniq))
|
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,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
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 @@
|
|
1
|
+
<h1>Users Index</h1>
|
@@ -0,0 +1,65 @@
|
|
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 "active_resource/railtie"
|
8
|
+
require "sprockets/railtie"
|
9
|
+
# require "rails/test_unit/railtie"
|
10
|
+
|
11
|
+
Bundler.require(*Rails.groups)
|
12
|
+
require "ettu"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
21
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Activate observers that should always be running.
|
28
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
29
|
+
|
30
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
31
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
32
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
33
|
+
|
34
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
35
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
36
|
+
# config.i18n.default_locale = :de
|
37
|
+
|
38
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
39
|
+
config.encoding = "utf-8"
|
40
|
+
|
41
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
42
|
+
config.filter_parameters += [:password]
|
43
|
+
|
44
|
+
# Enable escaping HTML in JSON.
|
45
|
+
config.active_support.escape_html_entities_in_json = true
|
46
|
+
|
47
|
+
# Use SQL instead of Active Record's schema dumper when creating the database.
|
48
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
49
|
+
# like if you have constraints or database-specific column types
|
50
|
+
# config.active_record.schema_format = :sql
|
51
|
+
|
52
|
+
# Enforce whitelist mode for mass assignment.
|
53
|
+
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
54
|
+
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
55
|
+
# parameters by using an attr_accessible or attr_protected declaration.
|
56
|
+
# config.active_record.whitelist_attributes = true
|
57
|
+
|
58
|
+
# Enable the asset pipeline
|
59
|
+
config.assets.enabled = true
|
60
|
+
|
61
|
+
# Version of your assets, change this if you want to expire all your assets
|
62
|
+
config.assets.version = '1.0'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,35 @@
|
|
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
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = 'c73defd757d28e3dcebf7d902e6acbb1ec4f5b3587ba7218092142a469af71e50d8cbac772c8963ac4eace9945e6d570cbf6526ca48a76eba528f8e4d0dd9b5f'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,10 @@
|
|
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]
|
9
|
+
end
|
10
|
+
|
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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
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,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
|
+
|
Binary file
|
@@ -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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
|
14
|
+
|
15
|
+
var test = true;
|
Binary file
|
@@ -0,0 +1,5 @@
|
|
1
|
+
---
|
2
|
+
application.js: application-5d535630590bf232c0d869f6b8fa6479.js
|
3
|
+
application/index.js: application-5d535630590bf232c0d869f6b8fa6479.js
|
4
|
+
application.css: application-e1e25f5530998b76317739a1762b3401.css
|
5
|
+
application/index.css: application-e1e25f5530998b76317739a1762b3401.css
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -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) { Rails.application.config.assets.digests }
|
14
|
+
let(:files) { assets.keys.reject { |f| f[/index/] } }
|
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: 3.
|
4
|
+
version: 3.2.0
|
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
|
@@ -67,21 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
70
|
+
name: rspec-rails
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - '>='
|
@@ -114,10 +100,44 @@ files:
|
|
114
100
|
- lib/ettu/fresh_when.rb
|
115
101
|
- lib/ettu/railtie.rb
|
116
102
|
- lib/ettu/version.rb
|
117
|
-
- spec/
|
118
|
-
- spec/
|
119
|
-
- spec/
|
103
|
+
- spec/controllers/users_controller_spec.rb
|
104
|
+
- spec/dummy/.gitignore
|
105
|
+
- spec/dummy/Rakefile
|
106
|
+
- spec/dummy/app/assets/javascripts/application.js
|
107
|
+
- spec/dummy/app/assets/javascripts/test.js
|
108
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
109
|
+
- spec/dummy/app/controllers/application_controller.rb
|
110
|
+
- spec/dummy/app/controllers/users_controller.rb
|
111
|
+
- spec/dummy/app/models/user.rb
|
112
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
113
|
+
- spec/dummy/app/views/users/index.html.erb
|
114
|
+
- spec/dummy/config.ru
|
115
|
+
- spec/dummy/config/application.rb
|
116
|
+
- spec/dummy/config/boot.rb
|
117
|
+
- spec/dummy/config/environment.rb
|
118
|
+
- spec/dummy/config/environments/test.rb
|
119
|
+
- spec/dummy/config/initializers/secret_token.rb
|
120
|
+
- spec/dummy/config/initializers/session_store.rb
|
121
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
122
|
+
- spec/dummy/config/locales/en.yml
|
123
|
+
- spec/dummy/config/routes.rb
|
124
|
+
- spec/dummy/db/.keep
|
125
|
+
- spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js
|
126
|
+
- spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js.gz
|
127
|
+
- spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css
|
128
|
+
- spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css.gz
|
129
|
+
- spec/dummy/public/assets/application.css
|
130
|
+
- spec/dummy/public/assets/application.css.gz
|
131
|
+
- spec/dummy/public/assets/application.js
|
132
|
+
- spec/dummy/public/assets/application.js.gz
|
133
|
+
- spec/dummy/public/assets/manifest.yml
|
134
|
+
- spec/dummy/script/rails
|
135
|
+
- spec/ettu/ettu_spec.rb
|
136
|
+
- spec/ettu/fresh_when_spec.rb
|
120
137
|
- spec/spec_helper.rb
|
138
|
+
- spec/support/fixtures.rb
|
139
|
+
- spec/support/include_hash.rb
|
140
|
+
- spec/support/memory_store.rb
|
121
141
|
homepage: http://github.com/cloudspace/ettu
|
122
142
|
licenses:
|
123
143
|
- MIT
|
@@ -138,12 +158,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
158
|
version: '0'
|
139
159
|
requirements: []
|
140
160
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.0.
|
161
|
+
rubygems_version: 2.0.2
|
142
162
|
signing_key:
|
143
163
|
specification_version: 4
|
144
164
|
summary: Add Assets and Views into the Rails ETag Equation.
|
145
165
|
test_files:
|
146
|
-
- spec/
|
147
|
-
- spec/
|
148
|
-
- spec/
|
166
|
+
- spec/controllers/users_controller_spec.rb
|
167
|
+
- spec/dummy/.gitignore
|
168
|
+
- spec/dummy/Rakefile
|
169
|
+
- spec/dummy/app/assets/javascripts/application.js
|
170
|
+
- spec/dummy/app/assets/javascripts/test.js
|
171
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
172
|
+
- spec/dummy/app/controllers/application_controller.rb
|
173
|
+
- spec/dummy/app/controllers/users_controller.rb
|
174
|
+
- spec/dummy/app/models/user.rb
|
175
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
176
|
+
- spec/dummy/app/views/users/index.html.erb
|
177
|
+
- spec/dummy/config.ru
|
178
|
+
- spec/dummy/config/application.rb
|
179
|
+
- spec/dummy/config/boot.rb
|
180
|
+
- spec/dummy/config/environment.rb
|
181
|
+
- spec/dummy/config/environments/test.rb
|
182
|
+
- spec/dummy/config/initializers/secret_token.rb
|
183
|
+
- spec/dummy/config/initializers/session_store.rb
|
184
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
185
|
+
- spec/dummy/config/locales/en.yml
|
186
|
+
- spec/dummy/config/routes.rb
|
187
|
+
- spec/dummy/db/.keep
|
188
|
+
- spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js
|
189
|
+
- spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js.gz
|
190
|
+
- spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css
|
191
|
+
- spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css.gz
|
192
|
+
- spec/dummy/public/assets/application.css
|
193
|
+
- spec/dummy/public/assets/application.css.gz
|
194
|
+
- spec/dummy/public/assets/application.js
|
195
|
+
- spec/dummy/public/assets/application.js.gz
|
196
|
+
- spec/dummy/public/assets/manifest.yml
|
197
|
+
- spec/dummy/script/rails
|
198
|
+
- spec/ettu/ettu_spec.rb
|
199
|
+
- spec/ettu/fresh_when_spec.rb
|
149
200
|
- spec/spec_helper.rb
|
201
|
+
- spec/support/fixtures.rb
|
202
|
+
- spec/support/include_hash.rb
|
203
|
+
- spec/support/memory_store.rb
|
data/spec/fixtures.rb
DELETED
@@ -1,57 +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 = Rails.application.assets.keys.reduce({}) do |hash, asset|
|
55
|
-
hash[asset.to_s] = asset.to_s + '.manifest'
|
56
|
-
hash
|
57
|
-
end
|