mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
Do not override attributes on dup by default scopes
This commit is contained in:
committed by
Steve Klabnik
parent
c90e24d087
commit
55a1765942
@@ -1,5 +1,9 @@
|
||||
## unreleased ##
|
||||
|
||||
* Fix overriding of attributes by default_scope on `ActiveRecord::Base#dup`.
|
||||
|
||||
*Hiroshige UMINO*
|
||||
|
||||
* Fix issue with overriding Active Record reader methods with a composed object
|
||||
and using that attribute as the scope of a `uniqueness_of` validation.
|
||||
Backport #7072.
|
||||
|
||||
@@ -553,7 +553,6 @@ module ActiveRecord #:nodoc:
|
||||
@new_record = true
|
||||
|
||||
ensure_proper_type
|
||||
populate_with_current_scope_attributes
|
||||
super
|
||||
end
|
||||
|
||||
|
||||
@@ -113,5 +113,14 @@ module ActiveRecord
|
||||
assert topic.invalid?
|
||||
assert duped.valid?
|
||||
end
|
||||
|
||||
def test_dup_with_default_scope
|
||||
prev_default_scopes = Topic.default_scopes
|
||||
Topic.default_scopes = [Topic.where(:approved => true)]
|
||||
topic = Topic.new(:approved => false)
|
||||
assert !topic.dup.approved?, "should not be overriden by default scopes"
|
||||
ensure
|
||||
Topic.default_scopes = prev_default_scopes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user