rails/rails — pull request #13710 by ujjwalt (2014-01-14 10:11:43+00:00)
Title: Active Record's subclass_from_attributes shouldn't assume :type is for STI unless there is a type column.

Active Record's subclass_from_attrs assumes type is for STI whether or not type exists as a column or not. This fixes this bug allowing you to use type as a reference in non-STI classes.

```ruby
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.2'
require 'active_record'
require 'minitest/autorun'
require 'logger'

# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

# 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 :products do |t|
t.references :type
t.string :name
end

add_index :products, :type_id

create_table :product_types do |t|
t.string :name
end

add_index :product_types, :name, unique: true
end

class Product < ActiveRecord::Base
class Type < ActiveRecord::Base
has_many :products
end

belongs_to :type
end

class BugTest < Minitest::Test
def test_sti_type_from_attributes_disabled_in_non_sti_class
phone = Product::Type.new(name: 'Phone')
product = Product.new(:type => phone)
assert product.save
end
end
```