Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 71b7b71030
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (70 sloc) 1.767 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
$TESTING=true
$:.push File.join(File.dirname(__FILE__), '..', 'lib')

require 'rubygems'
require 'active_record'
# require 'ruby-debug' # Slows down the tests massively

require 'eb_nested_set'

require 'spec'

# change this if sqlite is unavailable
dbconfig = case ENV["DB"]
  when "postgresql"
    {
      :adapter => 'postgresql',
      :database => 'eb_nested_set_test',
      :host => '127.0.0.1'
    }
  when "mysql"
    {
      :adapter => 'mysql',
      :database => 'eb_nested_set_test',
      :host => '127.0.0.1'
    }
  else
    {
      :adapter => 'sqlite3',
      :database => File.join(File.dirname(__FILE__), 'db', 'test.sqlite3')
    }
  end

ActiveRecord::Base.establish_connection(dbconfig)
ActiveRecord::Migration.verbose = false

def show_model_variables_for(context, model)
  context.instance_variables.sort.each do |i|
    m = eval(i)
    if m.is_a?(model)
      m.reload
      puts "#{i.ljust(8)}\t#{m.left}\t#{m.right}\t#{m.name}"
    end
  end
end

#ActiveRecord::Base.logger = Logger.new(STDOUT)


class TestMigration < ActiveRecord::Migration
  def self.up
    create_table :directories, :force => true do |t|
      t.column :lft, :integer
      t.column :rgt, :integer
      t.column :parent_id, :integer
      t.column :name, :string
    end
    
    create_table :employees, :force => true do |t|
      t.column :left, :integer
      t.column :right, :integer
      t.column :parent_id, :integer
      t.column :name, :string
      t.column :company_id, :integer
    end
  end

  def self.down
    drop_table :directories
    drop_table :employees
  rescue
    nil
  end
end

def without_changing_the_database
  ActiveRecord::Base.transaction do
    yield
    raise ActiveRecord::Rollback
  end
end

TestMigration.down
TestMigration.up
Something went wrong with that request. Please try again.