aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-02-25 07:56:07 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-02-25 07:56:07 -0800
commitd8dd965764ac6647a8f9befa279c468f67703a3a (patch)
tree70f2bbdd782970e85571cde3c84609ba04f879df
parent2eb89627d844dec2a4ba420ca903bb139b860e43 (diff)
parentec9aa3ca892fbda77c2fe628acf4db46ba095090 (diff)
downloadrails-d8dd965764ac6647a8f9befa279c468f67703a3a.tar.gz
rails-d8dd965764ac6647a8f9befa279c468f67703a3a.tar.bz2
rails-d8dd965764ac6647a8f9befa279c468f67703a3a.zip
Merge pull request #9197 from yaotti/fix/overriden-attr-on-dup
Fix: Overriding attributes on `dup` by default scopes
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/core.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 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