Skip to content

Instantly share code, notes, and snippets.

@nachokb
Last active August 29, 2015 14:11
Show Gist options
  • Save nachokb/b12c26af8fa4740d1230 to your computer and use it in GitHub Desktop.
Save nachokb/b12c26af8fa4740d1230 to your computer and use it in GitHub Desktop.
issue 18062
system 'rm Gemfile' if File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'activerecord',
'4.2.0.rc3'
# '4.1.8'
# '4.0.12'
# '3.2.21'
gem 'sqlite3'
GEMFILE
system 'bundle install'
require 'byebug'
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 :businesses do |t|
t.string :type
end
end
class Business < ActiveRecord::Base
end
class Foundation < Business
attr_accessor :lobbyist
end
class Company < Business
end
# class BugTest < Minitest::Test
class BugTest < MiniTest::Unit::TestCase
def setup
companya = Company.create
companyb = Company.create
foundationa = Foundation.create
foundationb = Foundation.create
end
def test_association_build_sti_1
assert_equal Business, Business.new.class
end
def test_association_build_sti_2
assert_equal Business, Business.where(type: 'Business').build.class
end
def test_association_build_sti_3
assert_equal Company, Business.where(type: 'Company').build.class
end
def test_association_build_sti_4
assert_equal Foundation, Business.where(type: 'Foundation').build.class
end
def test_association_build_sti_5
foundation = Business.where(type: 'Foundation', lobbyist: true).build
assert_equal Foundation, foundation.class
assert_not_nil foundation.lobbyist
end
def test_association_build_sti_6
assert_equal Company, Business.new(type: 'Company').class
end
def test_association_build_sti_7
assert_equal Foundation, Business.new(type: 'Foundation').class
end
def test_association_build_sti_8
assert_equal Foundation, Business.new(type: 'Foundation', lobbyist: true).class
end
end
@nachokb
Copy link
Author

nachokb commented Dec 19, 2014

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