aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/base.rb1
-rw-r--r--activerecord/test/cases/dup_test.rb9
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index bac7b358dc..338afb3991 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -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.
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 5a7743b808..5bd1721439 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -553,7 +553,6 @@ module ActiveRecord #:nodoc:
@new_record = true
ensure_proper_type
- populate_with_current_scope_attributes
super
end
diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb
index b2a3cb5733..17a02f139a 100644
--- a/activerecord/test/cases/dup_test.rb
+++ b/activerecord/test/cases/dup_test.rb
@@ -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