Skip to content

Instantly share code, notes, and snippets.

@senny
Last active August 29, 2015 14:01
Show Gist options
  • Save senny/f3ae65b439e801d4d31c to your computer and use it in GitHub Desktop.
Save senny/f3ae65b439e801d4d31c to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts do |t|
end
create_table :articles do |t|
end
end
class Post < ActiveRecord::Base
self.table_name = "posts"
end
class Articles < Post
self.table_name = "articles"
end
class BugTest < Minitest::Test
def test_association_stuff
article = Articles.create!
post = Post.create!
assert_equal article, Articles.base_class.where(id: 1).first!
end
end
@senny
Copy link
Author

senny commented May 6, 2014

activerecord :: (master*) » ruby test.rb                                                                                                                                                                                                                                                                                                 ~/Projects/rails/activerecord 1 ↵
-- create_table(:posts)
D, [2014-05-06T13:37:13.485279 #68305] DEBUG -- :    (0.8ms)  CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
   -> 0.0264s
-- create_table(:articles)
D, [2014-05-06T13:37:13.486315 #68305] DEBUG -- :    (0.2ms)  CREATE TABLE "articles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
   -> 0.0009s
Run options: --seed 33393

# Running:

D, [2014-05-06T13:37:13.521377 #68305] DEBUG -- :    (0.1ms)  begin transaction
D, [2014-05-06T13:37:13.527599 #68305] DEBUG -- :   SQL (0.1ms)  INSERT INTO "articles" DEFAULT VALUES
D, [2014-05-06T13:37:13.528028 #68305] DEBUG -- :    (0.1ms)  commit transaction
D, [2014-05-06T13:37:13.528462 #68305] DEBUG -- :    (0.1ms)  begin transaction
D, [2014-05-06T13:37:13.529382 #68305] DEBUG -- :   SQL (0.1ms)  INSERT INTO "posts" DEFAULT VALUES
D, [2014-05-06T13:37:13.529645 #68305] DEBUG -- :    (0.1ms)  commit transaction
D, [2014-05-06T13:37:13.537227 #68305] DEBUG -- :   Post Load (0.2ms)  SELECT  "posts".* FROM "posts" WHERE "posts"."id" = ?  ORDER BY "posts"."id" ASC LIMIT 1  [["id", 1]]
F

Finished in 0.029366s, 34.0530 runs/s, 34.0530 assertions/s.

  1) Failure:
BugTest#test_association_stuff [test.rb:33]:
Expected: #<Articles id: 1>
  Actual: #<Post id: 1>

1 runs, 1 assertions, 1 failures, 0 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment