Skip to content

Commit 9077ec9

Browse files
authored
Merge pull request #399 from igor-ladkin/encode-alpha-numeric-identifers-for-custom-methods
Encode ID parameter for custom methods
2 parents 1517cad + e0fa690 commit 9077ec9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/active_resource/custom_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def delete(method_name, options = {})
119119

120120
private
121121
def custom_method_element_url(method_name, options = {})
122-
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
122+
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{URI.encode_www_form_component(id.to_s)}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
123123
end
124124

125125
def custom_method_new_element_url(method_name, options = {})

test/cases/base/custom_methods_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,15 @@ def test_paths_without_format
141141
ensure
142142
ActiveResource::Base.include_format_in_path = true
143143
end
144+
145+
def test_custom_element_method_identifier_encoding
146+
luis = { person: { id: "luís", name: "Luís" } }.to_json
147+
148+
ActiveResource::HttpMock.respond_to do |mock|
149+
mock.get "/people/lu%C3%ADs.json", {}, luis
150+
mock.put "/people/lu%C3%ADs/deactivate.json", {}, luis, 204
151+
end
152+
153+
assert_equal ActiveResource::Response.new(luis, 204), Person.find("luís").put(:deactivate)
154+
end
144155
end

0 commit comments

Comments
 (0)