From ec9aa3ca892fbda77c2fe628acf4db46ba095090 Mon Sep 17 00:00:00 2001 From: Hiroshige Umino Date: Tue, 26 Feb 2013 00:30:49 +0900 Subject: [PATCH] Do not override attributes on `dup` by default scopes --- activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/core.rb | 1 - activerecord/test/cases/dup_test.rb | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e244b7ff8b..6f7d968125 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -181,6 +181,10 @@ *Justin George* +* Fix overriding of attributes by default_scope on `ActiveRecord::Base#dup`. + + *Hiroshige UMINO* + * The database adpters now converts the options passed thought `DATABASE_URL` environment variable to the proper Ruby types before using. For example, SQLite requires that the timeout value is an integer, and PostgreSQL requires that the diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 6510433056..899fe7d7c7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -249,7 +249,6 @@ module ActiveRecord @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 eca500f7e4..fe105b9d22 100644 --- a/activerecord/test/cases/dup_test.rb +++ b/activerecord/test/cases/dup_test.rb @@ -123,5 +123,14 @@ module ActiveRecord assert duped.valid? end 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