@@ -61,6 +61,17 @@ def self.route_formatter
61
61
end
62
62
end
63
63
64
+ class DashedOwner < Formatted
65
+ end
66
+
67
+ class DashedProperty < Formatted
68
+ has_one :dashed_owner
69
+ end
70
+
71
+ class DashedRegion < Formatted
72
+ has_many :dashed_properties
73
+ end
74
+
64
75
class Account < TestResource
65
76
property :name
66
77
property :is_active , default : true
@@ -256,6 +267,26 @@ def test_has_one_loads_nil
256
267
assert_nil property . owner , "expected to be able to ask for explicitly declared association even if it's not present"
257
268
end
258
269
270
+ def test_load_has_one_with_dasherized_key_type
271
+ stub_request ( :get , "http://example.com/dashed-owners/1" )
272
+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
273
+ data : [
274
+ {
275
+ id : 1 ,
276
+ type : 'dashed-owners' ,
277
+ attributes : {
278
+ name : "Arjuna"
279
+ }
280
+ }
281
+ ] ,
282
+ } . to_json )
283
+ dashed_owner = DashedOwner . find ( 1 ) . first
284
+ dashed_property = DashedProperty . new ( dashed_owner : dashed_owner )
285
+
286
+ assert_equal ( DashedOwner , dashed_property . dashed_owner . class )
287
+ assert_equal ( 1 , dashed_property . dashed_owner . id )
288
+ end
289
+
259
290
def test_has_one_fetches_relationship
260
291
stub_request ( :get , "http://example.com/properties/1" )
261
292
. to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
@@ -554,6 +585,27 @@ def test_load_has_many_single_entry
554
585
assert_equal ( "123 Main St." , owner . properties . first . address )
555
586
end
556
587
588
+ def test_load_has_many_with_dasherized_key_type
589
+ stub_request ( :get , "http://example.com/dashed-properties" )
590
+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
591
+ data : [
592
+ {
593
+ id : 1 ,
594
+ type : 'dashed-properties' ,
595
+ attributes : {
596
+ address : "78 Street No. 9, Ludhiana"
597
+ }
598
+ }
599
+ ] ,
600
+ } . to_json )
601
+
602
+ dashed_properties = DashedProperty . all
603
+ dashed_region = DashedRegion . new ( dashed_properties : dashed_properties )
604
+
605
+ assert_equal ( 1 , dashed_region . dashed_properties . count )
606
+ assert_equal ( DashedProperty , dashed_region . dashed_properties [ 0 ] . class )
607
+ end
608
+
557
609
def test_respect_included_has_many_relationship_empty_data
558
610
stub_request ( :get , "http://example.com/owners/1?include=properties" )
559
611
. to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
0 commit comments