aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-03-15 02:32:14 +0000
committerMichael Koziarski <michael@koziarski.com>2006-03-15 02:32:14 +0000
commitc42cd3c3834e13bd9eb0a444e0d6073aee548125 (patch)
tree290b94b2b865210a6ad9d1a2eb676838f031e70e /activerecord
parentc32fa73ea15d0d1b355b1f88f82757d79f82ba85 (diff)
downloadrails-c42cd3c3834e13bd9eb0a444e0d6073aee548125.tar.gz
rails-c42cd3c3834e13bd9eb0a444e0d6073aee548125.tar.bz2
rails-c42cd3c3834e13bd9eb0a444e0d6073aee548125.zip
make save! return true on success[johan@johansorensen.com]. Closes #4173
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3871 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rwxr-xr-xactiverecord/test/base_test.rb5
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 00b207bb38..3ddf180e0d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -4,6 +4,8 @@
* Allow ordering of calculated results and/or grouped fields in calculations [solo@gatelys.com]
+* Make ActiveRecord::Base#save! return true instead of nil on success. #4173 [johan@johansorensen.com]
+
* Dynamically set allow_concurrency. #4044 [Stefan Kaes]
* Added Base#to_xml that'll turn the current record into a XML representation [DHH]. Example:
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 9e3c54c7d4..8c1f615a37 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1305,7 +1305,7 @@ module ActiveRecord #:nodoc:
# Attempts to save the record, but instead of just returning false if it couldn't happen, it raises a
# RecordNotSaved exception
def save!
- raise RecordNotSaved unless save
+ save || raise(RecordNotSaved)
end
# Deletes the record in the database and freezes this instance to reflect that no changes should
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 226f163b52..d910215a0a 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -136,6 +136,11 @@ class BasicsTest < Test::Unit::TestCase
topic_reloaded = Topic.find(topic.id)
assert_equal("New Topic", topic_reloaded.title)
end
+
+ def test_save!
+ topic = Topic.new(:title => "New Topic")
+ assert topic.save!
+ end
def test_hashes_not_mangled
new_topic = { :title => "New Topic" }