Changeset 6587
- Timestamp:
- 04/26/07 19:38:16 (1 year ago)
- Files:
-
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activeresource/lib/active_resource/base.rb (modified) (3 diffs)
- trunk/activeresource/test/base/load_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activeresource/CHANGELOG
r6586 r6587 1 1 *SVN* 2 3 * Added support for using classes from within a single nested module [DHH]. Example: 4 5 module Highrise 6 class Note < ActiveResource::Base 7 self.site = "http://37s.sunrise.i:3000" 8 end 9 10 class Comment < ActiveResource::Base 11 self.site = "http://37s.sunrise.i:3000" 12 end 13 end 14 15 assert_kind_of Highrise::Comment, Note.find(1).comments.first 16 2 17 3 18 * Added load_attributes_from_response as a way of loading attributes from other responses than just create [DHH] trunk/activeresource/lib/active_resource/base.rb
r6586 r6587 113 113 end 114 114 115 # Core method for finding resources. Used similarly to ActiveRecord's find method. 116 # Person.find(1) # => GET /people/1.xml 115 # Core method for finding resources. Used similarly to Active Record's find method. 116 # Person.find(1) # => GET /people/1.xml 117 # Person.find(:all) # => GET /people.xml 118 # Person.find(:all, :title => "CEO") # => GET /people.xml?title=CEO 119 # Person.find(:managers) # => GET /people/managers.xml 117 120 # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml 118 121 def find(*arguments) … … 291 294 # Update the resource on the remote service. 292 295 def update 293 connection.put(element_path(prefix_options), to_xml) 296 returning connection.put(element_path(prefix_options), to_xml) do |response| 297 load_attributes_from_response(response) 298 end 294 299 end 295 300 … … 330 335 def find_or_create_resource_for(name) 331 336 resource_name = name.to_s.camelize 332 self.class.const_get(resource_name) 337 338 # FIXME: Make it generic enough to support any depth of module nesting 339 if (ancestors = self.class.name.split("::")).size > 1 340 ancestors.first.constantize.const_get(resource_name) 341 else 342 self.class.const_get(resource_name) 343 end 333 344 rescue NameError 334 345 resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base)) trunk/activeresource/test/base/load_test.rb
r5714 r6587 2 2 require "fixtures/person" 3 3 require "fixtures/street_address" 4 5 module Highrise 6 class Note < ActiveResource::Base 7 self.site = "http://37s.sunrise.i:3000" 8 end 9 10 class Comment < ActiveResource::Base 11 self.site = "http://37s.sunrise.i:3000" 12 end 13 end 14 4 15 5 16 class BaseLoadTest < Test::Unit::TestCase … … 93 104 assert_equal @matz[:id], rivers.last.rafted_by.id 94 105 end 106 107 def test_nested_collections_within_the_same_namespace 108 n = Highrise::Note.new(:comments => [{ :name => "1" }]) 109 assert_kind_of Highrise::Comment, n.comments.first 110 end 95 111 end