diff options
-rw-r--r-- | lib/tapicero.rb | 6 | ||||
-rw-r--r-- | lib/tapicero/user_database.rb | 8 | ||||
-rw-r--r-- | lib/tapicero/user_event_handler.rb | 2 | ||||
-rw-r--r-- | test/test_helper.rb | 9 |
4 files changed, 20 insertions, 5 deletions
diff --git a/lib/tapicero.rb b/lib/tapicero.rb index 1063b85..a098287 100644 --- a/lib/tapicero.rb +++ b/lib/tapicero.rb @@ -8,7 +8,11 @@ module Tapicero attr_accessor :config end - + # reraise exceptions instead of retrying + # used in tests + unless defined? RERAISE + RERAISE = false + end # # Load Config # this must come first, because CouchRest needs the connection diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb index 6daccf3..26d013d 100644 --- a/lib/tapicero/user_database.rb +++ b/lib/tapicero/user_database.rb @@ -35,8 +35,9 @@ module Tapicero end def upload_design_doc(file) + old = CouchRest.get design_url(file.basename('.json')) + rescue RestClient::ResourceNotFound CouchRest.put design_url(file.basename('.json')), JSON.parse(file.read) - rescue RestClient::Conflict end @@ -53,7 +54,9 @@ module Tapicero protected def create_db - db.create! || db.info + db.info # test if db exists + rescue RestClient::ResourceNotFound + couch.create_db(db.name) end def delete_db @@ -66,6 +69,7 @@ module Tapicero Tapicero.logger.debug "#{action} #{db.name}" yield rescue RestClient::Exception => exc + raise exc if Tapicero::RERAISE if second_try log_error "#{action} #{db.name} failed twice due to:", exc else diff --git a/lib/tapicero/user_event_handler.rb b/lib/tapicero/user_event_handler.rb index d19e23d..38cf8f8 100644 --- a/lib/tapicero/user_event_handler.rb +++ b/lib/tapicero/user_event_handler.rb @@ -19,6 +19,8 @@ module Tapicero end end + protected + def prepare_db(id) db = user_database(id) db.create diff --git a/test/test_helper.rb b/test/test_helper.rb index da8b88c..5a3b509 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,13 +1,18 @@ require 'rubygems' require 'minitest/autorun' +require 'pathname' -BASE_DIR = File.expand_path('../..', __FILE__) -$:.unshift File.expand_path('lib', BASE_DIR) +unless defined? BASE_DIR + BASE_DIR = Pathname.new(__FILE__) + '../..' +end + +$:.unshift BASE_DIR + 'lib' require 'mocha/setup' require 'tapicero/version' Tapicero::CONFIGS << "test/config.yaml" +Tapicero::RERAISE = true require 'tapicero' |