mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActiveRecord::Base#new_record? now returns false for existing records (was nil) [#1219 state:committed]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
This commit is contained in:
parent
4f043a4838
commit
6e98adfc8e
3 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
*2.3.0/3.0*
|
||||
|
||||
* Fixed that ActiveRecord::Base#new_record? should return false (not nil) for existing records #1219 [Yaroslav Markin]
|
||||
|
||||
* I18n the word separator for error messages. Introduces the activerecord.errors.format.separator translation key. #1294 [Akira Matsuda]
|
||||
|
||||
* Add :having as a key to find and the relevant associations. [Emilio Tagua]
|
||||
|
|
|
@ -2406,9 +2406,9 @@ module ActiveRecord #:nodoc:
|
|||
write_attribute(self.class.primary_key, value)
|
||||
end
|
||||
|
||||
# Returns true if this object hasn't been saved yet -- that is, a record for the object doesn't exist yet.
|
||||
# Returns true if this object hasn't been saved yet -- that is, a record for the object doesn't exist yet; otherwise, returns false.
|
||||
def new_record?
|
||||
defined?(@new_record) && @new_record
|
||||
(defined?(@new_record) && @new_record) || false
|
||||
end
|
||||
|
||||
# :call-seq:
|
||||
|
|
|
@ -1198,6 +1198,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
assert b_true.value?
|
||||
end
|
||||
|
||||
def test_new_record_returns_boolean
|
||||
assert_equal Topic.new.new_record?, true
|
||||
assert_equal Topic.find(1).new_record?, false
|
||||
end
|
||||
|
||||
def test_clone
|
||||
topic = Topic.find(1)
|
||||
cloned_topic = nil
|
||||
|
|
Loading…
Reference in a new issue