Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 85 lines (72 sloc) 2.105 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 84 85
require 'spec'
require 'rubygems'
require 'ruby-debug'
require 'activerecord'

ENV['TZ'] = 'UTC'
Time.zone = 'Eastern Time (US & Canada)'

ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
ActiveRecord::Base.configurations = true

ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define(:version => 1) do
  create_table :companies do |t|
    t.datetime :created_at
    t.datetime :updated_at
    t.string :name
    t.integer :users_count, :default => 0
  end
  
  create_table :users do |t|
    t.datetime :created_at
    t.datetime :updated_at
    t.integer :company_id
    t.string :username
    t.string :name
    t.integer :age
  end
  
  create_table :orders do |t|
    t.datetime :created_at
    t.datetime :updated_at
    t.integer :user_id
    t.date :shipped_on
    t.float :taxes
    t.float :total
  end
  
  create_table :line_items do |t|
    t.datetime :created_at
    t.datetime :updated_at
    t.integer :order_id
    t.float :price
  end
end

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'searchlogic'

Spec::Runner.configure do |config|
  config.before(:each) do
    class Company < ActiveRecord::Base
      has_many :users, :dependent => :destroy
    end
    
    class User < ActiveRecord::Base
      belongs_to :company, :counter_cache => true
      has_many :orders, :dependent => :destroy
      named_scope :uname, lambda { |value| {:conditions => ["users.username = ?", value]} }
      alias_scope :username_has, lambda { |value| username_like(value) }
    end
    
    class Order < ActiveRecord::Base
      belongs_to :user
      has_many :line_items, :dependent => :destroy
    end
    
    class LineItem < ActiveRecord::Base
      belongs_to :order
    end
    
    Company.destroy_all
    User.destroy_all
    Order.destroy_all
    LineItem.destroy_all
  end
  
  config.after(:each) do
    Object.send(:remove_const, :Company)
    Object.send(:remove_const, :User)
    Object.send(:remove_const, :Order)
    Object.send(:remove_const, :LineItem)
  end
end
Something went wrong with that request. Please try again.