Commits

yaotti committed ec9aa3c

Do not override attributes on `dup` by default scopes

Comments (0)

Files changed (3)

activerecord/CHANGELOG.md

 
     *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

activerecord/lib/active_record/core.rb

       @new_record  = true
 
       ensure_proper_type
-      populate_with_current_scope_attributes
       super
     end
 

activerecord/test/cases/dup_test.rb

         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