Changeset 6595
- Timestamp:
- 04/27/07 20:54:53 (1 year ago)
- Files:
-
- trunk/activeresource/CHANGELOG (modified) (1 diff)
- trunk/activeresource/lib/active_resource/base.rb (modified) (3 diffs)
- trunk/activeresource/test/base_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activeresource/CHANGELOG
r6587 r6595 1 1 *SVN* 2 3 * Added find-by-path options to ActiveResource::Base.find [DHH]. Examples: 4 5 employees = Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml 6 manager = Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml 7 2 8 3 9 * Added support for using classes from within a single nested module [DHH]. Example: trunk/activeresource/lib/active_resource/base.rb
r6587 r6595 114 114 115 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 120 # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml 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 120 # Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml 121 # Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml 122 # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml 121 123 def find(*arguments) 122 124 scope = arguments.slice!(0) … … 145 147 # Find every resource. 146 148 def find_every(options) 149 from = options.delete(:from) 147 150 prefix_options, query_options = split_options(options) 148 instantiate_collection(connection.get(collection_path(prefix_options, query_options)) || []) 151 from ||= collection_path(prefix_options, query_options) 152 153 instantiate_collection(connection.get(from) || []) 149 154 end 150 155 … … 161 166 def find_single(scope, options) 162 167 prefix_options, query_options = split_options(options) 163 returning new(connection.get(element_path(scope, prefix_options, query_options))) do |resource| 168 from = scope.to_s.include?("/") ? scope : element_path(scope, prefix_options, query_options) 169 170 returning new(connection.get(from)) do |resource| 164 171 resource.prefix_options = prefix_options 165 172 end trunk/activeresource/test/base_test.rb
r6584 r6595 204 204 end 205 205 206 def test_find_all_by_from 207 ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/people.xml", {}, "<people>#{@david}</people>" } 208 209 people = Person.find(:all, :from => "/companies/1/people.xml") 210 assert_equal 1, people.size 211 assert_equal "David", people.first.name 212 end 213 214 def test_find_single_by_from 215 ActiveResource::HttpMock.respond_to { |m| m.get "/companies/1/manager.xml", {}, @david } 216 217 david = Person.find("/companies/1/manager.xml") 218 assert_equal "David", david.name 219 end 220 206 221 def test_save 207 222 rick = Person.new