Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not override attributes on `dup` by default scopes

  • Loading branch information...
commit 55a1765942bc3d78ba5d449b5daf17a3c902e57c 1 parent c90e24d
Hiroshige Umino yaotti authored steveklabnik committed
4 activerecord/CHANGELOG.md
View
@@ -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.
1  activerecord/lib/active_record/base.rb
View
@@ -553,7 +553,6 @@ def initialize_dup(other)
@new_record = true
ensure_proper_type
- populate_with_current_scope_attributes
super
end
9 activerecord/test/cases/dup_test.rb
View
@@ -113,5 +113,14 @@ def test_dup_validity_is_independent
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
Please sign in to comment.
Something went wrong with that request. Please try again.