save! shouldn't validate twice. Closes #6324.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5215 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0092d0ac6d
commit
ef4fb3dee2
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* save! shouldn't validate twice. #6324 [maiha, Bob Silva]
|
||||
|
||||
* Association collections have an _ids reader method to match the existing writer for collection_select convenience (e.g. employee.task_ids). The writer method skips blank ids so you can safely do @employee.task_ids = params[:tasks] without checking every time for an empty list or blank values. #1887, #5780 [Michael Schuerig]
|
||||
|
||||
* Add an attribute reader method for ActiveRecord::Base.observers [Rick Olson]
|
||||
|
@ -1527,14 +1527,13 @@ def new_record?
|
||||
# * No record exists: Creates a new record with values matching those of the object attributes.
|
||||
# * A record does exist: Updates the record with values matching those of the object attributes.
|
||||
def save
|
||||
raise ReadOnlyRecord if readonly?
|
||||
create_or_update
|
||||
end
|
||||
|
||||
# Attempts to save the record, but instead of just returning false if it couldn't happen, it raises a
|
||||
# RecordNotSaved exception
|
||||
def save!
|
||||
save || raise(RecordNotSaved)
|
||||
create_or_update || raise(RecordNotSaved)
|
||||
end
|
||||
|
||||
# Deletes the record in the database and freezes this instance to reflect that no changes should
|
||||
@ -1765,6 +1764,7 @@ def readonly! #:nodoc:
|
||||
|
||||
private
|
||||
def create_or_update
|
||||
raise ReadOnlyRecord if readonly?
|
||||
if new_record? then create else update end
|
||||
true
|
||||
end
|
||||
|
@ -141,6 +141,12 @@ def test_create_without_validation
|
||||
assert reply.save(false)
|
||||
end
|
||||
|
||||
def test_create_without_validation_bang
|
||||
count = Reply.count
|
||||
assert_nothing_raised { Reply.new.save_without_validation! }
|
||||
assert count+1, Reply.count
|
||||
end
|
||||
|
||||
def test_validates_each
|
||||
perform = true
|
||||
hits = 0
|
||||
|
Loading…
Reference in New Issue
Block a user