Skip to content

Commit

Permalink
Merge pull request #86 from mtaylor/fix_connection_error
Browse files Browse the repository at this point in the history
Fix connection error
  • Loading branch information
jguiditta committed Dec 17, 2012
2 parents 5ea2d92 + 99f90b2 commit 0dc497f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/exceptions/tim/exceptions.rb
@@ -0,0 +1,6 @@
module Tim
module Error
class ImagefactoryConnectionRefused < ::StandardError
end
end
end
3 changes: 3 additions & 0 deletions app/models/tim/provider_image.rb
Expand Up @@ -47,6 +47,9 @@ def create_factory_provider_image
provider_image.save!
populate_factory_fields(provider_image)
self.save
rescue Errno::ECONNREFUSED
raise Tim::Error::ImagefactoryConnectionRefused.new("Unable to connect"\
" to Imagefactory server @ #{Tim::ImageFactory::Base.site}")
rescue => e
# TODO Add proper error handling
raise e
Expand Down
3 changes: 3 additions & 0 deletions app/models/tim/target_image.rb
Expand Up @@ -50,6 +50,9 @@ def create_factory_target_image

populate_factory_fields(target_image)
self.save
rescue Errno::ECONNREFUSED
raise Tim::Error::ImagefactoryConnectionRefused.new("Unable to connect"\
" to Imagefactory server @ #{Tim::ImageFactory::Base.site}")
rescue => e
# TODO Add proper error handling
raise e
Expand Down
5 changes: 5 additions & 0 deletions lib/tim/engine.rb
Expand Up @@ -16,6 +16,11 @@ class Engine < Rails::Engine
Dir[Tim::Engine.root.join('app', 'patches', '**', '*.rb')].each do |p|
require p
end

# Load Exceptions
Dir[Tim::Engine.root.join('app', 'exceptions', '**', '*.rb')].each do |e|
require e
end
end
end
end
9 changes: 9 additions & 0 deletions spec/models/provider_image_spec.rb
Expand Up @@ -77,6 +77,15 @@ module Tim
ti.should_not_receive(:create_factory_provider_image)
ti.save
end

it "should raise ImagefactoryConnectionRefused exception when it can"\
" not connect to Imagefactory" do
expect {
Tim::ImageFactory::ProviderImage.stub(:new).and_raise(Errno::ECONNREFUSED)
provider_image = FactoryGirl.build(:provider_image_with_full_tree)
provider_image.send(:create_factory_provider_image)
}.to raise_error(Tim::Error::ImagefactoryConnectionRefused)
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/models/target_image_spec.rb
Expand Up @@ -112,6 +112,15 @@ module Tim
mock_target_image.should_receive(:save!)
target_image.save
end

it "should raise ImagefactoryConnectionRefused exception when it can"\
" not connect to Imagefactory" do
expect {
Tim::ImageFactory::TargetImage.stub(:new).and_raise(Errno::ECONNREFUSED)
target_image = TargetImage.new
target_image.send(:create_factory_target_image)
}.to raise_error(Tim::Error::ImagefactoryConnectionRefused)
end
end
end
end
Expand Down

0 comments on commit 0dc497f

Please sign in to comment.