Skip to content

Commit 6b4923b

Browse files
sobrinhosausman
authored andcommitted
Do not mutate the given URL on token (#27)
1 parent 7f575c0 commit 6b4923b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/dwolla_v2/token.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_param params, key
7777

7878
def self.full_url client, path
7979
path = path[:_links][:self][:href] if path.is_a? Hash
80-
path.sub! /^https?:\/\/[^\/]*/, ""
80+
path = path.sub /^https?:\/\/[^\/]*/, ""
8181
if path.start_with? client.api_url
8282
path
8383
elsif path.start_with? "/"

spec/dwolla_v2/token_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ def unknown_param; "?"; end
271271
end
272272
end
273273

274+
it "#post (do not mutate path)" do
275+
token = DwollaV2::Token.new client, hash_params
276+
path = "/foo"
277+
res_body = {:hello => "world", :timestamp => Time.now.utc.round(3)}
278+
stub_request(:post, "#{token.client.api_url}#{path}")
279+
.with(:headers => {"Accept" => "application/vnd.dwolla.v1.hal+json"})
280+
.to_return(:status => 200,
281+
:headers => {"Content-Type" => "application/json"},
282+
:body => generate_json(res_body))
283+
path_variants(path).each do |path_variant|
284+
path_variant_copy = path_variant.clone
285+
expect(token.post path_variant).to eq res_body
286+
expect(path_variant).to eq path_variant_copy
287+
end
288+
end
289+
274290
it "#post (error)" do
275291
token = DwollaV2::Token.new client, hash_params
276292
path = "/foo"

0 commit comments

Comments
 (0)