2011-06-09 01:05:22 +02:00
|
|
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
|
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
|
|
|
2011-01-16 22:43:07 -02:00
|
|
|
require "bundler/setup"
|
2008-12-19 02:09:20 -08:00
|
|
|
require "rubygems"
|
2011-06-09 01:05:22 +02:00
|
|
|
require "rspec"
|
2008-12-19 02:09:20 -08:00
|
|
|
|
2011-06-09 01:05:22 +02:00
|
|
|
require 'couchrest_model'
|
2008-07-04 16:56:37 -07:00
|
|
|
|
2009-01-12 19:50:00 -08:00
|
|
|
unless defined?(FIXTURE_PATH)
|
2011-06-09 01:10:13 +02:00
|
|
|
MODEL_PATH = File.join(File.dirname(__FILE__), "fixtures", "models")
|
|
|
|
$LOAD_PATH.unshift(MODEL_PATH)
|
|
|
|
|
2009-01-29 18:45:01 -08:00
|
|
|
FIXTURE_PATH = File.join(File.dirname(__FILE__), '/fixtures')
|
|
|
|
SCRATCH_PATH = File.join(File.dirname(__FILE__), '/tmp')
|
2008-10-14 15:08:17 -07:00
|
|
|
|
2009-01-12 19:50:00 -08:00
|
|
|
COUCHHOST = "http://127.0.0.1:5984"
|
2010-06-20 22:01:11 +02:00
|
|
|
TESTDB = 'couchrest-model-test'
|
2010-09-29 18:11:59 -04:00
|
|
|
TEST_SERVER = CouchRest.new COUCHHOST
|
2009-01-29 18:45:01 -08:00
|
|
|
TEST_SERVER.default_database = TESTDB
|
2009-05-27 18:16:50 -07:00
|
|
|
DB = TEST_SERVER.database(TESTDB)
|
2009-01-12 19:50:00 -08:00
|
|
|
end
|
2008-11-08 16:28:58 -08:00
|
|
|
|
2011-06-09 01:05:22 +02:00
|
|
|
RSpec.configure do |config|
|
|
|
|
config.before(:all) { reset_test_db! }
|
|
|
|
|
|
|
|
config.after(:all) do
|
|
|
|
cr = TEST_SERVER
|
|
|
|
test_dbs = cr.databases.select { |db| db =~ /^#{TESTDB}/ }
|
|
|
|
test_dbs.each do |db|
|
|
|
|
cr.database(db).delete! rescue nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Require each of the fixture models
|
2011-06-09 01:10:13 +02:00
|
|
|
Dir[ File.join(MODEL_PATH, "*.rb") ].sort.each { |file| require File.basename(file) }
|
2011-06-09 01:05:22 +02:00
|
|
|
|
2010-06-20 22:01:11 +02:00
|
|
|
class Basic < CouchRest::Model::Base
|
2009-02-24 22:51:13 -08:00
|
|
|
use_database TEST_SERVER.default_database
|
|
|
|
end
|
|
|
|
|
2008-11-08 16:28:58 -08:00
|
|
|
def reset_test_db!
|
2009-07-14 23:48:06 -07:00
|
|
|
DB.recreate! rescue nil
|
2011-04-17 02:46:33 +02:00
|
|
|
# Reset the Design Cache
|
|
|
|
Thread.current[:couchrest_design_cache] = {}
|
2009-05-27 18:16:50 -07:00
|
|
|
DB
|
2009-03-21 12:14:42 +08:00
|
|
|
end
|
|
|
|
|
2010-03-11 11:17:15 -06:00
|
|
|
|
|
|
|
def couchdb_lucene_available?
|
|
|
|
lucene_path = "http://localhost:5985/"
|
|
|
|
url = URI.parse(lucene_path)
|
|
|
|
req = Net::HTTP::Get.new(url.path)
|
|
|
|
res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
|
|
|
true
|
|
|
|
rescue Exception => e
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|