mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not override attributes on dup
by default scopes
This commit is contained in:
parent
2eb89627d8
commit
ec9aa3ca89
3 changed files with 13 additions and 1 deletions
|
@ -181,6 +181,10 @@
|
||||||
|
|
||||||
*Justin George*
|
*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`
|
* The database adpters now converts the options passed thought `DATABASE_URL`
|
||||||
environment variable to the proper Ruby types before using. For example, SQLite requires
|
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
|
that the timeout value is an integer, and PostgreSQL requires that the
|
||||||
|
|
|
@ -249,7 +249,6 @@ module ActiveRecord
|
||||||
@new_record = true
|
@new_record = true
|
||||||
|
|
||||||
ensure_proper_type
|
ensure_proper_type
|
||||||
populate_with_current_scope_attributes
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -123,5 +123,14 @@ module ActiveRecord
|
||||||
assert duped.valid?
|
assert duped.valid?
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue