faraday 2.0.0.alpha.pre.2 → 2.0.0.alpha.pre.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5490b5d7735630cd51e014b7c4c6d72b12ee3d95c21bccbea616f5363796d563
4
- data.tar.gz: 84bf392c4e1c7a8b37cbf2395686eccd8145c43a4ff02c61cef54971615de79a
3
+ metadata.gz: 1c5ab8c9cafcd2690a2ea370814f080f0a085e666377048166868b84a9b3fb7e
4
+ data.tar.gz: 399207b7f32439dae2f9ad22bf839479e3cf715001f6b8d8a8fb8f88bb1f565d
5
5
  SHA512:
6
- metadata.gz: d0baf3290c10dab7253a44fe495492c52b3d1098410c16a87bf7082d44952f4a007c133c1025dd868dddf43d74fdf3401f256d51aaf8024e220b5ddb670bc6ec
7
- data.tar.gz: 5bbcaf4565082cc50e67a1a0c6b80ac68c51d57901573799a6dcd18f3ff22045b12bd26dccd9d70b1b7298dd728d4d2f35ee8cfa65aea9c94c8e9e9d6fb72e71
6
+ metadata.gz: 0a1b9107707c0f2ad30040885cd0037bf5ea64f3035e28b2cf4c8f0304de8b3acbc9217d6c77b0889a0603909dfaf87a9c54108a0a65e34291d13b69eae8efec
7
+ data.tar.gz: 74083d46a172455f40fd28151b806678c4d8f404508f2b25e2a8eb7b08c025a870565467fd5dff2420e2f1ebb01327b09d5519877770f46e0ea7d83c30c15a13
@@ -64,7 +64,7 @@ module Faraday
64
64
  options = ConnectionOptions.from(options)
65
65
 
66
66
  if url.is_a?(Hash) || url.is_a?(ConnectionOptions)
67
- options = options.merge(url)
67
+ options = Utils.deep_merge(options, url)
68
68
  url = options.url
69
69
  end
70
70
 
data/lib/faraday/utils.rb CHANGED
@@ -101,7 +101,7 @@ module Faraday
101
101
  # Recursive hash update
102
102
  def deep_merge!(target, hash)
103
103
  hash.each do |key, value|
104
- target[key] = if value.is_a?(Hash) && target[key].is_a?(Hash)
104
+ target[key] = if value.is_a?(Hash) && (target[key].is_a?(Hash) || target[key].is_a?(Options))
105
105
  deep_merge(target[key], value)
106
106
  else
107
107
  value
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.0.0.alpha-2'
4
+ VERSION = '2.0.0.alpha-3'
5
5
  end
data/lib/faraday.rb CHANGED
@@ -92,7 +92,7 @@ module Faraday
92
92
  # params: { page: 1 }
93
93
  # # => Faraday::Connection to http://faraday.com?page=1
94
94
  def new(url = nil, options = {}, &block)
95
- options = default_connection_options.merge(options)
95
+ options = Utils.deep_merge(default_connection_options, options)
96
96
  Faraday::Connection.new(url, options, &block)
97
97
  end
98
98
 
@@ -639,6 +639,27 @@ RSpec.describe Faraday::Connection do
639
639
 
640
640
  it_behaves_like 'default connection options'
641
641
  end
642
+
643
+ context 'preserving a user_agent assigned via default_conncetion_options' do
644
+ around do |example|
645
+ old = Faraday.default_connection_options
646
+ Faraday.default_connection_options = { headers: { user_agent: 'My Agent 1.2' } }
647
+ example.run
648
+ Faraday.default_connection_options = old
649
+ end
650
+
651
+ context 'when url is a Hash' do
652
+ let(:conn) { Faraday.new(url: 'http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
653
+
654
+ it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
655
+ end
656
+
657
+ context 'when url is a String' do
658
+ let(:conn) { Faraday.new('http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
659
+
660
+ it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
661
+ end
662
+ end
642
663
  end
643
664
 
644
665
  describe 'request params' do
@@ -53,4 +53,65 @@ RSpec.describe Faraday::Utils do
53
53
  expect(headers).not_to have_key('authorization')
54
54
  end
55
55
  end
56
+
57
+ describe '.deep_merge!' do
58
+ let(:connection_options) { Faraday::ConnectionOptions.new }
59
+ let(:url) do
60
+ {
61
+ url: 'http://example.com/abc',
62
+ headers: { 'Mime-Version' => '1.0' },
63
+ request: { oauth: { consumer_key: 'anonymous' } },
64
+ ssl: { version: '2' }
65
+ }
66
+ end
67
+
68
+ it 'recursively merges the headers' do
69
+ connection_options.headers = { user_agent: 'My Agent 1.0' }
70
+ deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
71
+
72
+ expect(deep_merge.headers).to eq('Mime-Version' => '1.0', user_agent: 'My Agent 1.0')
73
+ end
74
+
75
+ context 'when a target hash has an Options Struct value' do
76
+ let(:request) do
77
+ {
78
+ params_encoder: nil,
79
+ proxy: nil,
80
+ bind: nil,
81
+ timeout: nil,
82
+ open_timeout: nil,
83
+ read_timeout: nil,
84
+ write_timeout: nil,
85
+ boundary: nil,
86
+ oauth: { consumer_key: 'anonymous' },
87
+ context: nil,
88
+ on_data: nil
89
+ }
90
+ end
91
+ let(:ssl) do
92
+ {
93
+ verify: nil,
94
+ ca_file: nil,
95
+ ca_path: nil,
96
+ verify_mode: nil,
97
+ cert_store: nil,
98
+ client_cert: nil,
99
+ client_key: nil,
100
+ certificate: nil,
101
+ private_key: nil,
102
+ verify_depth: nil,
103
+ version: '2',
104
+ min_version: nil,
105
+ max_version: nil
106
+ }
107
+ end
108
+
109
+ it 'does not overwrite an Options Struct value' do
110
+ deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
111
+
112
+ expect(deep_merge.request.to_h).to eq(request)
113
+ expect(deep_merge.ssl.to_h).to eq(ssl)
114
+ end
115
+ end
116
+ end
56
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha.pre.2
4
+ version: 2.0.0.alpha.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-10-28 00:00:00.000000000 Z
13
+ date: 2021-11-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multipart-post
@@ -137,7 +137,7 @@ licenses:
137
137
  - MIT
138
138
  metadata:
139
139
  homepage_uri: https://lostisland.github.io/faraday
140
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0.0.alpha.pre.2
140
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0.0.alpha.pre.3
141
141
  source_code_uri: https://github.com/lostisland/faraday
142
142
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
143
143
  post_install_message: