aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-27 11:27:51 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-27 11:27:51 -0700
commite96d04a2e4e244ea5053cb4e8ab97db604d0c796 (patch)
tree858c566b0893a23753bac11d8c3cf5ce5295b633 /activerecord
parentb42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4 (diff)
downloadrails-e96d04a2e4e244ea5053cb4e8ab97db604d0c796.tar.gz
rails-e96d04a2e4e244ea5053cb4e8ab97db604d0c796.tar.bz2
rails-e96d04a2e4e244ea5053cb4e8ab97db604d0c796.zip
attributes are cached by string keys, so to_s to support symbols. fixes #5549
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb2
-rw-r--r--activerecord/test/cases/base_test.rb16
-rw-r--r--activerecord/test/schema/schema.rb1
3 files changed, 17 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 846ac03d82..37f440b44f 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -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)).
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)
}
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index fb2f66c4f8..ff39285f62 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -62,7 +62,11 @@ 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
include ActiveModel::Lint::Tests
@@ -957,6 +961,16 @@ class BasicsTest < ActiveRecord::TestCase
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
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 428a85ab4e..5e7985c530 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -91,6 +91,7 @@ ActiveRecord::Schema.define do
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|