Skip to content

Commit 277cfbd

Browse files
authored
Merge pull request #19 from emailable/dup-params
Duplicate params to avoid modifying input hash
2 parents e523247 + 2e64c6e commit 277cfbd

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/emailable/client.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ def initialize
1717
end
1818

1919
def request(method, endpoint, params = {})
20-
api_key = params.delete(:api_key)
21-
access_token = params.delete(:access_token)
20+
params_copy = params.dup
21+
api_key = params_copy.delete(:api_key)
22+
access_token = params_copy.delete(:access_token)
2223

2324
uri = URI("#{@base_url}/#{endpoint}")
2425
headers = {
@@ -30,12 +31,12 @@ def request(method, endpoint, params = {})
3031
tries ||= 3
3132
http_response =
3233
if method == :get
33-
uri.query = URI.encode_www_form(params) unless params.empty?
34+
uri.query = URI.encode_www_form(params_copy) if params_copy.any?
3435
request = Net::HTTP::Get.new(uri, headers)
3536
@connection.request(request)
3637
elsif method == :post
3738
request = Net::HTTP::Post.new(uri, headers)
38-
request.body = params.to_json
39+
request.body = params_copy.to_json
3940
@connection.request(request)
4041
end
4142

test/authentication_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ def test_request_time_authentication_takes_priority_over_global
3030
refute_nil Emailable.verify(@email, api_key: @api_key).domain
3131
end
3232

33+
def test_does_not_modify_params
34+
params = { api_key: @api_key, email: @email }
35+
Emailable.verify(params[:email], params)
36+
37+
assert_equal @api_key, params[:api_key]
38+
assert_equal @email, params[:email]
39+
end
40+
3341
end

0 commit comments

Comments
 (0)