ettu 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +32 -17
  4. data/ROADMAP.md +1 -1
  5. data/ettu.gemspec +5 -4
  6. data/lib/ettu/configuration.rb +18 -28
  7. data/lib/ettu/fresh_when.rb +14 -4
  8. data/lib/ettu/railtie.rb +11 -0
  9. data/lib/ettu/version.rb +1 -1
  10. data/lib/ettu.rb +16 -4
  11. data/spec/{ettu/ettu_spec.rb → ettu_spec.rb} +45 -69
  12. data/spec/fixtures.rb +52 -0
  13. data/spec/fresh_when_spec.rb +46 -0
  14. data/spec/spec_helper.rb +10 -19
  15. metadata +26 -94
  16. data/spec/controllers/users_controller_spec.rb +0 -66
  17. data/spec/dummy/.gitignore +0 -3
  18. data/spec/dummy/Rakefile +0 -7
  19. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  20. data/spec/dummy/app/assets/javascripts/test.js +0 -1
  21. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  22. data/spec/dummy/app/controllers/application_controller.rb +0 -11
  23. data/spec/dummy/app/controllers/users_controller.rb +0 -9
  24. data/spec/dummy/app/models/user.rb +0 -12
  25. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  26. data/spec/dummy/app/views/users/index.html.erb +0 -1
  27. data/spec/dummy/config/application.rb +0 -65
  28. data/spec/dummy/config/boot.rb +0 -10
  29. data/spec/dummy/config/environment.rb +0 -9
  30. data/spec/dummy/config/environments/test.rb +0 -35
  31. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  32. data/spec/dummy/config/initializers/session_store.rb +0 -8
  33. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -10
  34. data/spec/dummy/config/locales/en.yml +0 -5
  35. data/spec/dummy/config/routes.rb +0 -3
  36. data/spec/dummy/config.ru +0 -4
  37. data/spec/dummy/db/.keep +0 -0
  38. data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js +0 -15
  39. data/spec/dummy/public/assets/application-5d535630590bf232c0d869f6b8fa6479.js.gz +0 -0
  40. data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css +0 -14
  41. data/spec/dummy/public/assets/application-e1e25f5530998b76317739a1762b3401.css.gz +0 -0
  42. data/spec/dummy/public/assets/application.css +0 -14
  43. data/spec/dummy/public/assets/application.css.gz +0 -0
  44. data/spec/dummy/public/assets/application.js +0 -15
  45. data/spec/dummy/public/assets/application.js.gz +0 -0
  46. data/spec/dummy/public/assets/manifest.yml +0 -5
  47. data/spec/dummy/script/rails +0 -6
  48. data/spec/ettu/fresh_when_spec.rb +0 -28
  49. data/spec/support/fixtures.rb +0 -38
  50. data/spec/support/include_hash.rb +0 -5
  51. data/spec/support/memory_store.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1a5e5a4fa5edd6f0599a6fc900eae50f7cf25c0
4
- data.tar.gz: bacdad06438bbc50ae3fb847a6f649dba2fa7b82
3
+ metadata.gz: bdc3e36dd4f21333678bb4d88ad7a963040c6545
4
+ data.tar.gz: 85d2b61d41d2b4e8e28ce2c58355beb08fb6f282
5
5
  SHA512:
6
- metadata.gz: 8b195b10a8128e2d0ac5fd5449e95c51f4c4ac7fee5a2f14bf7560ed72d6bed06205d2a5d755213ea3fe82f6281c4f64518be10d16d489be92aa4856fd52c3e7
7
- data.tar.gz: b6f133486cdc146eefd50ec7a788045e9547e032e95d8553674eb31fd85038b12d3325e12e1f2b3e289f29b1d7b084a794bbf4ef2b51d6acd88cfae6dc20cd98
6
+ metadata.gz: 6894aba4eda3847150eacd85f0cfbd725b3689219857d83221cf6662c6c9485a9df11dfcd56e1e446d6db15ee585935b938cfdfb798b1f731bd0b029d3570787
7
+ data.tar.gz: 88edb98c24ee25bed3f4194ec6a1d8b402d2516f9d345d45553f6882fd9603d7006a7071930a1c3dfd1adc9fc6b5d89da3e4988792bc8e0b27200bbb70eafe4e
data/.travis.yml CHANGED
@@ -3,4 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - jruby-19mode
6
- - rbx
6
+ - rbx-19mode
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- Ettu [![Build Status](https://travis-ci.org/cloudspace/ettu.png?branch=v3)](https://travis-ci.org/cloudspace/ettu)
1
+ Ettu
2
2
  ====
3
3
 
4
- Using Rails 3's `stale?` or `fresh_when`? Are your users seeing old view
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 and [cache_digests](https://github.com/rails/cache_digests) to
23
- your Gemfile:
22
+ Add Ettu to your Gemfile:
24
23
 
25
- gem 'ettu', '~> 3.0'
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 your
50
- precompiled assets along with the cache digest of the current action
51
- into the calculation for the final ETag sent to the browser.
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 += ['first.js', 'second.css']
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: 'products/index'
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, assets: false, view: false
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 Gotchas
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 order for Rails to detect changes to templates when testing `perform_caching`
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.action_view.cache_template_loading = false
120
+ config.ettu.development_hack = true
106
121
  end
107
122
  ```
108
123
 
data/ROADMAP.md CHANGED
@@ -6,4 +6,4 @@ Ettu Roadmap
6
6
  - Separate gem into branches
7
7
  - v3 branch will track Rails 3
8
8
  - v4 branch will track Rails 4
9
- - [x] Default assets to those set in Rails.application.config.assets
9
+ - [ ] Default assets to those set in Rails.application.config.assets.precompile
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.summary = %q{Add Assets and Views into the Rails ETag Equation.}
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', '~> 3.0'
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-rails'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'simplecov'
26
27
  end
@@ -13,7 +13,9 @@ class Ettu
13
13
  private
14
14
 
15
15
  def set_defaults
16
- self.assets = LateLoadAssets.new(self, :assets)
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
- self.template_digestor = LateLoadTemplateDigestor.new(self, :template_digestor)
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 LateLoad
28
- def initialize(config, name)
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
- class LateLoadAssets < LateLoad
41
- def to_a
42
- super
38
+ def digest(*args)
39
+ digestor = attempt_late_template_digestor_set
40
+ digestor.digest(*args)
43
41
  end
44
42
 
45
- def defaults
46
- ::Rails.application.config.assets.digests.try(:keys) || []
47
- end
48
- end
43
+ private
49
44
 
50
- class LateLoadTemplateDigestor < LateLoad
51
- def defaults
52
- unless defined? CacheDigests::TemplateDigestor
53
- # Attempt to load cache_digets
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
@@ -2,12 +2,22 @@ class Ettu
2
2
  module FreshWhen
3
3
  extend ActiveSupport::Concern
4
4
 
5
- def fresh_when(record_or_options, additional_options = {})
6
- ettu = Ettu.new record_or_options, additional_options, self
5
+ included do
6
+ alias_method :old_fresh_when, :fresh_when
7
7
 
8
- ettu_params = {etag: ettu.etags, last_modified: ettu.last_modified}
8
+ def fresh_when(record_or_options, additional_options = {})
9
+ ettu = ettu_instance(record_or_options, additional_options, self)
9
10
 
10
- super nil, ettu.options.merge(ettu_params)
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
@@ -1,3 +1,3 @@
1
1
  class Ettu
2
- VERSION = '3.2.0'
2
+ VERSION = '4.0.0'
3
3
  end
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
- manifest = Rails.application.config.assets.digests
82
- if digest = manifest.try(:[], asset)
94
+ if digest = ActionView::Base.assets_manifest.assets[asset]
83
95
  digest
84
96
  else
85
- # Compute it in
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
- # 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 }
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
- before(:each) do
18
- Ettu.configure do |config|
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
- 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' } }
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([digests.first])
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
- 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
48
- end
32
+ describe '.configure' do
33
+ subject(:ettu) { Ettu.new(nil, {}, controller) }
34
+ after(:all) { Ettu.configure { |config| config.reset } }
49
35
 
50
- it 'will throw error if file does not exist' do
51
- def hash; { assets: 'does_not_exist' }; end
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
- expect{ ettu.asset_etags }.to raise_error
54
- end
55
- end
46
+ it 'will use the default js file' do
47
+ expect(ettu.js_etag).to eq('custom.js.digest')
48
+ end
56
49
 
57
- describe '.configure' do
58
- let(:hash) { nil }
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(digests)
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 'can append additional assets' do
73
- let(:configuration) { Ettu::Configuration.new }
74
- let(:random_string) { SecureRandom.hex }
75
-
76
- it 'with +=' do
77
- configuration.assets += [random_string]
78
- expect(configuration.assets).to include(random_string)
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 'with <<' do
82
- configuration.assets << random_string
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
- context 'when setting default to false' do
88
- it 'will disable asset etags' do
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
- subject(:ettu) { Ettu.new(record, {}, controller) }
104
-
87
+ let(:ettu) { Ettu.new(record, {}, controller) }
105
88
  it 'will collect all etags' do
106
- expected = [record, 'controller_name/action_name.digest'] | digests
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
- ENV['RAILS_ENV'] ||= 'test'
2
- require File.expand_path('../dummy/config/environment', __FILE__)
3
- require 'rspec/rails'
4
- require 'rspec/autorun'
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
- # 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 }
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