aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorElomar França <elomar@maisweb.org>2010-05-24 23:55:14 -0300
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-03 23:32:09 +1000
commit15b0947579a85103f06cb8868ce5da58b8f3430d (patch)
tree4e585648f2dd66f62a1bc33006f9c8b4b245d1f4 /activeresource
parent24ac08fd68a683c1c3904c430c738584a4944549 (diff)
downloadrails-15b0947579a85103f06cb8868ce5da58b8f3430d.tar.gz
rails-15b0947579a85103f06cb8868ce5da58b8f3430d.tar.bz2
rails-15b0947579a85103f06cb8868ce5da58b8f3430d.zip
Adding to_key to ActiveResource objects using ActiveModel::Conversion [#4685 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb6
-rw-r--r--activeresource/test/cases/base_test.rb7
2 files changed, 8 insertions, 5 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 6397fbc280..b89097ac4b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -1044,11 +1044,6 @@ module ActiveResource
attributes[self.class.primary_key] = id
end
- # Allows Active Resource objects to be used as parameters in Action Pack URL generation.
- def to_param
- id && id.to_s
- end
-
# Test for equality. Resource are equal if and only if +other+ is the same object or
# is an instance of the same class, is not <tt>new?</tt>, and has the same +id+.
#
@@ -1411,6 +1406,7 @@ module ActiveResource
class Base
extend ActiveModel::Naming
include CustomMethods, Observing, Validations
+ include ActiveModel::Conversion
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
end
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index 15084802f8..35c3f4c6ef 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -1081,6 +1081,13 @@ class BaseTest < Test::Unit::TestCase
assert_equal '1', matz.to_param
end
+ def test_to_key_quacks_like_active_record
+ new_person = Person.new
+ assert_nil new_person.to_key
+ matz = Person.find(1)
+ assert_equal [1], matz.to_key
+ end
+
def test_parse_deep_nested_resources
luis = Customer.find(1)
assert_kind_of Customer, luis