aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb19
-rw-r--r--activeresource/test/cases/base_test.rb13
2 files changed, 18 insertions, 14 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index b976844c1c..b89097ac4b 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -582,12 +582,13 @@ module ActiveResource
# Clear prefix parameters in case they have been cached
@prefix_parameters = nil
- # Redefine the new methods.
- code, line = <<-end_code, __LINE__ + 1
- def prefix_source() "#{value}" end
- def prefix(options={}) "#{prefix_call}" end
- end_code
- silence_warnings { instance_eval code, __FILE__, line }
+ silence_warnings do
+ # Redefine the new methods.
+ instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
+ def prefix_source() "#{value}" end
+ def prefix(options={}) "#{prefix_call}" end
+ RUBY_EVAL
+ end
rescue
logger.error "Couldn't set prefix: #{$!}\n #{code}" if logger
raise
@@ -1043,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+.
#
@@ -1410,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 d5ee7659af..35c3f4c6ef 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -1017,7 +1017,7 @@ class BaseTest < Test::Unit::TestCase
encode = matz.encode
xml = matz.to_xml
- assert encode, xml
+ assert_equal encode, xml
assert xml.include?('<?xml version="1.0" encoding="UTF-8"?>')
assert xml.include?('<name>Matz</name>')
assert xml.include?('<id type="integer">1</id>')
@@ -1030,7 +1030,7 @@ class BaseTest < Test::Unit::TestCase
encode = matz.encode
xml = matz.to_xml
- assert encode, xml
+ assert_equal encode, xml
assert xml.include?('<?xml version="1.0" encoding="UTF-8"?>')
assert xml.include?('<ruby-creator>')
assert xml.include?('<name>Matz</name>')
@@ -1065,7 +1065,7 @@ class BaseTest < Test::Unit::TestCase
json = joe.to_json
Person.format = :xml
- assert encode, json
+ assert_equal encode, json
assert_match %r{^\{"ruby_creator":\{"person":\{}, json
assert_match %r{"id":6}, json
assert_match %r{"name":"Joe"}, json
@@ -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