From 268a838b423f4cd332aaf9d45d4bc52ec626c968 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 14 May 2010 09:34:33 -0300 Subject: [PATCH] ActiveResource shouldn't consider modules in the path [#4529 state:committed] --- activeresource/lib/active_resource/base.rb | 18 ++---------------- activeresource/test/cases/base_test.rb | 5 +++++ activeresource/test/fixtures/sound.rb | 5 +++++ 3 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 activeresource/test/fixtures/sound.rb diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index ffdb5fb..b976844 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -551,22 +551,8 @@ module ActiveResource @headers ||= {} end - def element_name - @element_name ||= model_name.element - end - - def element_name=(element_name) - @element_name = element_name - @collection_name ||= model_name.collection.sub(/[^\/]*$/, @element_name.pluralize) - end - - def collection_name - @collection_name ||= model_name.collection - end - - def collection_name=(collection_name) - @collection_name = collection_name - end + attr_accessor_with_default(:element_name) { model_name.element } #:nodoc: + attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc: attr_accessor_with_default(:primary_key, 'id') #:nodoc: diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 5df1f41..4e21e84 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require "fixtures/person" require "fixtures/customer" require "fixtures/street_address" +require "fixtures/sound" require "fixtures/beast" require "fixtures/proxy" require 'active_support/json' @@ -563,6 +564,10 @@ class BaseTest < Test::Unit::TestCase assert_equal '/people/Greg/addresses/1.xml', StreetAddress.element_path(1, 'person_id' => 'Greg') end + def test_module_element_path + assert_equal '/sounds/1.xml', Asset::Sound.element_path(1) + end + def test_custom_element_path_with_redefined_to_param Person.module_eval do alias_method :original_to_param_element_path, :to_param diff --git a/activeresource/test/fixtures/sound.rb b/activeresource/test/fixtures/sound.rb new file mode 100644 index 0000000..5c0ef5d --- /dev/null +++ b/activeresource/test/fixtures/sound.rb @@ -0,0 +1,5 @@ +module Asset + class Sound < ActiveResource::Base + self.site = "http://37s.sunrise.i:3000" + end +end -- 1.7.1