diff options
author | Jefferson Lai <jefflai2@gmail.com> | 2014-02-10 03:00:05 -0800 |
---|---|---|
committer | Jefferson Lai <jefflai2@gmail.com> | 2014-04-23 17:21:45 -0700 |
commit | 9c3afdc327132c7f1f4d05eebc0c05b715442e7d (patch) | |
tree | 9c85b61fc019ee4c5a91fa4cf02bf39fd81fe008 /activerecord/test | |
parent | 9ed0cf51b467907810ef3959c8e9cdf77370370e (diff) | |
download | rails-9c3afdc327132c7f1f4d05eebc0c05b715442e7d.tar.gz rails-9c3afdc327132c7f1f4d05eebc0c05b715442e7d.tar.bz2 rails-9c3afdc327132c7f1f4d05eebc0c05b715442e7d.zip |
Fixes Issue #13466.
Changed the call to a scope block to be evaluated with instance_eval.
The result is that ScopeRegistry can use the actual class instead of base_class when
caching scopes so queries made by classes with a common ancestor won't leak scopes.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/scoping/named_scoping_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/ratings.yml | 10 | ||||
-rw-r--r-- | activerecord/test/models/comment.rb | 1 | ||||
-rw-r--r-- | activerecord/test/models/rating.rb | 4 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 2 |
5 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index f0ad9ebb8a..f66b76a7ad 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -2,12 +2,13 @@ require "cases/helper" require 'models/post' require 'models/topic' require 'models/comment' +require 'models/rating' require 'models/reply' require 'models/author' require 'models/developer' class NamedScopingTest < ActiveRecord::TestCase - fixtures :posts, :authors, :topics, :comments, :author_addresses + fixtures :posts, :authors, :topics, :comments, :author_addresses, :ratings def test_implements_enumerable assert !Topic.all.empty? @@ -115,6 +116,10 @@ class NamedScopingTest < ActiveRecord::TestCase assert_equal 1,SpecialPost.containing_the_letter_a.count end + def test_scope_subquery_with_STI + assert_nothing_raised { VerySpecialComment.special_parent(SpecialRating.first).count } + end + def test_has_many_through_associations_have_access_to_scopes assert_not_equal Comment.containing_the_letter_e, authors(:david).comments assert !Comment.containing_the_letter_e.empty? diff --git a/activerecord/test/fixtures/ratings.yml b/activerecord/test/fixtures/ratings.yml index 34e208efa3..2b45c5080e 100644 --- a/activerecord/test/fixtures/ratings.yml +++ b/activerecord/test/fixtures/ratings.yml @@ -2,13 +2,23 @@ normal_comment_rating: id: 1 comment_id: 8 value: 1 + type: Rating special_comment_rating: id: 2 comment_id: 6 value: 1 + type: Rating sub_special_comment_rating: id: 3 comment_id: 12 value: 1 + type: Rating + +special_rating: + id: 4 + comment_id: 10 + value: 1 + type: SpecialRating + special_comment_id: 3 diff --git a/activerecord/test/models/comment.rb b/activerecord/test/models/comment.rb index ede5fbd0c6..6a9dfacf56 100644 --- a/activerecord/test/models/comment.rb +++ b/activerecord/test/models/comment.rb @@ -35,4 +35,5 @@ class SubSpecialComment < SpecialComment end class VerySpecialComment < Comment + scope :special_parent, -> (special_rating) { where parent_id: special_rating.special_comment.id } end diff --git a/activerecord/test/models/rating.rb b/activerecord/test/models/rating.rb index 25a52c4ad7..5409230c2e 100644 --- a/activerecord/test/models/rating.rb +++ b/activerecord/test/models/rating.rb @@ -2,3 +2,7 @@ class Rating < ActiveRecord::Base belongs_to :comment has_many :taggings, :as => :taggable end + +class SpecialRating < Rating + belongs_to :special_comment +end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index b44e72a67c..cbcdf93673 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -579,7 +579,9 @@ ActiveRecord::Schema.define do create_table :ratings, force: true do |t| t.integer :comment_id + t.integer :special_comment_id t.integer :value + t.string :type end create_table :readers, force: true do |t| |