Permalink
Browse files

Do not override attributes on `dup` by default scopes

  • Loading branch information...
1 parent 2eb8962 commit ec9aa3ca892fbda77c2fe628acf4db46ba095090 @yaotti yaotti 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
@@ -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
@@ -249,7 +249,6 @@ def initialize_dup(other) # :nodoc:
@new_record = true
ensure_proper_type
- populate_with_current_scope_attributes
super
end
@@ -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 ec9aa3c

Please sign in to comment.