Skip to content

Commit

Permalink
Make sure to pass requestor through to all deserializes
Browse files Browse the repository at this point in the history
  • Loading branch information
helenye-stripe committed Dec 17, 2024
1 parent 68f806e commit 9224e80
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def raw_request(method, url, base_address: :api, params: {}, opts: {})

def deserialize(data, api_mode: :v1)
data = JSON.parse(data) if data.is_a?(String)
Util.convert_to_stripe_object(data, {}, api_mode: api_mode)
Util.convert_to_stripe_object(data, {}, api_mode: api_mode, requestor: @requestor)
end
end
end
6 changes: 3 additions & 3 deletions lib/stripe/stripe_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def inspect
def update_attributes(values, opts = {}, dirty: true)
values.each do |k, v|
add_accessors([k], values) unless metaclass.method_defined?(k.to_sym)
@values[k] = Util.convert_to_stripe_object(v, opts, api_mode: @api_mode)
@values[k] = Util.convert_to_stripe_object(v, opts, api_mode: @api_mode, requestor: @requestor)
dirty_value!(@values[k]) if dirty
@unsaved_values.add(k)
end
Expand Down Expand Up @@ -361,7 +361,7 @@ class << self; self; end
"We interpret empty strings as nil in requests. " \
"You may set (object).#{k} = nil to delete the property."
end
@values[k] = Util.convert_to_stripe_object(v, @opts, api_mode: @api_mode)
@values[k] = Util.convert_to_stripe_object(v, @opts, api_mode: @api_mode, requestor: @requestor)
dirty_value!(@values[k])
@unsaved_values.add(k)
end
Expand Down Expand Up @@ -534,7 +534,7 @@ class << self; self; end
# example by appending a new hash onto `additional_owners` for an
# account.
elsif value.is_a?(Hash)
Util.convert_to_stripe_object(value, @opts).serialize_params
Util.convert_to_stripe_object(value, @opts, api_mode: @api_mode, requestor: @requestor).serialize_params

elsif value.is_a?(StripeObject)
update = value.serialize_params(force: force)
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def self.convert_to_stripe_object_with_params(

case data
when Array
data.map { |i| convert_to_stripe_object(i, opts, api_mode: api_mode) }
data.map { |i| convert_to_stripe_object(i, opts, api_mode: api_mode, requestor: requestor) }
when Hash
# TODO: This is a terrible hack.
# Waiting on https://jira.corp.stripe.com/browse/API_SERVICES-3167 to add
Expand Down
7 changes: 7 additions & 0 deletions test/stripe/list_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class ListObjectTest < Test::Unit::TestCase
assert_equal 1, list.count
end

should "be able to refresh objects in list" do
list = Stripe::Customer.list
assert_not_nil list.first.instance_variable_get(:@requestor)
cus = list.first.refresh
assert cus.is_a?(Stripe::Customer)
end

should "provide #each" do
arr = [
{ id: 1 },
Expand Down
7 changes: 7 additions & 0 deletions test/stripe/search_result_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class SearchResultObjectTest < Test::Unit::TestCase
assert_equal 1, list.count
end

should "be able to refresh objects in search" do
list = Stripe::Customer.search({ query: "name:'fakename'" })
assert_not_nil list.first.instance_variable_get(:@requestor)
cus = list.first.refresh
assert cus.is_a?(Stripe::Customer)
end

should "provide #each" do
arr = [
{ id: 1 },
Expand Down

0 comments on commit 9224e80

Please sign in to comment.