responders 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,9 @@ module Responders
22
22
  protected
23
23
 
24
24
  def do_http_cache!
25
- timestamp = resource.updated_at.try(:utc) if resource.respond_to?(:updated_at)
25
+ timestamp = resources.map do |resource|
26
+ resource.updated_at.try(:utc) if resource.respond_to?(:updated_at)
27
+ end.compact.max
26
28
 
27
29
  controller.response.last_modified ||= timestamp if timestamp
28
30
 
@@ -31,7 +33,8 @@ module Responders
31
33
  end
32
34
 
33
35
  def do_http_cache?
34
- get? && @http_cache != false && ActionController::Base.perform_caching && persisted? && resourceful?
36
+ get? && @http_cache != false && ActionController::Base.perform_caching &&
37
+ persisted? && resourceful? && resource.respond_to?(:updated_at)
35
38
  end
36
39
 
37
40
  def persisted?
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "0.6.3".freeze
2
+ VERSION = "0.6.4".freeze
3
3
  end
@@ -13,12 +13,12 @@ class HttpCacheController < ApplicationController
13
13
  respond_with(Address.new(Time.utc(2009)), options)
14
14
  end
15
15
 
16
- def collection
17
- respond_with [Address.new(Time.utc(2009)), Address.new(Time.utc(2008))]
16
+ def nested
17
+ respond_with Address.new(Time.utc(2009)), Address.new(Time.utc(2008))
18
18
  end
19
19
 
20
- def changing_collection
21
- respond_with Address.all
20
+ def collection
21
+ respond_with [Address.new(Time.utc(2009)), Address.new(Time.utc(2008))]
22
22
  end
23
23
 
24
24
  def not_persisted
@@ -88,23 +88,16 @@ class HttpCacheResponderTest < ActionController::TestCase
88
88
 
89
89
  def test_does_not_set_cache_for_collection
90
90
  get :collection
91
-
92
91
  assert_nil @response.headers["Last-Modified"]
93
92
  assert_not_nil @response.headers["ETag"]
94
93
  assert_equal 200, @response.status
95
94
  end
96
95
 
97
- def test_does_not_return_not_modified_if_collection_has_changed
98
- #First request. Returns 2 items
99
- Address.stubs(:all).returns [Address.new(Time.utc(2009)), Address.new(Time.utc(2008))]
100
- get :changing_collection
101
-
102
- #Second request. Returns 1 item, simulating scenario where a address was deleted
103
- Address.stubs(:all).returns [Address.new(Time.utc(2009))]
104
- @request.env["HTTP_IF_MODIFIED_SINCE"] = @response.headers["Last-Modified"]
105
- get :changing_collection
106
-
107
- assert_not_equal 304, @response.status
96
+ def test_works_for_nested_resources
97
+ get :nested
98
+ assert_equal Time.utc(2009).httpdate, @response.headers["Last-Modified"]
99
+ assert_match /xml/, @response.body
100
+ assert_equal 200, @response.status
108
101
  end
109
102
 
110
103
  def test_work_with_an_empty_array
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responders
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jos\xC3\xA9 Valim"