aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorHiroshige Umino <hiroshige88@gmail.com>2013-02-26 11:32:04 +0900
committerSteve Klabnik <steve@steveklabnik.com>2013-02-26 11:08:50 -0800
commit55a1765942bc3d78ba5d449b5daf17a3c902e57c (patch)
tree561d698527541a063492720678322e72e93e4f10 /activerecord
parentc90e24d08782d583286ccb21cc15f60fa9ed8367 (diff)
downloadrails-55a1765942bc3d78ba5d449b5daf17a3c902e57c.tar.gz
rails-55a1765942bc3d78ba5d449b5daf17a3c902e57c.tar.bz2
rails-55a1765942bc3d78ba5d449b5daf17a3c902e57c.zip
Do not override attributes on `dup` by default scopes
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