diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-17 00:40:26 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-05-28 01:19:24 +0900 |
commit | c45c9cfb011fce54c319555c8852d915ff2ef97a (patch) | |
tree | c836e64a8033845fd010dd6cfeb6e5ac7812bea0 /activerecord/test | |
parent | 9b78974bc9f0dad0242d057b69f543471af2b92d (diff) | |
download | rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.tar.gz rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.tar.bz2 rails-c45c9cfb011fce54c319555c8852d915ff2ef97a.zip |
Cache the association proxy object
Some third party modules expects that association returns same proxy
object each time (e.g. for stubbing collection methods:
https://github.com/rspec/rspec-rails/issues/1817).
So I decided that cache the proxy object and reset scope in the proxy
object each time.
Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations_test.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 4ab690bfc6..ff31c82794 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -220,6 +220,11 @@ class AssociationProxyTest < ActiveRecord::TestCase assert_equal david.projects, david.projects.scope end + test "proxy object is cached" do + david = developers(:david) + assert_same david.projects, david.projects + end + test "inverses get set of subsets of the association" do man = Man.create man.interests.create |