mirror of
				https://github.com/stripe/stripe-ruby.git
				synced 2025-11-04 00:01:47 -05:00 
			
		
		
		
	Add tests for update (#1150)
* Add tests for update * Apply suggestions from code review Co-authored-by: Richard Marmorstein <52928443+richardm-stripe@users.noreply.github.com> * Lint Co-authored-by: Richard Marmorstein <52928443+richardm-stripe@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									24312f9f49
								
							
						
					
					
						commit
						a96e6f3b42
					
				@ -314,7 +314,7 @@ module Stripe
 | 
			
		||||
        assert_equal c.created, 12_345
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "updating an object should issue a POST request with only the changed properties" do
 | 
			
		||||
      should "saving an object should issue a POST request with only the changed properties" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
 | 
			
		||||
          .with(body: { "description" => "another_mn" })
 | 
			
		||||
          .to_return(body: JSON.generate(customer_fixture))
 | 
			
		||||
@ -323,7 +323,15 @@ module Stripe
 | 
			
		||||
        c.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "updating should merge in returned properties" do
 | 
			
		||||
      should "updating an object should issue a POST request with the specified properties" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
 | 
			
		||||
          .with(body: { "description" => "another_mn" })
 | 
			
		||||
          .to_return(body: JSON.generate(customer_fixture))
 | 
			
		||||
        Stripe::Customer.construct_from(customer_fixture)
 | 
			
		||||
        Stripe::Customer.update("cus_123", { description: "another_mn" })
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "saving should merge in returned properties" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
 | 
			
		||||
          .with(body: { "description" => "another_mn" })
 | 
			
		||||
          .to_return(body: JSON.generate(customer_fixture))
 | 
			
		||||
@ -333,14 +341,21 @@ module Stripe
 | 
			
		||||
        assert_equal false, c.livemode
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "updating should fail if api_key is overwritten with nil" do
 | 
			
		||||
      should "saving should fail if api_key is overwritten with nil" do
 | 
			
		||||
        c = Stripe::Customer.new
 | 
			
		||||
        assert_raises TypeError do
 | 
			
		||||
          c.save({}, api_key: nil)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "updating should use the supplied api_key" do
 | 
			
		||||
      should "updating should fail if api_key is nil" do
 | 
			
		||||
        Stripe::Customer.new("cus_123")
 | 
			
		||||
        assert_raises TypeError do
 | 
			
		||||
          Stripe::Customer.update("cus_123", {}, { api_key: nil })
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "saving should use the supplied api_key" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/customers")
 | 
			
		||||
          .with(headers: { "Authorization" => "Bearer sk_test_local" })
 | 
			
		||||
          .to_return(body: JSON.generate(customer_fixture))
 | 
			
		||||
@ -349,6 +364,14 @@ module Stripe
 | 
			
		||||
        assert_equal false, c.livemode
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "updating should use the supplied api_key" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/customers")
 | 
			
		||||
          .with(headers: { "Authorization" => "Bearer sk_test_local" })
 | 
			
		||||
          .to_return(body: JSON.generate(customer_fixture))
 | 
			
		||||
        Stripe::Customer.new("cus_123")
 | 
			
		||||
        Stripe::Customer.update("cus_123", {}, api_key: "sk_test_local")
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "deleting should send no props and result in an object that has no props other deleted" do
 | 
			
		||||
        stub_request(:delete, "#{Stripe.api_base}/v1/customers/cus_123")
 | 
			
		||||
          .to_return(body: JSON.generate("id" => "cus_123", "deleted" => true))
 | 
			
		||||
@ -385,7 +408,7 @@ module Stripe
 | 
			
		||||
        c.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "add key to nested objects" do
 | 
			
		||||
      should "add key to nested objects on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {
 | 
			
		||||
                                                size: "l",
 | 
			
		||||
@ -401,6 +424,14 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "update with a nested object" do
 | 
			
		||||
        stub_request(:post, "#{Stripe.api_base}/v1/accounts/myid")
 | 
			
		||||
          .with(body: { business_profile: { name: "Bob" } })
 | 
			
		||||
          .to_return(body: JSON.generate("id" => "myid"))
 | 
			
		||||
 | 
			
		||||
        Stripe::Account.update("myid", { business_profile: { name: "Bob" } })
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "save nothing if nothing changes" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "acct_id",
 | 
			
		||||
                                              metadata: {
 | 
			
		||||
@ -429,7 +460,7 @@ module Stripe
 | 
			
		||||
        ch.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle replaced nested objects" do
 | 
			
		||||
      should "correctly handle replaced nested objects on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(
 | 
			
		||||
          id: "acct_123",
 | 
			
		||||
          company: {
 | 
			
		||||
@ -449,7 +480,7 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle array setting" do
 | 
			
		||||
      should "correctly handle array setting on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {})
 | 
			
		||||
 | 
			
		||||
@ -461,7 +492,7 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle array insertion" do
 | 
			
		||||
      should "correctly handle array insertion on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {
 | 
			
		||||
                                                additional_owners: [],
 | 
			
		||||
@ -478,7 +509,7 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle array updates" do
 | 
			
		||||
      should "correctly handle array updates on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {
 | 
			
		||||
                                                additional_owners: [{ first_name: "Bob" }, { first_name: "Jane" }],
 | 
			
		||||
@ -495,7 +526,7 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle array noops" do
 | 
			
		||||
      should "correctly handle array noops on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {
 | 
			
		||||
                                                additional_owners: [{ first_name: "Bob" }],
 | 
			
		||||
@ -509,7 +540,7 @@ module Stripe
 | 
			
		||||
        acct.save
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      should "correctly handle hash noops" do
 | 
			
		||||
      should "correctly handle hash noops on save" do
 | 
			
		||||
        acct = Stripe::Account.construct_from(id: "myid",
 | 
			
		||||
                                              legal_entity: {
 | 
			
		||||
                                                address: { line1: "1 Two Three" },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user