rhinestone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "Rhinestone integration", :vcr do
4
+ it "proxies requests to rubygems.org" do
5
+ response = nil
6
+
7
+ EM.synchrony do
8
+ response = Rhinestone.server.get("/")
9
+ EM.stop
10
+ end
11
+
12
+ response.status.should == 200
13
+ response.headers["Content-Type"].should_not be_nil
14
+ response.body.should include("RubyGems.org")
15
+ end
16
+
17
+ it "caches the requests" do
18
+ server = Rhinestone.server
19
+ response_one = response_two = nil
20
+
21
+ EM.synchrony do
22
+ response_one = server.get("/")
23
+ response_two = server.get("/")
24
+ EM.stop
25
+ end
26
+
27
+ response_one.should == response_two
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rhinestone::Server do
4
+ let(:http_client) { stub(:http_client) }
5
+ let(:cache) { stub(:cache) }
6
+ let(:server) { Rhinestone::Server.new(http_client, cache, later) }
7
+ let(:response) { stub(:response) }
8
+ let(:later) { FakeLater.new }
9
+
10
+ class FakeLater
11
+ attr_reader :block
12
+
13
+ def run(&block)
14
+ @block = block
15
+ end
16
+ end
17
+
18
+ context "when the data is not in cache" do
19
+ before do
20
+ cache.stub(:get).and_return(nil)
21
+ http_client.should_receive(:get).with("/hello/world").and_return(response)
22
+ cache.stub(:set)
23
+ end
24
+
25
+ it "returns the data from http_client" do
26
+ proxy_response = server.get("/hello/world")
27
+
28
+ proxy_response.should == response
29
+ end
30
+
31
+ it "saves the data in cache" do
32
+ cache.should_receive(:set).with("/hello/world", response)
33
+
34
+ server.get("/hello/world")
35
+ end
36
+ end
37
+
38
+ context "when the data is in cache" do
39
+ before do
40
+ cache.should_receive(:get).with("/hello/world").and_return(response)
41
+ end
42
+
43
+ it "returns the data from cache to the client" do
44
+ proxy_response = server.get("/hello/world")
45
+
46
+ proxy_response.should == response
47
+ end
48
+
49
+ it "gets the data from http_client and saves it in cache in the background" do
50
+ server.get("/hello/world")
51
+
52
+ http_response = stub(:http_response)
53
+ http_client.should_receive(:get).with("/hello/world").and_return(http_response)
54
+ cache.should_receive(:set).with("/hello/world", http_response)
55
+
56
+ later.block.should_not be_nil
57
+ later.block.call
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../lib/rhinestone'
2
+
3
+ require 'em-synchrony'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = "spec/cassettes"
8
+ c.hook_into :webmock
9
+ c.configure_rspec_metadata!
10
+ end
11
+
12
+ RSpec.configure do |c|
13
+ c.treat_symbols_as_metadata_keys_with_true_values = true
14
+ end
15
+
16
+ RSpec.shared_examples_for "cache backend" do
17
+ it "returns nil when key does not exist" do
18
+ cache_backend.get("/some/completely/unknown/file").should be_nil
19
+ end
20
+
21
+ it "returns the stored value" do
22
+ cache_backend.set("/foo?bar=baz:hello.json", "some value")
23
+
24
+ cache_backend.get("/foo?bar=baz:hello.json").should == "some value"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rhinestone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Pohorecki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dependor
16
+ requirement: &77617600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *77617600
25
+ - !ruby/object:Gem::Dependency
26
+ name: goliath
27
+ requirement: &77617390 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *77617390
36
+ - !ruby/object:Gem::Dependency
37
+ name: em-http-request
38
+ requirement: &77617180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *77617180
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &77616970 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *77616970
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &77616760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *77616760
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: &77616550 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *77616550
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmock
82
+ requirement: &77616340 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *77616340
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard
93
+ requirement: &77616130 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *77616130
102
+ - !ruby/object:Gem::Dependency
103
+ name: guard-rspec
104
+ requirement: &77615920 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *77615920
113
+ - !ruby/object:Gem::Dependency
114
+ name: libnotify
115
+ requirement: &77615710 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *77615710
124
+ description: Proxy to rubygems that returns the latest cached version of the requested
125
+ url and updates the cache in the background
126
+ email:
127
+ - adam@pohorecki.pl
128
+ executables:
129
+ - rhinestone
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .rvmrc
136
+ - Gemfile
137
+ - Guardfile
138
+ - README.md
139
+ - Rakefile
140
+ - benchmark/Gemfile
141
+ - benchmark/Gemfile.proxy
142
+ - benchmark/Gemfile.proxy.lock
143
+ - benchmark/benchmark.sh
144
+ - bin/rhinestone
145
+ - lib/rhinestone.rb
146
+ - lib/rhinestone/app.rb
147
+ - lib/rhinestone/cache.rb
148
+ - lib/rhinestone/filesystem_cache_backend.rb
149
+ - lib/rhinestone/header_filter.rb
150
+ - lib/rhinestone/http_client.rb
151
+ - lib/rhinestone/in_memory_cache_backend.rb
152
+ - lib/rhinestone/injector.rb
153
+ - lib/rhinestone/later.rb
154
+ - lib/rhinestone/response.rb
155
+ - lib/rhinestone/server.rb
156
+ - lib/rhinestone/version.rb
157
+ - rhinestone.gemspec
158
+ - spec/cassettes/Rhinestone_HttpClient/returns_a_Rhinestone_Response.yml
159
+ - spec/cassettes/Rhinestone_integration/caches_the_requests.yml
160
+ - spec/cassettes/Rhinestone_integration/proxies_requests_to_rubygems_org.yml
161
+ - spec/rhinestone/cache_spec.rb
162
+ - spec/rhinestone/filesystem_cache_backend_spec.rb
163
+ - spec/rhinestone/header_filter_spec.rb
164
+ - spec/rhinestone/http_client_spec.rb
165
+ - spec/rhinestone/in_memory_cache_backend_spec.rb
166
+ - spec/rhinestone/integration_spec.rb
167
+ - spec/rhinestone/server_spec.rb
168
+ - spec/spec_helper.rb
169
+ homepage: http://github.com/psyho/rhinestone
170
+ licenses: []
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ segments:
182
+ - 0
183
+ hash: 796330893
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ segments:
191
+ - 0
192
+ hash: 796330893
193
+ requirements: []
194
+ rubyforge_project: rhinestone
195
+ rubygems_version: 1.8.10
196
+ signing_key:
197
+ specification_version: 3
198
+ summary: Proxy to rubygems
199
+ test_files: []