Skip to content

Instantly share code, notes, and snippets.

@jfoley
Created May 4, 2013 21: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 jfoley/5518882 to your computer and use it in GitHub Desktop.
Save jfoley/5518882 to your computer and use it in GitHub Desktop.
Failing test for rails/rails#3882
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
4.1.0.beta
-- create_table(:companies, {:force=>true})
D, [2013-05-04T15:53:21.940407 #17627] DEBUG -- : (0.2ms) CREATE TABLE "companies" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
-> 0.0144s
-- create_table(:departments, {:force=>true})
D, [2013-05-04T15:53:21.941014 #17627] DEBUG -- : (0.1ms) CREATE TABLE "departments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "company_id" integer)
-> 0.0005s
-- create_table(:designers, {:force=>true})
D, [2013-05-04T15:53:21.941456 #17627] DEBUG -- : (0.1ms) CREATE TABLE "designers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
-> 0.0004s
-- create_table(:developers, {:force=>true})
D, [2013-05-04T15:53:21.941872 #17627] DEBUG -- : (0.1ms) CREATE TABLE "developers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)
-> 0.0004s
-- create_table(:users, {:force=>true})
D, [2013-05-04T15:53:21.942380 #17627] DEBUG -- : (0.1ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "employable_id" integer, "employable_type" varchar(255), "department_id" integer)
-> 0.0005s
Run options: --seed 20450
# Running tests:
D, [2013-05-04T15:53:21.951495 #17627] DEBUG -- : (0.0ms) begin transaction
D, [2013-05-04T15:53:21.955949 #17627] DEBUG -- : SQL (0.5ms) INSERT INTO "companies" DEFAULT VALUES
D, [2013-05-04T15:53:21.956316 #17627] DEBUG -- : (0.1ms) commit transaction
D, [2013-05-04T15:53:21.963813 #17627] DEBUG -- : (0.0ms) begin transaction
D, [2013-05-04T15:53:21.970616 #17627] DEBUG -- : SQL (1.8ms) INSERT INTO "departments" ("company_id") VALUES (?) [["company_id", 1]]
D, [2013-05-04T15:53:21.970901 #17627] DEBUG -- : (0.1ms) commit transaction
D, [2013-05-04T15:53:21.972983 #17627] DEBUG -- : (0.0ms) begin transaction
D, [2013-05-04T15:53:21.975407 #17627] DEBUG -- : SQL (0.1ms) INSERT INTO "developers" DEFAULT VALUES
D, [2013-05-04T15:53:21.975671 #17627] DEBUG -- : (0.1ms) commit transaction
D, [2013-05-04T15:53:21.975993 #17627] DEBUG -- : (0.0ms) begin transaction
D, [2013-05-04T15:53:21.985272 #17627] DEBUG -- : SQL (0.2ms) INSERT INTO "users" ("department_id", "employable_id", "employable_type") VALUES (?, ?, ?) [["department_id", 1], ["employable_id", 1], ["employable_type", "Developer"]]
D, [2013-05-04T15:53:21.985566 #17627] DEBUG -- : (0.1ms) commit transaction
D, [2013-05-04T15:53:21.986433 #17627] DEBUG -- : (0.0ms) begin transaction
D, [2013-05-04T15:53:21.989047 #17627] DEBUG -- : SQL (0.1ms) INSERT INTO "designers" DEFAULT VALUES
D, [2013-05-04T15:53:21.989346 #17627] DEBUG -- : (0.1ms) commit transaction
D, [2013-05-04T15:53:21.989726 #17627] DEBUG -- : (0.1ms) begin transaction
D, [2013-05-04T15:53:21.990898 #17627] DEBUG -- : SQL (0.1ms) INSERT INTO "users" ("department_id", "employable_id", "employable_type") VALUES (?, ?, ?) [["department_id", 1], ["employable_id", 1], ["employable_type", "Designer"]]
D, [2013-05-04T15:53:21.991099 #17627] DEBUG -- : (0.0ms) commit transaction
D, [2013-05-04T15:53:22.014818 #17627] DEBUG -- : (0.2ms) SELECT COUNT(*) FROM "designers" INNER JOIN "users" ON "designers"."id" = "users"."employable_id" INNER JOIN "departments" ON "users"."department_id" = "departments"."id" WHERE "users"."employable_type" = 'Designer' AND "departments"."company_id" = ? [["company_id", 1]]
D, [2013-05-04T15:53:22.015986 #17627] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "users" INNER JOIN "departments" ON "users"."department_id" = "departments"."id" WHERE "users"."employable_type" = 'Designer' AND "departments"."company_id" = ? [["company_id", 1]]
F
Fabulous tests in 0.072217s, 13.8472 tests/s, 27.6943 assertions/s.
1) Failure:
BugTest#test_polymorphic_counts [test_case.rb:76]:
Expected: 2
Actual: 1
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
gem 'activerecord'
require 'sqlite3'
require 'active_record'
require "minitest/autorun"
require 'minitest/pride'
require 'logger'
puts `ruby -v`
puts ActiveRecord::VERSION::STRING
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :companies, force: true do |t|
end
create_table :departments, force: true do |t|
t.integer :company_id
end
create_table :designers, force: true do |t|
end
create_table :developers, force: true do |t|
end
create_table :users, force: true do |t|
t.integer :employable_id
t.string :employable_type
t.integer :department_id
end
end
class Company < ActiveRecord::Base
has_many :departments
has_many :users, through: :departments
has_many :developers, source_type: 'Developer', source: :employable, through: :users
has_many :designers, source_type: 'Designer', source: :employable, through: :users
end
class Department < ActiveRecord::Base
has_many :users
belongs_to :company
end
class User < ActiveRecord::Base
belongs_to :employable, polymorphic: true
end
class Designer < ActiveRecord::Base
has_one :user, as: :employable
end
class Developer < ActiveRecord::Base
has_one :user, as: :employable
end
class BugTest < MiniTest::Unit::TestCase
def setup
@company = Company.create!
@department = @company.departments.create!
@department.users.create!(employable: Developer.create!)
@department.users.create!(employable: Designer.create!)
end
def test_polymorphic_counts
assert_equal 1, @company.designers.size
assert_equal 2, @company.users.size
end
def teardown
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment