Sha256: 5775b3e93e1015d7f87066763236a1009da0f3a6a836954cae6fa84a6a26994d
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'rubygems' require 'bundler/setup' require 'active_record' require 'locker' ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.default_timezone = "UTC" config = YAML.load_file(File.join(File.dirname(__FILE__), 'database.yml')) begin ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.connection.create_database(config['database'], config.merge("encoding" => config['encoding'] || ENV['CHARSET'] || 'utf8')) rescue ActiveRecord::StatementInvalid => e raise unless e.message =~ /database "locker_test" already exists/ end ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS locks") ActiveRecord::Base.connection.create_table(:locks) do |t| t.string :locked_by t.string :key t.datetime :locked_at t.datetime :locked_until end ActiveRecord::Base.connection.add_index :locks, :key, :unique => true class Lock < ActiveRecord::Base end class FakeLock attr_accessor :locked_by, :key, :locked_at, :locked_until cattr_accessor :fake_locks self.fake_locks = {} def self.find_by_key(key) fake_locks[key] end def self.create(attributes={}) fake_locks[attributes[:key]] = new(attributes) true end def initialize(attributes={}) attributes.each do |key, value| send("#{key}=", value) end end end RSpec.configure do |c| c.before do ActiveRecord::Base.connection.increment_open_transactions ActiveRecord::Base.connection.begin_db_transaction end c.after do ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.connection.decrement_open_transactions end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locker-0.0.3 | spec/spec_helper.rb |