Skip to content

Commit

Permalink
Move database setup into spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Aug 27, 2010
1 parent 4d60b33 commit 4efba64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
16 changes: 3 additions & 13 deletions spec/pickle/orm_adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
require 'spec_helper'

begin
require 'activerecord'
rescue LoadError
require 'active_record'
rescue LoadError
if !defined?(ActiveRecord::Base)
puts "** install activerecord to run the specs in #{__FILE__}"
end

if defined?(ActiveRecord::Base)
else
require 'pickle/orm_adapters/active_record'

#
# setup an activerecord db, and classes, specs are below
#

database = File.join(File.dirname(__FILE__), '../../../tmp/active_record.sqlite')
`mkdir -p #{File.dirname(database)}`
Expand All @@ -27,7 +19,7 @@
end
end

# stick the ActiveRecord classes and specs in a namespace to isolate them from the other specs
# stick the ActiveRecord classes and specs in a namespace to isolate them
module ArOrmSpec
class User < ActiveRecord::Base
belongs_to :site, :class_name => "ArOrmSpec::Site"
Expand All @@ -47,9 +39,7 @@ class Note < AbstractNoteClass
belongs_to :owner, :polymorphic => true
end

#
# here be the specs!
#
describe ActiveRecord::Base::PickleOrmAdapter do
before { DatabaseCleaner.clean }

Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'rubygems'
require 'spec'
require 'active_support'
require 'active_record'

$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'pickle'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

require 'active_support'
4 changes: 4 additions & 0 deletions spec/support/database.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'active_record'
require 'database_cleaner'

DatabaseCleaner.strategy = :truncation

0 comments on commit 4efba64

Please sign in to comment.