mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Adding to_key to ActiveResource objects using ActiveModel::Conversion [#4685 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
committed by
José Valim
parent
163152bfd0
commit
7bd30b9585
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user