Skip to content

Commit

Permalink
Adding to_key to ActiveResource objects using ActiveModel::Conversion [
Browse files Browse the repository at this point in the history
…#4685 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Elomar França authored and josevalim committed May 26, 2010
1 parent 163152b commit 7bd30b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions activeresource/lib/active_resource/base.rb
Expand Up @@ -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+.
#
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions activeresource/test/cases/base_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 7bd30b9

Please sign in to comment.