Browse files

Adding to_key to ActiveResource objects using ActiveModel::Conversion [

…#4685 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 24ac08f commit 15b0947579a85103f06cb8868ce5da58b8f3430d Elomar França committed with mikel May 24, 2010
Showing with 8 additions and 5 deletions.
  1. +1 −5 activeresource/lib/active_resource/base.rb
  2. +7 −0 activeresource/test/cases/base_test.rb
View
6 activeresource/lib/active_resource/base.rb
@@ -1044,11 +1044,6 @@ def id=(id)
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 @@ def method_missing(method_symbol, *arguments) #:nodoc:
class Base
extend ActiveModel::Naming
include CustomMethods, Observing, Validations
+ include ActiveModel::Conversion
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
end
View
7 activeresource/test/cases/base_test.rb
@@ -1081,6 +1081,13 @@ def test_to_param_quacks_like_active_record
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

0 comments on commit 15b0947

Please sign in to comment.