Skip to content

Commit

Permalink
Do not override attributes on dup by default scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
yaotti authored and steveklabnik committed Feb 26, 2013
1 parent c90e24d commit 55a1765
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## unreleased ##

* Fix overriding of attributes by default_scope on `ActiveRecord::Base#dup`.

*Hiroshige UMINO*

* Fix issue with overriding Active Record reader methods with a composed object
and using that attribute as the scope of a `uniqueness_of` validation.
Backport #7072.
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -553,7 +553,6 @@ def initialize_dup(other)
@new_record = true

ensure_proper_type
populate_with_current_scope_attributes
super
end

Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/dup_test.rb
Expand Up @@ -113,5 +113,14 @@ def test_dup_validity_is_independent
assert topic.invalid?
assert duped.valid?
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 55a1765

Please sign in to comment.