mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-12-07 00:00:35 -05:00
Raise InvalidRequestError if no id provided
This commit is contained in:
parent
0813418b74
commit
24dcd8707e
@ -260,7 +260,11 @@ module Stripe
|
||||
shortname = self.name.split('::')[-1]
|
||||
"/#{CGI.escape(shortname.downcase)}s"
|
||||
end
|
||||
def url; "#{self.class.url}/#{CGI.escape(id)}"; end
|
||||
def url
|
||||
id = self['id']
|
||||
raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id') unless id
|
||||
"#{self.class.url}/#{CGI.escape(id)}"
|
||||
end
|
||||
|
||||
def refresh
|
||||
response, api_key = Stripe.request(:get, url, @api_key)
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
require File.dirname(__FILE__) + '/test_helper.rb'
|
||||
require 'test/unit'
|
||||
require 'context'
|
||||
@ -76,6 +77,11 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
assert_raises(Stripe::InvalidRequestError) { c.refresh }
|
||||
end
|
||||
|
||||
test "requesting with no ID shuold result in an InvalidRequestError with no request" do
|
||||
c = Stripe::Customer.new
|
||||
assert_raises(Stripe::InvalidRequestError) { c.refresh }
|
||||
end
|
||||
|
||||
test "loading an object should issue a GET request" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user