mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
- elmenth_path raise an ActiveResource::MissingPrefixParam exception when prefix_options does not has all required prefix_options ex: class StreetAddress < ActiveResource::Base self.site = "http://37s.sunrise.i:3000/people/:person_id/" end
StreetAddress.element_path(1) # => ActiveResource::MissingPrefixParam
This commit is contained in:
parent
e3d6434dd9
commit
a71e07d61e
4 changed files with 18 additions and 1 deletions
|
@ -621,6 +621,12 @@ module ActiveResource
|
|||
# # => /posts/5/comments/1.xml?active=1
|
||||
#
|
||||
def element_path(id, prefix_options = {}, query_options = nil)
|
||||
|
||||
p_options = HashWithIndifferentAccess.new(prefix_options)
|
||||
prefix_parameters.each do |p|
|
||||
raise MissingPrefixParam if p_options[p].blank?
|
||||
end
|
||||
|
||||
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
||||
"#{prefix(prefix_options)}#{collection_name}/#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
|
||||
end
|
||||
|
|
|
@ -36,6 +36,9 @@ module ActiveResource
|
|||
def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
|
||||
end
|
||||
|
||||
# Raised when ...
|
||||
class MissingPrefixParam < ArgumentError; end # :nodoc:
|
||||
|
||||
# 4xx Client Error
|
||||
class ClientError < ConnectionError; end # :nodoc:
|
||||
|
||||
|
|
|
@ -475,6 +475,12 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal '/people/ann%20mary/addresses/ann%20mary.xml', StreetAddress.element_path(:'ann mary', 'person_id' => 'ann mary')
|
||||
end
|
||||
|
||||
def test_custom_element_path_without_parent_id
|
||||
assert_raise ActiveResource::MissingPrefixParam do
|
||||
assert_equal '/people/1/addresses/1.xml', StreetAddress.element_path(1)
|
||||
end
|
||||
end
|
||||
|
||||
def test_module_element_path
|
||||
assert_equal '/sounds/1.xml', Asset::Sound.element_path(1)
|
||||
end
|
||||
|
@ -560,6 +566,8 @@ class BaseTest < Test::Unit::TestCase
|
|||
assert_equal Set.new([:the_param1]), person_class.prefix_parameters
|
||||
person_class.prefix = "the_prefix/:the_param2"
|
||||
assert_equal Set.new([:the_param2]), person_class.prefix_parameters
|
||||
person_class.prefix = "the_prefix/:the_param1/other_prefix/:the_param2"
|
||||
assert_equal Set.new([:the_param2, :the_param1]), person_class.prefix_parameters
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class FinderTest < Test::Unit::TestCase
|
|||
|
||||
def test_find_by_id_not_found
|
||||
assert_raise(ActiveResource::ResourceNotFound) { Person.find(99) }
|
||||
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1) }
|
||||
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(99, :params => {:person_id => 1}) }
|
||||
end
|
||||
|
||||
def test_find_all_sub_objects
|
||||
|
|
Loading…
Reference in a new issue