1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Prevent duplicating where clauses when model is extended from an abstract class

Fixes #19528

fix for mysql2 test

better test
This commit is contained in:
Mehmet Emin İNAÇ 2015-04-15 21:00:09 +03:00
parent 4825042a1c
commit 929fcd2617
3 changed files with 14 additions and 0 deletions

View file

@ -100,6 +100,7 @@ module ActiveRecord
end
def build_default_scope(base_rel = relation) # :nodoc:
return if abstract_class?
if !Base.is_a?(method(:default_scope).owner)
# The user has defined their own default scope method, so call that
evaluate_default_scope { default_scope }

View file

@ -3,6 +3,7 @@ require 'models/post'
require 'models/comment'
require 'models/developer'
require 'models/computer'
require 'models/vehicle'
class DefaultScopingTest < ActiveRecord::TestCase
fixtures :developers, :posts, :comments
@ -441,4 +442,9 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal 1, scope.where_clause.ast.children.length
assert_equal Developer.where(name: "David"), scope
end
def test_with_abstract_class_where_clause_should_not_be_duplicated
scope = Bus.all
assert_equal scope.where_clause.ast.children.length, 1
end
end

View file

@ -0,0 +1,7 @@
class Vehicle < ActiveRecord::Base
self.abstract_class = true
default_scope -> { where("tires_count IS NOT NULL") }
end
class Bus < Vehicle
end