1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

ActiveResource shouldn't consider modules in the path

[#4529 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Santiago Pastorino 2010-05-14 09:34:33 -03:00 committed by José Valim
parent d18a2742e0
commit 7ffe76046a
3 changed files with 12 additions and 16 deletions

View file

@ -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:

View file

@ -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

5
activeresource/test/fixtures/sound.rb vendored Normal file
View file

@ -0,0 +1,5 @@
module Asset
class Sound < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
end
end