diff options
author | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-09-16 19:21:56 +0530 |
---|---|---|
committer | Prathamesh Sonpatki <csonpatki@gmail.com> | 2016-12-08 23:59:10 +0530 |
commit | 9cbf54c81a46cc070f3997956c12915f39dbb46b (patch) | |
tree | 37f46f943cfa46866cd654cc7d60f043f08d0e96 /activerecord/test/cases | |
parent | 17b09f4fca976063187be6494e64430850c37632 (diff) | |
download | rails-9cbf54c81a46cc070f3997956c12915f39dbb46b.tar.gz rails-9cbf54c81a46cc070f3997956c12915f39dbb46b.tar.bz2 rails-9cbf54c81a46cc070f3997956c12915f39dbb46b.zip |
Check whether the current attribute being read is aliased or not before reading
- If aliased, then use the aliased attribute name.
- Fixes #26417.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index ba6877a6a6..a89ecc32a6 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -329,6 +329,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal "Don't change the topic", topic[:title] end + test "read_attribute can read aliased attributes as well" do + topic = Topic.new(title: "Don't change the topic") + + assert_equal "Don't change the topic", topic.read_attribute("heading") + assert_equal "Don't change the topic", topic["heading"] + + assert_equal "Don't change the topic", topic.read_attribute(:heading) + assert_equal "Don't change the topic", topic[:heading] + end + test "read_attribute raises ActiveModel::MissingAttributeError when the attribute does not exist" do computer = Computer.select("id").first assert_raises(ActiveModel::MissingAttributeError) { computer[:developer] } |