diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 13:40:26 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-19 13:40:26 +0530 |
commit | c71120e29caddda295c133adfb279870733a3f81 (patch) | |
tree | da81981de36bc146c36cae3bc73cb5020ba05919 /activeresource | |
parent | 087b67805e3785159cb4da524ad37782bd182b93 (diff) | |
parent | 71d67fc6bd504956bce66e274e6228dd00a814c1 (diff) | |
download | rails-c71120e29caddda295c133adfb279870733a3f81.tar.gz rails-c71120e29caddda295c133adfb279870733a3f81.tar.bz2 rails-c71120e29caddda295c133adfb279870733a3f81.zip |
Merge remote branch 'mainstream/master'
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 |