aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-01-19 21:05:37 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-01-19 21:05:37 +1100
commit2107921000f4a186fed36e676d1ac089c8be1f99 (patch)
tree42f2188f058f8401d57f0d4c72063689a93e0419 /activeresource
parentccb7d9def3c20037c9ed5989d8cae1ed68763f4f (diff)
parented8501ef16fb2f5e4bd4d987740f5e5f62978400 (diff)
downloadrails-2107921000f4a186fed36e676d1ac089c8be1f99.tar.gz
rails-2107921000f4a186fed36e676d1ac089c8be1f99.tar.bz2
rails-2107921000f4a186fed36e676d1ac089c8be1f99.zip
Merge branch 'master' of git://github.com/rails/rails into rails
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb7
-rw-r--r--activeresource/lib/active_resource/validations.rb15
-rw-r--r--activeresource/test/cases/validations_test.rb13
3 files changed, 32 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index a6243e7011..b841108bd1 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -42,6 +42,13 @@ module ActiveResource
# self.element_name = "person"
# end
#
+ # If your Active Resource object is required to use an HTTP proxy you can set the +proxy+ value which holds a URI.
+ #
+ # class PersonResource < ActiveResource::Base
+ # self.site = "http://api.people.com:3000/"
+ # self.proxy = "http://user:password@proxy.people.com:8080"
+ # end
+ #
#
# == Lifecycle methods
#
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