aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases/validations_test.rb
diff options
context:
space:
mode:
authortaryn <teast@globalpersonals.co.uk>2009-08-19 12:25:05 +0100
committerJoshua Peek <josh@joshpeek.com>2009-08-19 09:05:02 -0500
commit328ba3b333777bbc1269cbe0e9f590c845006c9d (patch)
treee3bfecf2acd9c5270ceb0bcf5f59c28f685e2f64 /activeresource/test/cases/validations_test.rb
parent4dc05bc8a9824b9404cebecaba28f9f248f9995e (diff)
downloadrails-328ba3b333777bbc1269cbe0e9f590c845006c9d.tar.gz
rails-328ba3b333777bbc1269cbe0e9f590c845006c9d.tar.bz2
rails-328ba3b333777bbc1269cbe0e9f590c845006c9d.zip
Added save! which raises ResourceInvalid unless valid?
Similar to Active Record - it will raise ActiveResouce::ResourceInvalid if the resource is not valid (ie if <tt>valid?</tt> returns false) However - does not raise ActiveResource::ResourceNotFound if the callbacks fail (callbacks have not yet been implemented) - it will just try to save and raise if the callbacks all fail. This is not ideal behaviour - but will do until we decide to change the behaviour of save_with_validations to actually raise (rather than catch) the ResourceInvalid exception. Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activeresource/test/cases/validations_test.rb')
-rw-r--r--activeresource/test/cases/validations_test.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activeresource/test/cases/validations_test.rb b/activeresource/test/cases/validations_test.rb
index f5a43b1ac1..a8ab7d64e7 100644
--- a/activeresource/test/cases/validations_test.rb
+++ b/activeresource/test/cases/validations_test.rb
@@ -23,9 +23,15 @@ class ValidationsTest < ActiveModel::TestCase
assert p.save, "should have saved after fixing the validation, but had: #{p.errors.inspect}"
end
+
+ def test_fails_save!
+ p = new_project(:name => nil)
+ assert_raise(ActiveResource::ResourceInvalid) { p.save! }
+ end
+
def test_validate_callback
- # we have a callback ensuring the description is longer thn three letters
+ # we have a callback ensuring the description is longer than three letters
p = new_project(:description => 'a')
assert !p.valid?, "should not be a valid record when it fails a validation callback"
assert !p.save, "should not have saved an invalid record"