aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authoralfa-jpn <a.nkmr.ja@gmail.com>2014-11-08 17:03:54 +0900
committeralfa-jpn <a.nkmr.ja@gmail.com>2014-11-08 17:03:54 +0900
commit9bd43868502f5e8a67649ffb5e766853a05714c5 (patch)
tree73822e597d3a868ea1b5d9e60bfcc60d9d70a79e /activerecord/test
parentcb976371e43c90a995afb1224c325c7eed4fc194 (diff)
downloadrails-9bd43868502f5e8a67649ffb5e766853a05714c5.tar.gz
rails-9bd43868502f5e8a67649ffb5e766853a05714c5.tar.bz2
rails-9bd43868502f5e8a67649ffb5e766853a05714c5.zip
default scopes should break the cache on singulur_association.
fixes #17495
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 25555bd75c..bcd0cf82d5 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -57,6 +57,35 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_default_scope_on_relations_is_not_cached
+ counter = 0
+
+ comments = Class.new(ActiveRecord::Base) {
+ self.table_name = 'comments'
+ self.inheritance_column = 'not_there'
+
+ posts = Class.new(ActiveRecord::Base) {
+ self.table_name = 'posts'
+ self.inheritance_column = 'not_there'
+
+ default_scope -> {
+ counter += 1
+ where("id = :inc", :inc => counter)
+ }
+
+ has_many :comments, :class => comments
+ }
+ belongs_to :post, :class => posts, :inverse_of => false
+ }
+
+ assert_equal 0, counter
+ comment = comments.first
+ assert_equal 0, counter
+ sql = capture_sql { comment.post }
+ comment.reload
+ assert_not_equal sql, capture_sql { comment.post }
+ end
+
def test_proxy_assignment
account = Account.find(1)
assert_nothing_raised { account.firm = account.firm }