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 committed Feb 25, 2013
1 parent 2eb8962 commit ec9aa3c
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
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/core.rb
Expand Up @@ -249,7 +249,6 @@ def initialize_dup(other) # :nodoc:
@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 @@ -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.