Permalink
Browse files

Improve error handling when access details not set

  • Loading branch information...
1 parent b90e9ef commit 9d0b5306f79b3ce6687b73101bec4ab56fb5350c @hmarr hmarr committed Nov 21, 2011
Showing with 23 additions and 2 deletions.
  1. +3 −1 lib/gocardless/resource.rb
  2. +20 −1 spec/resource_spec.rb
View
4 lib/gocardless/resource.rb
@@ -59,7 +59,9 @@ def find_with_client(client_obj, id)
end
def find(id)
- self.find_with_client(client, id)
+ message = "Merchant details not found, set GoCardless.account_details"
+ raise Error, message unless GoCardless.client
+ self.find_with_client(GoCardless.client, id)
end
def date_writer(*args)
View
21 spec/resource_spec.rb
@@ -58,7 +58,7 @@
end
end
- describe "#find_with_client" do
+ describe ".find_with_client" do
it "instantiates the correct object" do
test_resource = Class.new(GoCardless::Resource) do
self.endpoint = '/test/:id'
@@ -71,6 +71,25 @@
end
end
+ describe ".find" do
+ it "calls find with the default client" do
+ test_resource = Class.new(GoCardless::Resource) do
+ self.endpoint = '/test/:id'
+ end
+ GoCardless.stubs(:client => mock)
+ test_resource.expects(:find_with_client).with(GoCardless.client, 1)
+ test_resource.find(1)
+ unset_ivar GoCardless, :client
+ end
+
+ it "raises a helpful error when there is no default client" do
+ test_resource = Class.new(GoCardless::Resource) do
+ self.endpoint = '/test/:id'
+ end
+ expect { test_resource.find(1) }.to raise_error
+ end
+ end
+
describe "#reference_writer" do
it "creates reference writers properly" do
test_resource = Class.new(GoCardless::Resource) do

0 comments on commit 9d0b530

Please sign in to comment.