diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-22 22:53:03 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-22 22:53:03 +0200 |
commit | 7035a205a37057be290d75a65a397e161839c598 (patch) | |
tree | 04dde031ef1b2638ececddba70ca3e7e7db7d3a7 /activerecord | |
parent | 22da898becb1e6d64ec6ed7894b2d58c217a0a71 (diff) | |
parent | 3529bbd8cab56db5fea527cdd2f21e7d2552d62e (diff) | |
download | rails-7035a205a37057be290d75a65a397e161839c598.tar.gz rails-7035a205a37057be290d75a65a397e161839c598.tar.bz2 rails-7035a205a37057be290d75a65a397e161839c598.zip |
Merge pull request #15866 from sgrif/sg-reload-attributes
`reload` should fully reload attributes
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/attribute_set.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 7 |
3 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb index 8f6b73eac2..5e5f7ca1b5 100644 --- a/activerecord/lib/active_record/attribute_set.rb +++ b/activerecord/lib/active_record/attribute_set.rb @@ -6,10 +6,6 @@ module ActiveRecord @attributes = attributes end - def update(other) - attributes.update(other.attributes) - end - def to_hash attributes.each_with_object({}) { |(k, v), h| h[k] = v.value } end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 6707f12489..86cc928644 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -395,7 +395,7 @@ module ActiveRecord self.class.unscoped { self.class.find(id) } end - @attributes.update(fresh_object.instance_variable_get('@attributes')) + @attributes = fresh_object.instance_variable_get('@attributes') @column_types = self.class.column_types self diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 28341d0b42..1192ecd6b4 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -858,4 +858,11 @@ class PersistenceTest < ActiveRecord::TestCase post.body end end + + def test_reload_removes_custom_selects + post = Post.select('posts.*, 1 as wibble').last! + + assert_equal 1, post[:wibble] + assert_nil post.reload[:wibble] + end end |