Do not override attributes on dup by default scopes

This commit is contained in:
Hiroshige Umino
2013-02-26 11:32:04 +09:00
committed by Steve Klabnik
parent c90e24d087
commit 55a1765942
3 changed files with 13 additions and 1 deletions

View File

@@ -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.

View File

@@ -553,7 +553,6 @@ module ActiveRecord #:nodoc:
@new_record = true
ensure_proper_type
populate_with_current_scope_attributes
super
end

View File

@@ -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