Changeset 8502
- Timestamp:
- 12/28/07 17:03:58 (2 years ago)
- Files:
-
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activeresource/lib/active_resource.rb (modified) (1 diff)
- trunk/activeresource/lib/active_resource/custom_methods.rb (modified) (2 diffs)
- trunk/activeresource/test/format_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activeresource/CHANGELOG
r8472 r8502 1 1 *SVN* 2 3 * Support agnostic formats when calling custom methods. Closes #10635 [joerichsen] 2 4 3 5 * Document custom methods. #10589 [Cheah Chu Yeow] trunk/activeresource/lib/active_resource.rb
r7518 r8502 28 28 begin 29 29 $:.unshift(File.dirname(__FILE__) + "/../../activesupport/lib") 30 require 'active_support' 30 require 'active_support' 31 31 rescue LoadError 32 32 require 'rubygems' trunk/activeresource/lib/active_resource/custom_methods.rb
r8472 r8502 81 81 def custom_method_collection_url(method_name, options = {}) 82 82 prefix_options, query_options = split_options(options) 83 "#{prefix(prefix_options)}#{collection_name}/#{method_name}. xml#{query_string(query_options)}"83 "#{prefix(prefix_options)}#{collection_name}/#{method_name}.#{format.extension}#{query_string(query_options)}" 84 84 end 85 85 end … … 109 109 private 110 110 def custom_method_element_url(method_name, options = {}) 111 "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}. xml#{self.class.send!(:query_string, options)}"111 "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}" 112 112 end 113 113 114 114 def custom_method_new_element_url(method_name, options = {}) 115 "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}. xml#{self.class.send!(:query_string, options)}"115 "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}" 116 116 end 117 117 end trunk/activeresource/test/format_test.rb
r7518 r8502 30 30 end 31 31 32 def test_formats_on_custom_collection_method 33 for format in [ :json, :xml ] 34 using_format(Person, format) do 35 ActiveResource::HttpMock.respond_to.get "/people/retrieve.#{format}?name=David", {}, ActiveResource::Formats[format].encode([@david]) 36 remote_programmers = Person.get(:retrieve, :name => 'David') 37 assert_equal 1, remote_programmers.size 38 assert_equal @david[:id], remote_programmers[0]['id'] 39 assert_equal @david[:name], remote_programmers[0]['name'] 40 end 41 end 42 end 43 44 def test_formats_on_custom_element_method 45 for format in [ :json, :xml ] 46 using_format(Person, format) do 47 ActiveResource::HttpMock.respond_to do |mock| 48 mock.get "/people/2.#{format}", {}, ActiveResource::Formats[format].encode(@david) 49 mock.get "/people/2/shallow.#{format}", {}, ActiveResource::Formats[format].encode(@david) 50 end 51 remote_programmer = Person.find(2).get(:shallow) 52 assert_equal @david[:id], remote_programmer['id'] 53 assert_equal @david[:name], remote_programmer['name'] 54 end 55 end 56 57 for format in [ :json, :xml ] 58 ryan = ActiveResource::Formats[format].encode({ :name => 'Ryan' }) 59 using_format(Person, format) do 60 ActiveResource::HttpMock.respond_to.post "/people/new/register.#{format}", {}, ryan, 201, 'Location' => "/people/5.#{format}" 61 remote_ryan = Person.new(:name => 'Ryan') 62 assert_equal ActiveResource::Response.new(ryan, 201, {'Location' => "/people/5.#{format}"}), remote_ryan.post(:register) 63 end 64 end 65 end 32 66 33 67 private