1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

attributes are cached by string keys, so to_s to support symbols. fixes #5549

This commit is contained in:
Aaron Patterson 2012-03-27 11:27:51 -07:00
parent b42fbd3ecb
commit e96d04a2e4
3 changed files with 17 additions and 2 deletions

View file

@ -118,7 +118,7 @@ module ActiveRecord
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name) def read_attribute(attr_name)
# If it's cached, just return it # If it's cached, just return it
@attributes_cache.fetch(attr_name) { |name| @attributes_cache.fetch(attr_name.to_s) { |name|
column = @columns_hash.fetch(name) { column = @columns_hash.fetch(name) {
return self.class.type_cast_attribute(name, @attributes, @attributes_cache) return self.class.type_cast_attribute(name, @attributes, @attributes_cache)
} }

View file

@ -62,7 +62,11 @@ end
class Weird < ActiveRecord::Base; end class Weird < ActiveRecord::Base; end
class Boolean < ActiveRecord::Base; end class Boolean < ActiveRecord::Base
def has_fun
super
end
end
class LintTest < ActiveRecord::TestCase class LintTest < ActiveRecord::TestCase
include ActiveModel::Lint::Tests include ActiveModel::Lint::Tests
@ -957,6 +961,16 @@ class BasicsTest < ActiveRecord::TestCase
assert b_true.value? assert b_true.value?
end end
def test_boolean_without_questionmark
b_true = Boolean.create({ "value" => true })
true_id = b_true.id
subclass = Class.new(Boolean).find true_id
superclass = Boolean.find true_id
assert_equal superclass.read_attribute(:has_fun), subclass.read_attribute(:has_fun)
end
def test_boolean_cast_from_string def test_boolean_cast_from_string
b_blank = Boolean.create({ "value" => "" }) b_blank = Boolean.create({ "value" => "" })
blank_id = b_blank.id blank_id = b_blank.id

View file

@ -91,6 +91,7 @@ ActiveRecord::Schema.define do
create_table :booleans, :force => true do |t| create_table :booleans, :force => true do |t|
t.boolean :value t.boolean :value
t.boolean :has_fun, :null => false, :default => false
end end
create_table :bulbs, :force => true do |t| create_table :bulbs, :force => true do |t|