fixed connect method, add exception catching
Signed-off-by: Jason Guiditta jason.guiditta@gmail.com --- src/app/models/provider.rb | 14 +++++++------- src/test/unit/provider_test.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index 1832c54..f8d6f09 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -11,7 +11,12 @@ class Provider < ActiveRecord::Base validates_presence_of :url
def connect - DeltaCloud.new(nil, nil, provider.url) + begin + return DeltaCloud.new(nil, nil, url) + rescue Exception => e + #TODO: log or return an exception + return nil + end end
protected @@ -25,11 +30,6 @@ class Provider < ActiveRecord::Base private
def valid_framework? - begin - DeltaCloud.new(nil, nil, url) - return true - rescue Exception => e - return false - end + connect.nil? ? false : true end end diff --git a/src/test/unit/provider_test.rb b/src/test/unit/provider_test.rb index d9af732..877fd9c 100644 --- a/src/test/unit/provider_test.rb +++ b/src/test/unit/provider_test.rb @@ -23,4 +23,13 @@ class ProviderTest < ActiveSupport::TestCase @provider.url = "http://dcloud.awesome/api" flunk "Invalid url passed validation" unless @provider.invalid? end + + test "should return nil if no connection" do + assert_equal(nil, @provider.connect) + end + + test "should return DeltaCloud if successful connection" do + @provider.url = "http://localhost:3000/api" + assert_instance_of(DeltaCloud, @provider.connect) + end end
deltacloud-devel@lists.fedorahosted.org