aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/belongs_to_associations_test.rb
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2014-11-08 11:24:52 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2014-11-08 11:24:52 -0200
commita153fae6d9549961a81d0e43364c2b970b42730b (patch)
treedf9f6893d1fce9bdb44ad566209e06c9d0ac9aaf /activerecord/test/cases/associations/belongs_to_associations_test.rb
parentf8f02f4f6d73fd514d499063cceeaadbd823f273 (diff)
parent9bd43868502f5e8a67649ffb5e766853a05714c5 (diff)
downloadrails-a153fae6d9549961a81d0e43364c2b970b42730b.tar.gz
rails-a153fae6d9549961a81d0e43364c2b970b42730b.tar.bz2
rails-a153fae6d9549961a81d0e43364c2b970b42730b.zip
Merge pull request #17559 from alfa-jpn/fix/singular_association_cache
default scopes should break the cache on singulur_association.
Diffstat (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb')
-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 }