etag_for 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/lib/etag_for/etag_for.rb +1 -11
- data/lib/etag_for/version.rb +1 -1
- data/test/etag_for_test.rb +6 -30
- metadata +2 -2
data/README.md
CHANGED
@@ -52,7 +52,9 @@ end
|
|
52
52
|
|
53
53
|
## etag_for(item_or_items, options = {})
|
54
54
|
|
55
|
-
Returns an array of strings that can be used as
|
55
|
+
Returns an array of objects and strings that can be used as the **etag** parameter to **fresh_when** and **stale?** to calculate
|
56
|
+
an ETag value for the current request. The extra files involved give a more representative value for the **ETAG** header when rendering the
|
57
|
+
response using Rails view templates
|
56
58
|
|
57
59
|
### item_or_items parameter
|
58
60
|
|
data/lib/etag_for/etag_for.rb
CHANGED
@@ -10,7 +10,7 @@ module EtagFor
|
|
10
10
|
files << options[:view] if options[:view]
|
11
11
|
files += options[:files] if options[:files]
|
12
12
|
|
13
|
-
[
|
13
|
+
[ item_or_items ].flatten + [ css_path(css_file), js_path(js_file) ] + digests_of(files)
|
14
14
|
end
|
15
15
|
|
16
16
|
protected
|
@@ -28,14 +28,4 @@ protected
|
|
28
28
|
view_context.javascript_path(js_file) if js_file && js_file.length > 0
|
29
29
|
end
|
30
30
|
|
31
|
-
def extract_keys(item_or_items)
|
32
|
-
if item_or_items.respond_to?(:map)
|
33
|
-
item_or_items.map do |item|
|
34
|
-
item.respond_to?(:cache_key) ? item.cache_key : item.to_param
|
35
|
-
end
|
36
|
-
else
|
37
|
-
item_or_items.respond_to?(:cache_key) ? item_or_items.cache_key : item_or_items.to_param
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
31
|
end
|
data/lib/etag_for/version.rb
CHANGED
data/test/etag_for_test.rb
CHANGED
@@ -55,45 +55,21 @@ describe EtagFor do
|
|
55
55
|
TestController.new.send(:js_path, "").must_be_nil
|
56
56
|
end
|
57
57
|
|
58
|
-
it "must
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
item_2 = MiniTest::Mock.new
|
63
|
-
item_2.expect :cache_key, "bar"
|
64
|
-
|
65
|
-
TestController.new.send(:extract_keys, [ item_1, item_2 ]).must_equal [ "foo", "bar" ]
|
66
|
-
end
|
67
|
-
|
68
|
-
it "must extract key from a single item with cache_key" do
|
69
|
-
item_1 = MiniTest::Mock.new
|
70
|
-
item_1.expect :cache_key, "foo"
|
58
|
+
it "must return array from etag_for with single item" do
|
59
|
+
item = MiniTest::Mock.new
|
60
|
+
item.expect :to_param, "foo"
|
71
61
|
|
72
|
-
TestController.new.
|
62
|
+
TestController.new.etag_for(item, :css => "", :js => "").must_equal [ item, nil, nil ]
|
73
63
|
end
|
74
64
|
|
75
|
-
it "must
|
65
|
+
it "must return array from etag_for with many items" do
|
76
66
|
item_1 = MiniTest::Mock.new
|
77
67
|
item_1.expect :to_param, "foo"
|
78
68
|
|
79
69
|
item_2 = MiniTest::Mock.new
|
80
70
|
item_2.expect :to_param, "bar"
|
81
71
|
|
82
|
-
TestController.new.
|
83
|
-
end
|
84
|
-
|
85
|
-
it "must extract key from a single item with out cache_key" do
|
86
|
-
item_1 = MiniTest::Mock.new
|
87
|
-
item_1.expect :to_param, "foo"
|
88
|
-
|
89
|
-
TestController.new.send(:extract_keys, item_1).must_equal "foo"
|
90
|
-
end
|
91
|
-
|
92
|
-
it "must return array from etag_for" do
|
93
|
-
item = MiniTest::Mock.new
|
94
|
-
item.expect :to_param, "foo"
|
95
|
-
|
96
|
-
TestController.new.etag_for(item, :css => "", :js => "").must_equal [ "foo", nil, nil ]
|
72
|
+
TestController.new.etag_for( [ item_1, item_2 ], :css => "", :js => "").must_equal [ item_1, item_2, nil, nil ]
|
97
73
|
end
|
98
74
|
end
|
99
75
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etag_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|