spec/spec_helper.rb in do_postgres-0.9.9 vs spec/spec_helper.rb in do_postgres-0.9.10
- old
+ new
@@ -1,57 +1,76 @@
$TESTING=true
+JRUBY = RUBY_PLATFORM =~ /java/
require 'rubygems'
gem 'rspec', '>=1.1.3'
require 'spec'
require 'date'
+require 'ostruct'
require 'pathname'
require 'fileutils'
require 'bigdecimal'
# put data_objects from repository in the load path
# DO NOT USE installed gem of data_objects!
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_objects', 'lib'))
require 'data_objects'
+if JRUBY
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
+ require 'do_jdbc'
+end
+
# put the pre-compiled extension in the path to be found
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'do_postgres'
log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
FileUtils.mkdir_p(File.dirname(log_path))
DataObjects::Postgres.logger = DataObjects::Logger.new(log_path, 0)
+POSTGRES = OpenStruct.new
+POSTGRES.user = ENV['DO_PG_USER'] || 'postgres'
+POSTGRES.pass = ENV['DO_PG_PASS'] || ''
+POSTGRES.host = ENV['DO_PG_HOST'] || '127.0.0.1'
+POSTGRES.hostname = ENV['DO_PG_HOSTNAME'] || 'localhost'
+POSTGRES.port = ENV['DO_PG_PORT'] || '5432'
+POSTGRES.database = ENV['DO_PG_DATABASE'] || 'do_test'
+
+DO_POSTGRES_SPEC_URI = Addressable::URI::parse(ENV["DO_PG_SPEC_URI"] ||
+ "postgres://#{POSTGRES.user}:#{POSTGRES.pass}@#{POSTGRES.hostname}:#{POSTGRES.port}/#{POSTGRES.database}")
+
module PostgresSpecHelpers
def ensure_users_table_and_return_connection
- connection = DataObjects::Connection.new("postgres://postgres@localhost/do_test")
+ connection = DataObjects::Connection.new(DO_POSTGRES_SPEC_URI)
connection.create_command("DROP TABLE users").execute_non_query rescue nil
connection.create_command("DROP TABLE companies").execute_non_query rescue nil
connection.create_command(<<-EOF).execute_non_query
CREATE TABLE users (
id serial NOT NULL,
"name" text,
registered boolean DEFAULT false,
money double precision DEFAULT 1908.56,
created_on date DEFAULT ('now'::text)::date,
created_at timestamp without time zone DEFAULT now(),
--- born_at time without time zone DEFAULT now(),
+ born_at time without time zone DEFAULT now(),
fired_at timestamp with time zone DEFAULT now(),
+ amount numeric(10,2) DEFAULT 11.1,
company_id integer DEFAULT 1
)
- WITH (OIDS=FALSE);
+ WITHOUT OIDS;
EOF
connection.create_command(<<-EOF).execute_non_query
CREATE TABLE companies (
id serial NOT NULL,
"name" character varying
)
- WITH (OIDS=FALSE);
+ WITHOUT OIDS;
EOF
return connection
end