diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-17 14:22:27 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-17 14:22:34 +0100 |
commit | c0d31ca41b2f019d3bf940ac79f104c412b115bf (patch) | |
tree | 4946099ab3a6cdffbb82a3fd78e77a7f4dccef58 /activeresource | |
parent | 020e656447a7cc2ce9cbf83483ab3b31730a565e (diff) | |
download | rails-c0d31ca41b2f019d3bf940ac79f104c412b115bf.tar.gz rails-c0d31ca41b2f019d3bf940ac79f104c412b115bf.tar.bz2 rails-c0d31ca41b2f019d3bf940ac79f104c412b115bf.zip |
save(false) is gone, use save(:validate => false) instead.
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/validations.rb | 15 | ||||
-rw-r--r-- | activeresource/test/cases/validations_test.rb | 13 |
2 files changed, 25 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 67b69fa505..7b2382bd8c 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -58,9 +58,8 @@ module ActiveResource # person.save # => true (and person is now saved to the remote service) # module Validations - extend ActiveSupport::Concern + extend ActiveSupport::Concern include ActiveModel::Validations - extend ActiveModel::Validations::ClassMethods included do alias_method_chain :save, :validation @@ -68,7 +67,17 @@ module ActiveResource # Validate a resource and save (POST) it to the remote web service. # If any local validations fail - the save (POST) will not be attempted. - def save_with_validation(perform_validation = true) + def save_with_validation(options=nil) + perform_validation = case options + when Hash + options[:validate] != false + when NilClass + true + else + ActiveSupport::Deprecation.warn "save(#{options}) is deprecated, please give save(:validate => #{options}) instead", caller + options + end + # clear the remote validations so they don't interfere with the local # ones. Otherwise we get an endless loop and can never change the # fields so as to make the resource valid diff --git a/activeresource/test/cases/validations_test.rb b/activeresource/test/cases/validations_test.rb index c05f625fb7..82546424f2 100644 --- a/activeresource/test/cases/validations_test.rb +++ b/activeresource/test/cases/validations_test.rb @@ -30,6 +30,19 @@ class ValidationsTest < ActiveModel::TestCase assert_raise(ActiveResource::ResourceInvalid) { p.save! } end + def test_save_without_validation + p = new_project(:name => nil) + assert !p.save + assert p.save(:validate => false) + end + + def test_deprecated_save_without_validation + p = new_project(:name => nil) + assert !p.save + assert_deprecated do + assert p.save(false) + end + end def test_validate_callback # we have a callback ensuring the description is longer than three letters |