aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-10-02 03:21:32 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-10-02 03:21:32 +0000
commitef4fb3dee2e897b245ee6f545232378db3de7b38 (patch)
tree42e47264ddce4b70da1308d7bfc92e7fe5b1d84a /activerecord
parent0092d0ac6de041995d6f4555c6e52590799cbefb (diff)
downloadrails-ef4fb3dee2e897b245ee6f545232378db3de7b38.tar.gz
rails-ef4fb3dee2e897b245ee6f545232378db3de7b38.tar.bz2
rails-ef4fb3dee2e897b245ee6f545232378db3de7b38.zip
save! shouldn't validate twice. Closes #6324.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5215 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb4
-rwxr-xr-xactiverecord/test/validations_test.rb6
3 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 7272741329..7107d825a3 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -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]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 43f631ef6c..af2645eeb7 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1527,14 +1527,13 @@ module ActiveRecord #:nodoc:
# * 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 @@ module ActiveRecord #:nodoc:
private
def create_or_update
+ raise ReadOnlyRecord if readonly?
if new_record? then create else update end
true
end
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index 936c36e6cb..d0d644a567 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -141,6 +141,12 @@ class ValidationsTest < Test::Unit::TestCase
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