@@ -1335,6 +1335,19 @@ def test_show_has_many_relationship_invalid_id
13351335 assert_response :bad_request
13361336 assert_match /2,1 is not a valid value for id/ , response . body
13371337 end
1338+
1339+ def test_show_has_one_relationship_nil
1340+ get :show_association , { post_id : '17' , association : 'author' }
1341+ assert_response :success
1342+ assert_hash_equals json_response ,
1343+ {
1344+ data : nil ,
1345+ links : {
1346+ self : 'http://test.host/posts/17/links/author' ,
1347+ related : 'http://test.host/posts/17/author'
1348+ }
1349+ }
1350+ end
13381351end
13391352
13401353class TagsControllerTest < ActionController ::TestCase
@@ -1678,6 +1691,50 @@ def test_valid_filter_value
16781691 assert_equal json_response [ 'data' ] [ 0 ] [ 'id' ] , '1'
16791692 assert_equal json_response [ 'data' ] [ 0 ] [ 'name' ] , 'Joe Author'
16801693 end
1694+
1695+ def test_get_related_resource
1696+ get :get_related_resource , { post_id : '2' , association : 'author' , :source => 'posts' }
1697+ assert_response :success
1698+ assert_hash_equals json_response ,
1699+ {
1700+ data : {
1701+ id : '1' ,
1702+ type : 'people' ,
1703+ name : 'Joe Author' ,
1704+ email : 'joe@xyz.fake' ,
1705+ dateJoined : '2013-08-07 16:25:00 -0400' ,
1706+ links : {
1707+ self : 'http://test.host/people/1' ,
1708+ comments : {
1709+ self : 'http://test.host/people/1/links/comments' ,
1710+ related : 'http://test.host/people/1/comments'
1711+ } ,
1712+ posts : {
1713+ self : 'http://test.host/people/1/links/posts' ,
1714+ related : 'http://test.host/people/1/posts'
1715+ } ,
1716+ preferences : {
1717+ self : 'http://test.host/people/1/links/preferences' ,
1718+ related : 'http://test.host/people/1/preferences' ,
1719+ linkage : {
1720+ type : 'preferences' ,
1721+ id : '1'
1722+ }
1723+ }
1724+ }
1725+ }
1726+ }
1727+ end
1728+
1729+ def test_get_related_resource_nil
1730+ get :get_related_resource , { post_id : '17' , association : 'author' , :source => 'posts' }
1731+ assert_response :success
1732+ assert_hash_equals json_response ,
1733+ {
1734+ data : nil
1735+ }
1736+
1737+ end
16811738end
16821739
16831740class Api ::V5 ::AuthorsControllerTest < ActionController ::TestCase
0 commit comments