stripe-ruby/test/stripe/api_operations_test.rb
Brandur 11a6eec5f5 Don't allow protected fields in Save.update API operation
As described in #481, adding a protected field like `legal_entity` as
part of an update API operation can cause some issues like a custom
encoding scheme not being considered and special handling around empty
values being ignored.

As a an easy fix for this, let's disallow access to protected fields in
the same way that we disallow them from being set directly on an
instance of a given model.

Helps address (but is not a complete fix for) #481.
2016-11-28 11:42:57 -08:00

32 lines
929 B
Ruby

# -*- coding: utf-8 -*-
require File.expand_path('../../test_helper', __FILE__)
module Stripe
class ApiOperationsTest < Test::Unit::TestCase
class UpdateableResource < APIResource
include Stripe::APIOperations::Save
def self.protected_fields
[:protected]
end
end
context ".update" do
should "post the correct parameters to the resource URL" do
@mock.expects(:post).once.
with("#{Stripe.api_base}/v1/updateableresources/id", nil, 'foo=bar').
returns(make_response({foo: 'bar'}))
resource = UpdateableResource::update("id", { foo: "bar" })
assert_equal('bar', resource.foo)
end
should "error on protected fields" do
e = assert_raises do
UpdateableResource::update("id", { protected: "bar" })
end
assert_equal "Cannot update protected field: protected", e.message
end
end
end
end