rails/rails — pull request #8055 by frodsan (2012-10-28 18:54:42+00:00)
Title: AR::AttributeMethods#[] should raise AM::AttributeMissingError if given ...

...attribute is missing

This fixes the following behaviour:

class Person < ActiveRecord::Base
belongs_to :company
end

# Before:
person = Person.select('id').first
person[:name] # => nil
person.name # => ActiveModel::MissingAttributeError
person[:company_id] # => nil
person.company # => nil

# After:
person = Person.select('id').first
person[:name] # => ActiveModel::MissingAttributeError
person.name # => ActiveModel::MissingAttributeError
person[:company_id] # => ActiveModel::MissingAttributeError
person.company # => ActiveModel::MissingAttributeError

Fixes #5433.