@@ -89,8 +89,21 @@ class Employee < TestResource
8989 has_one :chief , klass : 'Employee'
9090end
9191
92- class AssociationTest < MiniTest ::Test
92+ module CrossNamespaceTwo
93+ class Nail < TestResource
94+ property :size
95+ end
96+ end
97+
98+ module CrossNamespaceOne
99+ class Hammer < TestResource
100+ property :brand
101+
102+ has_many :nails , class : CrossNamespaceTwo ::Nail
103+ end
104+ end
93105
106+ class AssociationTest < Minitest ::Test
94107 def test_default_properties_no_changes
95108 stub_request ( :post , 'http://example.com/accounts' ) .
96109 with ( headers : { content_type : 'application/vnd.api+json' , accept : 'application/vnd.api+json' } , body : {
@@ -1070,4 +1083,62 @@ def test_does_not_load_include_from_dataset
10701083 assert_nil ( records . first . chief )
10711084 end
10721085
1086+ def test_cross_namespace_resource_references
1087+ stub_request ( :get , 'http://example.com/hammers?include=nails' )
1088+ . to_return (
1089+ headers : {
1090+ content_type : 'application/vnd.api+json'
1091+ } , body : {
1092+ data : [
1093+ {
1094+ id : '1' ,
1095+ type : 'hammers' ,
1096+ attributes : {
1097+ brand : 'Hardware Store'
1098+ } ,
1099+ relationships : {
1100+ nails : { data : [ { id : '2' , type : 'nails' } ] }
1101+ }
1102+ } ,
1103+ {
1104+ id : '2' ,
1105+ type : 'hammers' ,
1106+ attributes : {
1107+ brand : 'Hardware Store'
1108+ } ,
1109+ relationships : {
1110+ nails : { data : [ { id : '3' , type : 'nails' } ] }
1111+ }
1112+ }
1113+ ] ,
1114+ included : [
1115+ {
1116+ id : '2' ,
1117+ type : 'nails' ,
1118+ attributes : {
1119+ size : 10
1120+ }
1121+ } ,
1122+ {
1123+ id : '3' ,
1124+ type : 'nails' ,
1125+ attributes : {
1126+ size : 8
1127+ }
1128+ }
1129+ ]
1130+ } . to_json )
1131+
1132+ records = CrossNamespaceOne ::Hammer . includes ( :nails ) . to_a
1133+
1134+ assert_equal ( 2 , records . size )
1135+ assert_equal ( '1' , records . first . id )
1136+ assert_equal ( '2' , records . second . id )
1137+ assert_equal ( '2' , records . first . nails . first . id )
1138+ assert_equal ( '3' , records . second . nails . first . id )
1139+
1140+ assert_equal ( 1 , records . first . nails . size )
1141+ assert_equal ( 1 , records . second . nails . size )
1142+ end
1143+
10731144end
0 commit comments