Permalink
Browse files

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

  • Loading branch information...
1 parent b42fbd3 commit e96d04a2e4e244ea5053cb4e8ab97db604d0c796 @tenderlove tenderlove committed Mar 27, 2012
@@ -118,7 +118,7 @@ def attribute_cast_code(attr_name)
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
# 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) {
return self.class.type_cast_attribute(name, @attributes, @attributes_cache)
}
@@ -62,7 +62,11 @@ class ProtectedTitlePost < Post
class Weird < ActiveRecord::Base; end
-class Boolean < ActiveRecord::Base; end
+class Boolean < ActiveRecord::Base
+ def has_fun
+ super
+ end
+end
class LintTest < ActiveRecord::TestCase
include ActiveModel::Lint::Tests
@@ -957,6 +961,16 @@ def test_boolean
assert b_true.value?
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
b_blank = Boolean.create({ "value" => "" })
blank_id = b_blank.id
@@ -91,6 +91,7 @@ def create_table(*args, &block)
create_table :booleans, :force => true do |t|
t.boolean :value
+ t.boolean :has_fun, :null => false, :default => false
end
create_table :bulbs, :force => true do |t|

0 comments on commit e96d04a

Please sign in to comment.