social-avatar-proxy 0.0.4 → 0.0.5

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.
@@ -56,7 +56,7 @@ module SocialAvatarProxy
56
56
  directives << "no-cache" if cc[:no_cache]
57
57
  directives << "max-stale=#{cc[:max_stale]}" if cc[:max_stale]
58
58
  directives << "max-age=#{cc[:max_age]}" if cc[:max_age]
59
- directives << cc[:public] ? "public" : "private"
59
+ directives << (cc[:public] ? "public" : "private")
60
60
  response["Cache-Control"] = directives.join("; ")
61
61
  end
62
62
  # set the data
@@ -1,3 +1,3 @@
1
1
  module SocialAvatarProxy
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -3,10 +3,13 @@ require "rack"
3
3
 
4
4
  describe SocialAvatarProxy::App do
5
5
  subject do
6
- app = SocialAvatarProxy::App
7
6
  Rack::MockRequest.new(app)
8
7
  end
9
8
 
9
+ let(:app) { SocialAvatarProxy::App.new(options) }
10
+
11
+ let(:options) { Hash.new }
12
+
10
13
  let(:successful_response) do
11
14
  response = Net::HTTPSuccess.new("1.1", 200, "Success")
12
15
  response.stub(:stream_check).and_return(true)
@@ -25,6 +28,15 @@ describe SocialAvatarProxy::App do
25
28
  klass.any_instance.stub(:response).and_return(response)
26
29
  end
27
30
 
31
+ describe "::call" do
32
+ let(:response) { successful_response }
33
+ let(:app) { SocialAvatarProxy::App }
34
+
35
+ it "should be callable from the class" do
36
+ expect(subject.get("/twitter/dave").status).to eq(200)
37
+ end
38
+ end
39
+
28
40
  context "given an invalid path" do
29
41
  it "should return a 404 response" do
30
42
  path = "/unknown"
@@ -35,11 +47,59 @@ describe SocialAvatarProxy::App do
35
47
  context "given a valid path" do
36
48
  context "that finds an existing avatar" do
37
49
  let(:response) { successful_response }
50
+ let(:path) { "/facebook/61413673" }
38
51
 
39
52
  it "should return a 200 response" do
40
- path = "/facebook/61413673"
41
53
  expect(subject.get(path).status).to eq(200)
42
54
  end
55
+
56
+ it "should return a Cache-Control header by default" do
57
+ expect(subject.get(path).headers["Cache-Control"]).to eq("max-stale=86400; max-age=86400; public")
58
+ end
59
+
60
+ it "should return a Expires header by default" do
61
+ expect(subject.get(path).headers["Expires"]).to eq((Time.now + 86400).httpdate)
62
+ end
63
+
64
+ context "given Cache-Control is turned off" do
65
+ let(:options) do
66
+ { cache_control: false }
67
+ end
68
+
69
+ it "should not return a Cache-Control header" do
70
+ expect(subject.get(path).headers["Cache-Control"]).to be_nil
71
+ end
72
+ end
73
+
74
+ context "given Cache-Control is set to private" do
75
+ let(:options) do
76
+ { cache_control: { public: false } }
77
+ end
78
+
79
+ it "should return a Cache-Control header marked for private use" do
80
+ expect(subject.get(path).headers["Cache-Control"]).to match(/private$/)
81
+ end
82
+ end
83
+
84
+ context "given Expires is turned off" do
85
+ let(:options) do
86
+ { expires: false }
87
+ end
88
+
89
+ it "should not return a Cache-Control header" do
90
+ expect(subject.get(path).headers["Expires"]).to be_nil
91
+ end
92
+ end
93
+
94
+ context "given Expires is set to two days" do
95
+ let(:options) do
96
+ { expires: (86400 * 2) }
97
+ end
98
+
99
+ it "should not return a Cache-Control header" do
100
+ expect(subject.get(path).headers["Expires"]).to eq((Time.now + (86400 * 2)).httpdate)
101
+ end
102
+ end
43
103
  end
44
104
 
45
105
  context "that fails to find an avatar" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social-avatar-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: 308556052636751640
139
+ hash: -2134945313775672714
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: 308556052636751640
148
+ hash: -2134945313775672714
149
149
  requirements: []
150
150
  rubyforge_project:
151
151
  rubygems_version: 1.8.24