Skip to content

Instantly share code, notes, and snippets.

@chancancode
Forked from arthurnn/ar_sample2.rb
Created November 29, 2013 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chancancode/7713074 to your computer and use it in GitHub Desktop.
Save chancancode/7713074 to your computer and use it in GitHub Desktop.
require 'active_record'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: 'foobar.db'
class Record < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.string :name
end
end
class Foo < ActiveRecord::Base
connection.create_table table_name, force: true do |t|
t.string :name
t.belongs_to :record
end
belongs_to :record
end
class Test < MiniTest::Unit::TestCase
def test_ar
rec = Record.create!(name: 'record')
foo = Foo.create!(name: 'foo', record: rec)
assert_equal 1, Record.count
assert 1, Foo.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment