faraday 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,14 +5,14 @@ source "http://rubygems.org"
5
5
  # and rake tasks are available in development mode:
6
6
  group :development, :test do
7
7
  gem 'patron', '~> 0.4', :platforms => :ruby
8
- gem 'sinatra', '~> 1.1'
8
+ gem 'sinatra', '~> 1.2'
9
9
  gem 'typhoeus', '~> 0.2', :platforms => :ruby
10
- gem 'excon', '~> 0.5.8'
10
+ gem 'excon', '~> 0.6'
11
11
  gem 'em-http-request', '~> 0.3', :require => 'em-http', :platforms => :ruby
12
12
  gem 'em-synchrony', '~> 0.2', :require => ['em-synchrony', 'em-synchrony/em-http'], :platforms => :ruby_19
13
13
  gem 'webmock'
14
14
  # ActiveSupport::JSON will be used in ruby 1.8 and Yajl in 1.9; this is to test against both adapters
15
- gem 'activesupport', '~> 2.3.8', :require => nil, :platforms => [:ruby_18, :jruby]
15
+ gem 'activesupport', '~> 2.3', :require => nil, :platforms => [:ruby_18, :jruby]
16
16
  gem 'yajl-ruby', :require => 'yajl', :platforms => :ruby_19
17
17
  end
18
18
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ #!/usr/bin/env rake
2
+
3
3
  require 'date'
4
4
 
5
5
  #############################################################################
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  ## If your rubyforge_project name is different, then edit it and comment out
13
13
  ## the sub! line in the Rakefile
14
14
  s.name = 'faraday'
15
- s.version = '0.6.1'
16
- s.date = '2011-04-13'
15
+ s.version = '0.7.0'
16
+ s.date = '2011-05-10'
17
17
  s.rubyforge_project = 'faraday'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
 
4
4
  class << self
5
5
  attr_accessor :default_adapter
@@ -12,11 +12,8 @@ module Faraday
12
12
  session = ::Patron::Session.new
13
13
 
14
14
  response = begin
15
- if Connection::METHODS_WITH_BODIES.include? env[:method]
16
- session.send(env[:method], env[:url].to_s, env[:body].to_s, env[:request_headers])
17
- else
18
- session.send(env[:method], env[:url].to_s, env[:request_headers])
19
- end
15
+ data = Connection::METHODS_WITH_BODIES.include?(env[:method]) ? env[:body].to_s : nil
16
+ session.request(env[:method], env[:url].to_s, env[:request_headers], :data => data)
20
17
  rescue Errno::ECONNREFUSED
21
18
  raise Error::ConnectionFailed, $!
22
19
  end
@@ -26,5 +23,11 @@ module Faraday
26
23
  @app.call env
27
24
  end
28
25
  end
26
+
27
+ # HAX: helps but doesn't work completely
28
+ # https://github.com/toland/patron/issues/34
29
+ valid_actions = ::Patron::Request::VALID_ACTIONS
30
+ valid_actions << :patch unless valid_actions.include? :patch
31
+ valid_actions << :options unless valid_actions.include? :options
29
32
  end
30
33
  end
@@ -12,6 +12,9 @@ module Faraday
12
12
  new { |builder| yield builder }
13
13
  end
14
14
 
15
+ # Error raised when trying to modify the stack after calling `lock!`
16
+ class StackLocked < RuntimeError; end
17
+
15
18
  # borrowed from ActiveSupport::Dependencies::Reference &
16
19
  # ActionDispatch::MiddlewareStack::Middleware
17
20
  class Handler
@@ -55,6 +58,7 @@ module Faraday
55
58
  end
56
59
 
57
60
  def build(options = {})
61
+ raise_if_locked
58
62
  @handlers.clear unless options[:keep]
59
63
  yield self if block_given?
60
64
  end
@@ -76,7 +80,17 @@ module Faraday
76
80
  @handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }
77
81
  end
78
82
 
83
+ # Locks the middleware stack to ensure no further modifications are possible.
84
+ def lock!
85
+ @handlers.freeze
86
+ end
87
+
88
+ def locked?
89
+ @handlers.frozen?
90
+ end
91
+
79
92
  def use(klass, *args)
93
+ raise_if_locked
80
94
  block = block_given? ? Proc.new : nil
81
95
  @handlers << self.class::Handler.new(klass, *args, &block)
82
96
  end
@@ -99,6 +113,7 @@ module Faraday
99
113
  ## methods to push onto the various positions in the stack:
100
114
 
101
115
  def insert(index, *args, &block)
116
+ raise_if_locked
102
117
  index = assert_index(index)
103
118
  handler = self.class::Handler.new(*args, &block)
104
119
  @handlers.insert(index, handler)
@@ -112,17 +127,23 @@ module Faraday
112
127
  end
113
128
 
114
129
  def swap(index, *args, &block)
130
+ raise_if_locked
115
131
  index = assert_index(index)
116
132
  @handlers.delete_at(index)
117
133
  insert(index, *args, &block)
118
134
  end
119
135
 
120
136
  def delete(handler)
137
+ raise_if_locked
121
138
  @handlers.delete(handler)
122
139
  end
123
140
 
124
141
  private
125
142
 
143
+ def raise_if_locked
144
+ raise StackLocked, "can't modify middleware stack after making a request" if locked?
145
+ end
146
+
126
147
  def use_symbol(mod, key, *args)
127
148
  block = block_given? ? Proc.new : nil
128
149
  use(mod.lookup_module(key), *args, &block)
@@ -4,10 +4,10 @@ require 'base64'
4
4
 
5
5
  module Faraday
6
6
  class Connection
7
- include Addressable, Faraday::Utils
7
+ include Addressable
8
8
 
9
- METHODS = Set.new [:get, :post, :put, :delete, :head]
10
- METHODS_WITH_BODIES = Set.new [:post, :put]
9
+ METHODS = Set.new [:get, :post, :put, :delete, :head, :patch, :options]
10
+ METHODS_WITH_BODIES = Set.new [:post, :put, :patch, :options]
11
11
 
12
12
  attr_accessor :host, :port, :scheme, :params, :headers, :parallel_manager
13
13
  attr_reader :path_prefix, :builder, :options, :ssl
@@ -22,15 +22,17 @@ module Faraday
22
22
  options = url
23
23
  url = options[:url]
24
24
  end
25
- @headers = Headers.new
26
- @params = {}
25
+ @headers = Utils::Headers.new
26
+ @params = Utils::ParamsHash.new
27
27
  @options = options[:request] || {}
28
28
  @ssl = options[:ssl] || {}
29
29
  @parallel_manager = options[:parallel]
30
+
30
31
  self.url_prefix = url if url
31
32
  proxy(options[:proxy])
32
- merge_params @params, options[:params] if options[:params]
33
- merge_headers @headers, options[:headers] if options[:headers]
33
+
34
+ @params.update options[:params] if options[:params]
35
+ @headers.update options[:headers] if options[:headers]
34
36
 
35
37
  if block_given?
36
38
  @builder = Builder.create { |b| yield b }
@@ -59,6 +61,25 @@ module Faraday
59
61
  @builder.build(options, &block)
60
62
  end
61
63
 
64
+ # The "rack app" wrapped in middleware. All requests are sent here.
65
+ #
66
+ # The builder is responsible for creating the app object. After this,
67
+ # the builder gets locked to ensure no further modifications are made
68
+ # to the middleware stack.
69
+ #
70
+ # Returns an object that responds to `call` and returns a Response.
71
+ def app
72
+ @app ||= begin
73
+ builder.lock!
74
+ builder.to_app(lambda { |env|
75
+ # the inner app that creates and returns the Response object
76
+ response = Response.new
77
+ response.finish(env) unless env[:parallel_manager]
78
+ env[:response] = response
79
+ })
80
+ end
81
+ end
82
+
62
83
  def get(url = nil, headers = nil)
63
84
  block = block_given? ? Proc.new : nil
64
85
  run_request(:get, url, nil, headers, &block)
@@ -74,6 +95,11 @@ module Faraday
74
95
  run_request(:put, url, body, headers, &block)
75
96
  end
76
97
 
98
+ def patch(url = nil, body = nil, headers = nil)
99
+ block = block_given? ? Proc.new : nil
100
+ run_request(:patch, url, body, headers, &block)
101
+ end
102
+
77
103
  def head(url = nil, headers = nil)
78
104
  block = block_given? ? Proc.new : nil
79
105
  run_request(:head, url, nil, headers, &block)
@@ -145,12 +171,11 @@ module Faraday
145
171
  self.host = uri.host
146
172
  self.port = uri.port
147
173
  self.path_prefix = uri.path
148
- if uri.query && !uri.query.empty?
149
- merge_params @params, parse_query(uri.query)
150
- end
151
- if uri.user && uri.password
152
- basic_auth(uri.user, uri.password)
153
- end
174
+
175
+ @params.merge_query(uri.query)
176
+ basic_auth(uri.user, uri.password) if uri.user && uri.password
177
+
178
+ uri
154
179
  end
155
180
 
156
181
  # Ensures that the path prefix always has a leading / and no trailing /
@@ -167,12 +192,15 @@ module Faraday
167
192
  raise ArgumentError, "unknown http method: #{method}"
168
193
  end
169
194
 
170
- Request.run(self, method) do |req|
195
+ request = Request.create(method) do |req|
171
196
  req.url(url) if url
172
197
  req.headers.update(headers) if headers
173
198
  req.body = body if body
174
199
  yield req if block_given?
175
200
  end
201
+
202
+ env = request.to_env(self)
203
+ self.app.call(env)
176
204
  end
177
205
 
178
206
  # Takes a relative url for a request and combines it with the defaults
@@ -186,7 +214,7 @@ module Faraday
186
214
  # conn.build_url("nigiri?page=2") # => https://sushi.com/api/nigiri?token=abc&page=2
187
215
  # conn.build_url("nigiri", :page => 2) # => https://sushi.com/api/nigiri?token=abc&page=2
188
216
  #
189
- def build_url(url, params = nil)
217
+ def build_url(url, extra_params = nil)
190
218
  uri = URI.parse(url.to_s)
191
219
  if @path_prefix && uri.path !~ /^\//
192
220
  uri.path = "#{@path_prefix.size > 1 ? @path_prefix : nil}/#{uri.path}"
@@ -194,7 +222,11 @@ module Faraday
194
222
  uri.host ||= @host
195
223
  uri.port ||= @port
196
224
  uri.scheme ||= @scheme
197
- replace_query(uri, params)
225
+
226
+ params = @params.dup.merge_query(uri.query)
227
+ params.update extra_params if extra_params
228
+ uri.query = params.empty? ? nil : params.to_query
229
+
198
230
  uri
199
231
  end
200
232
 
@@ -202,18 +234,6 @@ module Faraday
202
234
  self.class.new(build_url(''), :headers => headers.dup, :params => params.dup, :builder => builder.dup)
203
235
  end
204
236
 
205
- def replace_query(uri, params)
206
- url_params = @params.dup
207
- if uri.query && !uri.query.empty?
208
- merge_params(url_params, parse_query(uri.query))
209
- end
210
- if params && !params.empty?
211
- merge_params(url_params, params)
212
- end
213
- uri.query = url_params.empty? ? nil : build_query(url_params)
214
- uri
215
- end
216
-
217
237
  def proxy_arg_to_uri(arg)
218
238
  case arg
219
239
  when String then URI.parse(arg)
@@ -22,16 +22,18 @@ module Faraday
22
22
  :url_encoded => :UrlEncoded,
23
23
  :multipart => :Multipart
24
24
 
25
- def self.run(connection, request_method)
26
- req = create
27
- yield req if block_given?
28
- req.run(connection, request_method)
25
+ attr_reader :method
26
+
27
+ def self.create(request_method)
28
+ new(request_method).tap do |request|
29
+ yield request if block_given?
30
+ end
29
31
  end
30
32
 
31
- def self.create
32
- req = new(nil, {}, {}, nil)
33
- yield req if block_given?
34
- req
33
+ def initialize(request_method)
34
+ @method = request_method
35
+ self.params = {}
36
+ self.headers = {}
35
37
  end
36
38
 
37
39
  def url(path, params = {})
@@ -63,13 +65,11 @@ module Faraday
63
65
  # :user - Proxy server username
64
66
  # :password - Proxy server password
65
67
  # :ssl - Hash of options for configuring SSL requests.
66
- def to_env_hash(connection, request_method)
67
- env_headers = connection.headers.dup
68
- env_params = connection.params.dup
69
- connection.merge_headers(env_headers, headers)
70
- connection.merge_params(env_params, params)
68
+ def to_env(connection)
69
+ env_params = connection.params.merge(params)
70
+ env_headers = connection.headers.merge(headers)
71
71
 
72
- { :method => request_method,
72
+ { :method => method,
73
73
  :body => body,
74
74
  :url => connection.build_url(path, env_params),
75
75
  :request_headers => env_headers,
@@ -77,15 +77,5 @@ module Faraday
77
77
  :request => connection.options.merge(:proxy => connection.proxy),
78
78
  :ssl => connection.ssl}
79
79
  end
80
-
81
- def run(connection, request_method)
82
- app = lambda { |env|
83
- response = Response.new
84
- response.finish(env) unless env[:parallel_manager]
85
- env[:response] = response
86
- }
87
- env = to_env_hash(connection, request_method)
88
- connection.builder.to_app(app).call(env)
89
- end
90
80
  end
91
81
  end
@@ -1,4 +1,5 @@
1
1
  require 'rack/utils'
2
+
2
3
  module Faraday
3
4
  module Utils
4
5
  include Rack::Utils
@@ -44,8 +45,65 @@ module Faraday
44
45
  end
45
46
  end
46
47
 
47
- # Make Rack::Utils build_query method public.
48
- public :build_query
48
+ # hash with stringified keys
49
+ class ParamsHash < Hash
50
+ def [](key)
51
+ super(convert_key(key))
52
+ end
53
+
54
+ def []=(key, value)
55
+ super(convert_key(key), value)
56
+ end
57
+
58
+ def delete(key)
59
+ super(convert_key(key))
60
+ end
61
+
62
+ def include?(key)
63
+ super(convert_key(key))
64
+ end
65
+
66
+ alias_method :has_key?, :include?
67
+ alias_method :member?, :include?
68
+ alias_method :key?, :include?
69
+
70
+ def update(params)
71
+ params.each do |key, value|
72
+ self[key] = value
73
+ end
74
+ self
75
+ end
76
+ alias_method :merge!, :update
77
+
78
+ def merge(params)
79
+ dup.update(params)
80
+ end
81
+
82
+ def replace(other)
83
+ clear
84
+ update(other)
85
+ end
86
+
87
+ def merge_query(query)
88
+ if query && !query.empty?
89
+ update Utils.parse_query(query)
90
+ end
91
+ self
92
+ end
93
+
94
+ def to_query
95
+ Utils.build_query(self)
96
+ end
97
+
98
+ private
99
+
100
+ def convert_key(key)
101
+ key.to_s
102
+ end
103
+ end
104
+
105
+ # Make Rack::Utils methods public.
106
+ public :build_query, :parse_query
49
107
 
50
108
  # Override Rack's version since it doesn't handle non-String values
51
109
  def build_nested_query(value, prefix = nil)
@@ -72,20 +130,6 @@ module Faraday
72
130
  end
73
131
  end
74
132
 
75
- # Turns param keys into strings
76
- def merge_params(existing_params, new_params)
77
- new_params.each do |key, value|
78
- existing_params[key.to_s] = value
79
- end
80
- end
81
-
82
- # Turns headers keys and values into strings
83
- def merge_headers(existing_headers, new_headers)
84
- new_headers.each do |key, value|
85
- existing_headers[key] = value.to_s
86
- end
87
- end
88
-
89
133
  # Receives a URL and returns just the path with the query string sorted.
90
134
  def normalize_path(url)
91
135
  (url.path != "" ? url.path : "/") +
@@ -67,8 +67,8 @@ else
67
67
  assert_equal "file live_test.rb text/x-ruby", resp.body
68
68
  end unless :default == adapter # isn't configured for multipart
69
69
 
70
- # http://github.com/toland/patron/issues/#issue/9
71
- if ENV['FORCE'] || adapter != Faraday::Adapter::Patron
70
+ # https://github.com/toland/patron/issues/9
71
+ if ENV['FORCE'] || %[Faraday::Adapter::Patron] != adapter.to_s
72
72
  define_method "test_#{adapter}_PUT_send_url_encoded_params" do
73
73
  resp = create_connection(adapter).put do |req|
74
74
  req.url 'echo_name'
@@ -90,6 +90,21 @@ else
90
90
  end
91
91
  end
92
92
 
93
+ # https://github.com/toland/patron/issues/34
94
+ unless %w[Faraday::Adapter::Patron Faraday::Adapter::EMSynchrony].include? adapter.to_s
95
+ define_method "test_#{adapter}_PATCH_send_url_encoded_params" do
96
+ resp = create_connection(adapter).patch('echo_name', 'name' => 'zack')
97
+ assert_equal %("zack"), resp.body
98
+ end
99
+ end
100
+
101
+ unless %[Faraday::Adapter::EMSynchrony] == adapter.to_s
102
+ define_method "test_#{adapter}_OPTIONS" do
103
+ resp = create_connection(adapter).run_request(:options, '/options', nil, {})
104
+ assert_equal "hi", resp.body
105
+ end
106
+ end
107
+
93
108
  define_method "test_#{adapter}_HEAD_send_url_encoded_params" do
94
109
  resp = create_connection(adapter).head do |req|
95
110
  req.url 'hello', 'name' => 'zack'
@@ -158,19 +173,19 @@ else
158
173
 
159
174
  def create_connection(adapter)
160
175
  if adapter == :default
161
- Faraday.default_connection.tap do |conn|
162
- conn.url_prefix = LIVE_SERVER
163
- conn.headers['X-Faraday-Adapter'] = adapter.to_s
164
- end
176
+ builder_block = nil
165
177
  else
166
- Faraday::Connection.new LIVE_SERVER, :headers => {'X-Faraday-Adapter' => adapter.to_s} do |b|
178
+ builder_block = Proc.new do |b|
167
179
  b.request :multipart
168
180
  b.request :url_encoded
169
181
  b.use adapter
170
182
  end
171
- end.tap do |conn|
172
- target = conn.builder.handlers.last
173
- conn.builder.insert_before target, Faraday::Response::RaiseError
183
+ end
184
+
185
+ Faraday::Connection.new(LIVE_SERVER, &builder_block).tap do |conn|
186
+ conn.headers['X-Faraday-Adapter'] = adapter.to_s
187
+ adapter_handler = conn.builder.handlers.last
188
+ conn.builder.insert_before adapter_handler, Faraday::Response::RaiseError
174
189
  end
175
190
  end
176
191
 
@@ -38,18 +38,22 @@ class TestConnection < Faraday::TestCase
38
38
 
39
39
  def test_initialize_stores_default_params_from_options
40
40
  conn = Faraday::Connection.new :params => {:a => 1}
41
- assert_equal 1, conn.params['a']
41
+ assert_equal({'a' => 1}, conn.params)
42
42
  end
43
43
 
44
44
  def test_initialize_stores_default_params_from_uri
45
- conn = Faraday::Connection.new "http://sushi.com/fish?a=1", :params => {'b' => '2'}
46
- assert_equal '1', conn.params['a']
47
- assert_equal '2', conn.params['b']
45
+ conn = Faraday::Connection.new "http://sushi.com/fish?a=1"
46
+ assert_equal({'a' => '1'}, conn.params)
47
+ end
48
+
49
+ def test_initialize_stores_default_params_from_uri_and_options
50
+ conn = Faraday::Connection.new "http://sushi.com/fish?a=1&b=2", :params => {'a' => 3}
51
+ assert_equal({'a' => 3, 'b' => '2'}, conn.params)
48
52
  end
49
53
 
50
54
  def test_initialize_stores_default_headers_from_options
51
- conn = Faraday::Connection.new :headers => {:a => 1}
52
- assert_equal '1', conn.headers['A']
55
+ conn = Faraday::Connection.new :headers => {:user_agent => 'Faraday'}
56
+ assert_equal 'Faraday', conn.headers['User-agent']
53
57
  end
54
58
 
55
59
  def test_basic_auth_sets_authorization_header
@@ -152,21 +156,21 @@ class TestConnection < Faraday::TestCase
152
156
  def test_build_url_mashes_default_and_given_params_together
153
157
  conn = Faraday::Connection.new 'http://sushi.com/api?token=abc', :params => {'format' => 'json'}
154
158
  url = conn.build_url("nigiri?page=1", :limit => 5)
155
- assert_match /limit=5/, url.query
156
- assert_match /page=1/, url.query
157
- assert_match /format=json/, url.query
158
- assert_match /token=abc/, url.query
159
+ assert_equal %w[format=json limit=5 page=1 token=abc], url.query.split('&').sort
159
160
  end
160
161
 
161
162
  def test_build_url_overrides_default_params_with_given_params
162
163
  conn = Faraday::Connection.new 'http://sushi.com/api?token=abc', :params => {'format' => 'json'}
163
164
  url = conn.build_url("nigiri?page=1", :limit => 5, :token => 'def', :format => 'xml')
164
- assert_match /limit=5/, url.query
165
- assert_match /page=1/, url.query
166
- assert_match /format=xml/, url.query
167
- assert_match /token=def/, url.query
168
- assert_no_match /format=json/, url.query
169
- assert_no_match /token=abc/, url.query
165
+ assert_equal %w[format=xml limit=5 page=1 token=def], url.query.split('&').sort
166
+ end
167
+
168
+ def test_default_params_hash_has_indifferent_access
169
+ conn = Faraday::Connection.new :params => {'format' => 'json'}
170
+ assert conn.params.has_key?(:format)
171
+ conn.params[:format] = 'xml'
172
+ url = conn.build_url("")
173
+ assert_equal %w[format=xml], url.query.split('&').sort
170
174
  end
171
175
 
172
176
  def test_build_url_parses_url
@@ -222,10 +226,8 @@ class TestConnection < Faraday::TestCase
222
226
 
223
227
  def test_params_to_query_converts_hash_of_params_to_uri_escaped_query_string
224
228
  conn = Faraday::Connection.new
225
- class << conn
226
- public :build_query
227
- end
228
- assert_equal "a%5Bb%5D=1%20%2B%202", conn.build_query('a[b]' => '1 + 2')
229
+ url = conn.build_url('', 'a[b]' => '1 + 2')
230
+ assert_equal "a%5Bb%5D=1%20%2B%202", url.query
229
231
  end
230
232
 
231
233
  def test_dups_connection_object
@@ -47,10 +47,10 @@ class EnvTest < Faraday::TestCase
47
47
  end
48
48
 
49
49
  def env_for(connection)
50
- env_setup = Faraday::Request.create do |req|
50
+ env_setup = Faraday::Request.create(:get) do |req|
51
51
  yield req
52
52
  end
53
- env_setup.to_env_hash(connection, :get)
53
+ env_setup.to_env(connection)
54
54
  end
55
55
  end
56
56
 
@@ -20,18 +20,22 @@ post '/file' do
20
20
  end
21
21
  end
22
22
 
23
- %w[get post].each do |method|
23
+ [:get, :post].each do |method|
24
24
  send(method, '/hello') do
25
25
  "hello #{params[:name]}"
26
26
  end
27
27
  end
28
28
 
29
- %w[post put].each do |method|
30
- send(method, '/echo_name') do
29
+ %w[POST PUT PATCH].each do |http_method|
30
+ settings.send(:route, http_method, '/echo_name') do
31
31
  params[:name].inspect
32
32
  end
33
33
  end
34
34
 
35
+ options '/options' do
36
+ 'hi'
37
+ end
38
+
35
39
  delete '/delete_with_json' do
36
40
  %/{"deleted":true}/
37
41
  end
@@ -26,8 +26,6 @@ class MiddlewareStackTest < Faraday::TestCase
26
26
 
27
27
  def test_allows_rebuilding
28
28
  build_stack Apple
29
- assert_handlers %w[Apple]
30
-
31
29
  build_stack Orange
32
30
  assert_handlers %w[Orange]
33
31
  end
@@ -67,6 +65,28 @@ class MiddlewareStackTest < Faraday::TestCase
67
65
  assert_handlers %w[Orange]
68
66
  end
69
67
 
68
+ def test_stack_is_locked_after_making_requests
69
+ build_stack Apple
70
+ assert !@builder.locked?
71
+ @conn.get('/')
72
+ assert @builder.locked?
73
+
74
+ assert_raises Faraday::Builder::StackLocked do
75
+ @conn.use Orange
76
+ end
77
+ end
78
+
79
+ def test_duped_stack_is_unlocked
80
+ build_stack Apple
81
+ assert !@builder.locked?
82
+ @builder.lock!
83
+ assert @builder.locked?
84
+
85
+ duped_connection = @conn.dup
86
+ assert_equal @builder, duped_connection.builder
87
+ assert !duped_connection.builder.locked?
88
+ end
89
+
70
90
  private
71
91
 
72
92
  # make a stack with test adapter that reflects the order of middleware
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.1
5
+ version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rick Olson
@@ -10,7 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-13 00:00:00 Z
13
+ date: 2011-05-10 00:00:00 -07:00
14
+ default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rake
@@ -106,6 +107,7 @@ files:
106
107
  - test/middleware_stack_test.rb
107
108
  - test/request_middleware_test.rb
108
109
  - test/response_middleware_test.rb
110
+ has_rdoc: true
109
111
  homepage: http://github.com/technoweenie/faraday
110
112
  licenses: []
111
113
 
@@ -129,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
131
  requirements: []
130
132
 
131
133
  rubyforge_project: faraday
132
- rubygems_version: 1.7.2
134
+ rubygems_version: 1.6.2
133
135
  signing_key:
134
136
  specification_version: 2
135
137
  summary: HTTP/REST API client library.
@@ -143,4 +145,3 @@ test_files:
143
145
  - test/middleware_stack_test.rb
144
146
  - test/request_middleware_test.rb
145
147
  - test/response_middleware_test.rb
146
- has_rdoc: