webmock 1.24.1 → 1.24.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.24.2
4
+
5
+ * Improve parsing of params on request
6
+
7
+ Thanks to [Cedric Pimenta](https://github.com/cedricpim)
8
+
3
9
  ## 1.24.1
4
10
 
5
11
  * HTTPClient adapter supports reading basic authentication credentials directly from Authorization header.
data/README.md CHANGED
@@ -538,7 +538,7 @@ so when there is no request, `Net::HTTP.start` doesn't do anything.
538
538
  **This means that WebMock breaks the Net::HTTP behaviour by default!**
539
539
 
540
540
  To workaround this issue, WebMock offers `:net_http_connect_on_start` option,
541
- which can be passed to `WebMock.allow_net_connect!` and `WebMock#disable_net_connect!` methods, i.e.
541
+ which can be passed to `WebMock.allow_net_connect!` and `WebMock.disable_net_connect!` methods, i.e.
542
542
 
543
543
  ```ruby
544
544
  WebMock.allow_net_connect!(:net_http_connect_on_start => true)
@@ -143,12 +143,12 @@ module WebMock::Util
143
143
  array_value = !!(last_key =~ /\[\]$/)
144
144
  last_key = last_key.gsub(/[\[\]]/, '')
145
145
  if current_node.is_a? Array
146
- container = current_node.find { |n| n.is_a?(Hash) && n.has_key?(last_key) }
147
- if container
146
+ last_container = current_node.select { |n| n.is_a?(Hash) }.last
147
+ if last_container && !last_container.has_key?(last_key)
148
148
  if array_value
149
- container[last_key] << value
149
+ last_container[last_key] << value
150
150
  else
151
- container[last_key] = value
151
+ last_container[last_key] = value
152
152
  end
153
153
  else
154
154
  if array_value
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.24.1' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.24.2' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -391,6 +391,24 @@ describe WebMock::RequestPattern do
391
391
  expect(WebMock::RequestPattern.new(:post, "www.example.com", :body => {:a => /^\d+$/, :b => {:c => /^\d{3}$/}})).
392
392
  not_to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=abcde&b[c]=123'))
393
393
  end
394
+
395
+ context 'body is an hash with an array of hashes' do
396
+ let(:body_hash) { {:a => [{'b' => '1'}, {'b' => '2'}]} }
397
+
398
+ it "should match when hash matches body" do
399
+ expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
400
+ to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a[][b]=1&a[][b]=2'))
401
+ end
402
+ end
403
+
404
+ context 'body is an hash with an array of hashes with multiple keys' do
405
+ let(:body_hash) { {:a => [{'b' => '1', 'a' => '2'}, {'b' => '3'}]} }
406
+
407
+ it "should match when hash matches body" do
408
+ expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
409
+ to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a[][b]=1&a[][a]=2&a[][b]=3'))
410
+ end
411
+ end
394
412
  end
395
413
 
396
414
  describe "for request with json body and content type is set to json" do
@@ -106,9 +106,16 @@ describe WebMock::Util::QueryMapper do
106
106
  expect(subject.query_to_values query).to eq values
107
107
  end
108
108
 
109
- it 'converts complex nested values, vice versa' do
109
+ it 'converts complex nested hashes, vice versa' do
110
110
  query = "one%5B%5D[foo]=bar&one%5B%5D[zoo]=car" # one[][foo]=bar&one[][zoo]=car
111
- values = {"one" => [{"foo" => "bar"}, {"zoo" => "car"}]}
111
+ values = {"one" => [{"foo" => "bar", "zoo" => "car"}]}
112
+ expect(subject.values_to_query values).to eq query
113
+ expect(subject.query_to_values query).to eq values
114
+ end
115
+
116
+ it 'converts complex nested array of hashes, vice versa' do
117
+ query = "one%5B%5D[foo]=bar&one%5B%5D[foo]=bar&one%5B%5D[zoo]=car" # one[][foo]=bar&one[][foo]=bar&one[][zoo]=car
118
+ values = {"one" => [{"foo" => "bar"}, {"foo" => "bar", "zoo" => "car"}]}
112
119
  expect(subject.values_to_query values).to eq query
113
120
  expect(subject.query_to_values query).to eq values
114
121
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- hash: 117
4
+ hash: 115
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 24
9
- - 1
10
- version: 1.24.1
9
+ - 2
10
+ version: 1.24.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bartosz Blimke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2016-02-23 00:00:00 +01:00
18
+ date: 2016-03-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency