public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/JackDanger/rails.git
Fixes parsing deep nested resources from XML.  [#380 state:resolved]
Luis Hurtado (author)
Mon Jun 09 19:39:39 -0700 2008
jeremy (committer)
Mon Jun 09 23:06:07 -0700 2008
commit  225065709c43dacd57e0904aef2075024ccf2744
tree    97bb64adfd245513c9c5fcd8aa9f929cc19013fc
parent  16a9787bf034a4de36a35b647c456ef142f814e1
...
988
989
990
991
 
 
 
 
 
992
993
994
...
988
989
990
 
991
992
993
994
995
996
997
998
0
@@ -988,7 +988,11 @@ module ActiveResource
0
           self.class.const_get(resource_name)
0
         end
0
       rescue NameError
0
- resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base))
0
+ if self.class.const_defined?(resource_name)
0
+ resource = self.class.const_get(resource_name)
0
+ else
0
+ resource = self.class.const_set(resource_name, Class.new(ActiveResource::Base))
0
+ end
0
         resource.prefix = self.class.prefix
0
         resource.site = self.class.site
0
         resource
...
1
2
 
3
4
5
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
46
47
48
 
 
49
50
51
...
788
789
790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791
...
1
2
3
4
5
6
...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
78
79
80
81
82
83
84
85
...
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
0
@@ -1,5 +1,6 @@
0
 require 'abstract_unit'
0
 require "fixtures/person"
0
+require "fixtures/customer"
0
 require "fixtures/street_address"
0
 require "fixtures/beast"
0
 
0
@@ -15,6 +16,37 @@ class BaseTest < Test::Unit::TestCase
0
     @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people')
0
     @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses')
0
 
0
+ # - deep nested resource -
0
+ # - Luis (Customer)
0
+ # - JK (Customer::Friend)
0
+ # - Mateo (Customer::Friend::Brother)
0
+ # - Edith (Customer::Friend::Brother::Child)
0
+ # - Martha (Customer::Friend::Brother::Child)
0
+ # - Felipe (Customer::Friend::Brother)
0
+ # - Bryan (Customer::Friend::Brother::Child)
0
+ # - Luke (Customer::Friend::Brother::Child)
0
+ # - Eduardo (Customer::Friend)
0
+ # - Sebas (Customer::Friend::Brother)
0
+ # - Andres (Customer::Friend::Brother::Child)
0
+ # - Jorge (Customer::Friend::Brother::Child)
0
+ # - Elsa (Customer::Friend::Brother)
0
+ # - Natacha (Customer::Friend::Brother::Child)
0
+ # - Milena (Customer::Friend::Brother)
0
+ #
0
+ @luis = {:id => 1, :name => 'Luis',
0
+ :friends => [{:name => 'JK',
0
+ :brothers => [{:name => 'Mateo',
0
+ :children => [{:name => 'Edith'},{:name => 'Martha'}]},
0
+ {:name => 'Felipe',
0
+ :children => [{:name => 'Bryan'},{:name => 'Luke'}]}]},
0
+ {:name => 'Eduardo',
0
+ :brothers => [{:name => 'Sebas',
0
+ :children => [{:name => 'Andres'},{:name => 'Jorge'}]},
0
+ {:name => 'Elsa',
0
+ :children => [{:name => 'Natacha'}]},
0
+ {:name => 'Milena',
0
+ :children => []}]}]}.to_xml(:root => 'customer')
0
+
0
     ActiveResource::HttpMock.respond_to do |mock|
0
       mock.get "/people/1.xml", {}, @matz
0
       mock.get "/people/2.xml", {}, @david
0
@@ -46,6 +78,8 @@ class BaseTest < Test::Unit::TestCase
0
       mock.head "/people/1/addresses/2.xml", {}, nil, 404
0
       mock.head "/people/2/addresses/1.xml", {}, nil, 404
0
       mock.head "/people/Greg/addresses/1.xml", {}, nil, 200
0
+ # customer
0
+ mock.get "/customers/1.xml", {}, @luis
0
     end
0
 
0
     Person.user = nil
0
@@ -788,4 +822,18 @@ class BaseTest < Test::Unit::TestCase
0
     matz = Person.find(1)
0
     assert_equal '1', matz.to_param
0
   end
0
+
0
+ def test_parse_deep_nested_resources
0
+ luis = Customer.find(1)
0
+ assert_kind_of Customer, luis
0
+ luis.friends.each do |friend|
0
+ assert_kind_of Customer::Friend, friend
0
+ friend.brothers.each do |brother|
0
+ assert_kind_of Customer::Friend::Brother, brother
0
+ brother.children.each do |child|
0
+ assert_kind_of Customer::Friend::Brother::Child, child
0
+ end
0
+ end
0
+ end
0
+ end
0
 end

Comments

    No one has commented yet.