Permalink
Browse files

Merge pull request #9197 from yaotti/fix/overriden-attr-on-dup

Fix: Overriding attributes on `dup` by default scopes
  • Loading branch information...
2 parents 2eb8962 + ec9aa3c commit d8dd965764ac6647a8f9befa279c468f67703a3a @rafaelfranca rafaelfranca committed Feb 25, 2013
Showing with 13 additions and 1 deletion.
  1. +4 −0 activerecord/CHANGELOG.md
  2. +0 −1 activerecord/lib/active_record/core.rb
  3. +9 −0 activerecord/test/cases/dup_test.rb
View
4 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
View
1 activerecord/lib/active_record/core.rb
@@ -249,7 +249,6 @@ def initialize_dup(other) # :nodoc:
@new_record = true
ensure_proper_type
- populate_with_current_scope_attributes
super
end
View
9 activerecord/test/cases/dup_test.rb
@@ -123,5 +123,14 @@ def test_dup_validity_is_independent
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

0 comments on commit d8dd965

Please sign in to comment.