faraday_middleware 0.9.0 → 0.9.1

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.
data/.gemtest DELETED
File without changes
data/.gitignore DELETED
@@ -1,29 +0,0 @@
1
- # TextMate
2
- *.tmproj
3
- tmtags
4
-
5
- # emails
6
- *~
7
- \#*
8
- .\#*
9
-
10
- # vim
11
- *.swp
12
-
13
- # General
14
- coverage
15
- rdoc
16
- doc
17
- log
18
- .yardoc
19
- tmp
20
-
21
- # Bundler
22
- *.gem
23
- .bundle
24
- Gemfile.lock
25
- pkg
26
- *.gem
27
-
28
- # Rubinius
29
- *.rbc
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --backtrace
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - rbx-18mode
4
- - rbx-19mode
5
- - jruby-18mode
6
- - jruby-19mode
7
- - 1.8.7
8
- - 1.9.2
9
- - 1.9.3
10
- - ruby-head
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- platforms :mri_19 do
4
- gem 'simplecov'
5
- gem 'cane', '~> 2.2.2'
6
- end
7
-
8
- gem 'json', :platforms => [:ruby_18, :jruby]
9
- gem 'jruby-openssl', '~> 0.7', :platforms => :jruby
10
-
11
- gemspec
@@ -1,155 +0,0 @@
1
- require 'test/unit'
2
- require 'forwardable'
3
- require 'fileutils'
4
- require 'rack/cache'
5
- require 'faraday'
6
- require 'faraday_middleware/response/caching'
7
- require 'faraday_middleware/rack_compatible'
8
-
9
- class CachingTest < Test::Unit::TestCase
10
- class TestCache < Hash
11
- def read(key)
12
- if cached = self[key]
13
- Marshal.load(cached)
14
- end
15
- end
16
-
17
- def write(key, data)
18
- self[key] = Marshal.dump(data)
19
- end
20
-
21
- def fetch(key)
22
- read(key) || yield.tap { |data| write(key, data) }
23
- end
24
- end
25
-
26
- class Lint < Struct.new(:app)
27
- def call(env)
28
- app.call(env).on_complete do
29
- raise "no headers" unless env[:response_headers].is_a? Hash
30
- raise "no response" unless env[:response].is_a? Faraday::Response
31
- raise "env not identical" unless env[:response].env.object_id == env.object_id
32
- end
33
- end
34
- end
35
-
36
- def setup
37
- @cache = TestCache.new
38
-
39
- request_count = 0
40
- response = lambda { |env|
41
- [200, {'Content-Type' => 'text/plain'}, "request:#{request_count+=1}"]
42
- }
43
-
44
- @conn = Faraday.new do |b|
45
- b.use Lint
46
- b.use FaradayMiddleware::Caching, @cache
47
- b.adapter :test do |stub|
48
- stub.get('/', &response)
49
- stub.get('/?foo=bar', &response)
50
- stub.post('/', &response)
51
- stub.get('/other', &response)
52
- end
53
- end
54
- end
55
-
56
- extend Forwardable
57
- def_delegators :@conn, :get, :post
58
-
59
- def test_cache_get
60
- assert_equal 'request:1', get('/').body
61
- assert_equal 'request:1', get('/').body
62
- assert_equal 'request:2', get('/other').body
63
- assert_equal 'request:2', get('/other').body
64
- end
65
-
66
- def test_response_has_request_params
67
- get('/') # make cache
68
- response = get('/')
69
- assert_equal :get, response.env[:method]
70
- assert_equal '/', response.env[:url].request_uri
71
- end
72
-
73
- def test_cache_query_params
74
- assert_equal 'request:1', get('/').body
75
- assert_equal 'request:2', get('/?foo=bar').body
76
- assert_equal 'request:2', get('/?foo=bar').body
77
- assert_equal 'request:1', get('/').body
78
- end
79
-
80
- def test_doesnt_cache_post
81
- assert_equal 'request:1', post('/').body
82
- assert_equal 'request:2', post('/').body
83
- assert_equal 'request:3', post('/').body
84
- end
85
- end
86
-
87
- # RackCompatible + Rack::Cache
88
- class HttpCachingTest < Test::Unit::TestCase
89
- include FileUtils
90
-
91
- CACHE_DIR = File.expand_path('../../tmp/cache', __FILE__)
92
-
93
- # middleware to check whether "rack.errors" is free of error reports
94
- class RackErrorsComplainer < Struct.new(:app)
95
- def call(env)
96
- response = app.call(env)
97
- error_stream = env['rack.errors'].string
98
- raise %(unexpected error in 'rack.errors') if error_stream.include? 'error'
99
- response
100
- end
101
- end
102
-
103
- def setup
104
- rm_r CACHE_DIR if File.exists? CACHE_DIR
105
- # force reinitializing cache dirs
106
- Rack::Cache::Storage.instance.clear
107
-
108
- request_count = 0
109
- response = lambda { |env|
110
- [200, { 'Content-Type' => 'text/plain',
111
- 'Cache-Control' => 'public, max-age=900',
112
- },
113
- "request:#{request_count+=1}"]
114
- }
115
-
116
- @conn = Faraday.new do |b|
117
- b.use RackErrorsComplainer
118
-
119
- b.use FaradayMiddleware::RackCompatible, Rack::Cache::Context,
120
- :metastore => "file:#{CACHE_DIR}/rack/meta",
121
- :entitystore => "file:#{CACHE_DIR}/rack/body",
122
- :verbose => true
123
-
124
- b.adapter :test do |stub|
125
- stub.get('/', &response)
126
- stub.post('/', &response)
127
- end
128
- end
129
- end
130
-
131
- extend Forwardable
132
- def_delegators :@conn, :get, :post
133
-
134
- def test_cache_get
135
- response = get('/', :user_agent => 'test')
136
- assert_equal 'request:1', response.body
137
- assert_equal :get, response.env[:method]
138
- assert_equal 200, response.status
139
-
140
- response = get('/', :user_agent => 'test')
141
- assert_equal 'request:1', response.body
142
- assert_equal 'text/plain', response['content-type']
143
- assert_equal :get, response.env[:method]
144
- assert response.env[:request].respond_to?(:fetch)
145
- assert_equal 200, response.status
146
-
147
- assert_equal 'request:2', post('/').body
148
- end
149
-
150
- def test_doesnt_cache_post
151
- assert_equal 'request:1', get('/').body
152
- assert_equal 'request:2', post('/').body
153
- assert_equal 'request:3', post('/').body
154
- end
155
- end unless defined? RUBY_ENGINE and "rbx" == RUBY_ENGINE # rbx bug #1522