webmock 1.24.1 → 1.24.2
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/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/webmock/util/query_mapper.rb +4 -4
- data/lib/webmock/version.rb +1 -1
- data/spec/unit/request_pattern_spec.rb +18 -0
- data/spec/unit/util/query_mapper_spec.rb +9 -2
- metadata +4 -4
data/CHANGELOG.md
CHANGED
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
|
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
|
-
|
147
|
-
if
|
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
|
-
|
149
|
+
last_container[last_key] << value
|
150
150
|
else
|
151
|
-
|
151
|
+
last_container[last_key] = value
|
152
152
|
end
|
153
153
|
else
|
154
154
|
if array_value
|
data/lib/webmock/version.rb
CHANGED
@@ -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
|
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"
|
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:
|
4
|
+
hash: 115
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 24
|
9
|
-
-
|
10
|
-
version: 1.24.
|
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-
|
18
|
+
date: 2016-03-03 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|