test/stripe/api_resource_test.rb in stripe-1.8.8 vs test/stripe/api_resource_test.rb in stripe-1.9.9

- old
+ new

@@ -3,16 +3,16 @@ module Stripe class ApiResourceTest < Test::Unit::TestCase should "creating a new APIResource should not fetch over the network" do @mock.expects(:get).never - c = Stripe::Customer.new("someid") + Stripe::Customer.new("someid") end should "creating a new APIResource from a hash should not fetch over the network" do @mock.expects(:get).never - c = Stripe::Customer.construct_from({ + Stripe::Customer.construct_from({ :id => "somecustomer", :card => {:id => "somecard", :object => "card"}, :object => "customer" }) end @@ -183,18 +183,18 @@ uri = URI(url) query = CGI.parse(uri.query) (url =~ %r{^#{Stripe.api_base}/v1/charges?} && query.keys.sort == ['offset', 'sad']) end.returns(test_response({ :count => 1, :data => [test_charge] })) - c = Stripe::Charge.all(:count => nil, :offset => 5, :sad => false) + Stripe::Charge.all(:count => nil, :offset => 5, :sad => false) @mock.expects(:post).with do |url, api_key, params| - url == "#{Stripe.api_base}/v1/charges" && - api_key.nil? && + url == "#{Stripe.api_base}/v1/charges" && + api_key.nil? && CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] } end.returns(test_response({ :count => 1, :data => [test_charge] })) - c = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil }) + Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil }) end should "requesting with a unicode ID should result in a request" do response = test_response(test_missing_id_error, 404) @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404)) @@ -208,19 +208,19 @@ end should "making a GET request with parameters should have a query string and no body" do params = { :limit => 1 } @mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).returns(test_response([test_charge])) - c = Stripe::Charge.all(params) + Stripe::Charge.all(params) end should "making a POST request with parameters should have a body and no query string" do params = { :amount => 100, :currency => 'usd', :card => 'sc_token' } @mock.expects(:post).once.with do |url, get, post| get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']} end.returns(test_response(test_charge)) - c = Stripe::Charge.create(params) + Stripe::Charge.create(params) end should "loading an object should issue a GET request" do @mock.expects(:get).once.returns(test_response(test_customer)) c = Stripe::Customer.new("test_customer") @@ -292,53 +292,56 @@ should "404s should raise an InvalidRequestError" do response = test_response(test_missing_id_error, 404) @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404)) + rescued = false begin Stripe::Customer.new("test_customer").refresh assert false #shouldn't get here either rescue Stripe::InvalidRequestError => e # we don't use assert_raises because we want to examine e + rescued = true assert e.kind_of? Stripe::InvalidRequestError assert_equal "id", e.param assert_equal "Missing id", e.message - return end - assert false #shouldn't get here + assert_equal true, rescued end should "5XXs should raise an APIError" do response = test_response(test_api_error, 500) @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500)) + rescued = false begin Stripe::Customer.new("test_customer").refresh assert false #shouldn't get here either rescue Stripe::APIError => e # we don't use assert_raises because we want to examine e + rescued = true assert e.kind_of? Stripe::APIError - return end - assert false #shouldn't get here + assert_equal true, rescued end should "402s should raise a CardError" do response = test_response(test_invalid_exp_year_error, 402) @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 402)) + rescued = false begin Stripe::Customer.new("test_customer").refresh assert false #shouldn't get here either rescue Stripe::CardError => e # we don't use assert_raises because we want to examine e + rescued = true assert e.kind_of? Stripe::CardError assert_equal "invalid_expiry_year", e.code assert_equal "exp_year", e.param assert_equal "Your card's expiration year is invalid", e.message - return end - assert false #shouldn't get here + assert_equal true, rescued end end end end end