responders 0.6.3 → 0.6.4
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.
@@ -22,7 +22,9 @@ module Responders
|
|
22
22
|
protected
|
23
23
|
|
24
24
|
def do_http_cache!
|
25
|
-
timestamp =
|
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 &&
|
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?
|
data/lib/responders/version.rb
CHANGED
@@ -13,12 +13,12 @@ class HttpCacheController < ApplicationController
|
|
13
13
|
respond_with(Address.new(Time.utc(2009)), options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
respond_with
|
16
|
+
def nested
|
17
|
+
respond_with Address.new(Time.utc(2009)), Address.new(Time.utc(2008))
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
respond_with Address.
|
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
|
98
|
-
|
99
|
-
|
100
|
-
|
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 4
|
10
|
+
version: 0.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Jos\xC3\xA9 Valim"
|