jsonapi-resources 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -129,7 +129,7 @@ class PostsControllerTest < ActionController::TestCase
129
129
  assert json_response['data'][0]['relationships'].key?('author')
130
130
  end
131
131
 
132
- def test_filter_association_single
132
+ def test_filter_relationship_single
133
133
  count_queries do
134
134
  get :index, {filter: {tags: '5,1'}}
135
135
  end
@@ -141,7 +141,7 @@ class PostsControllerTest < ActionController::TestCase
141
141
  assert_match /JR How To/, response.body
142
142
  end
143
143
 
144
- def test_filter_associations_multiple
144
+ def test_filter_relationships_multiple
145
145
  count_queries do
146
146
  get :index, {filter: {tags: '5,1', comments: '3'}}
147
147
  end
@@ -151,7 +151,7 @@ class PostsControllerTest < ActionController::TestCase
151
151
  assert_match /JR Solves your serialization woes!/, response.body
152
152
  end
153
153
 
154
- def test_filter_associations_multiple_not_found
154
+ def test_filter_relationships_multiple_not_found
155
155
  get :index, {filter: {tags: '1', comments: '3'}}
156
156
  assert_response :success
157
157
  assert_equal 0, json_response['data'].size
@@ -199,7 +199,7 @@ class PostsControllerTest < ActionController::TestCase
199
199
  assert_match /posters is not a valid resource./, json_response['errors'][0]['detail']
200
200
  end
201
201
 
202
- def test_index_filter_on_association
202
+ def test_index_filter_on_relationship
203
203
  get :index, {filter: {author: '1'}}
204
204
  assert_response :success
205
205
  assert_equal 3, json_response['data'].size
@@ -275,7 +275,6 @@ class PostsControllerTest < ActionController::TestCase
275
275
  assert_response :success
276
276
  assert json_response['data'].is_a?(Hash)
277
277
  assert_nil json_response['data']['attributes']
278
- assert_equal '1', json_response['data']['relationships']['author']['data']['id']
279
278
  end
280
279
 
281
280
  def test_show_single_with_fields_string
@@ -326,7 +325,6 @@ class PostsControllerTest < ActionController::TestCase
326
325
 
327
326
  assert_response :created
328
327
  assert json_response['data'].is_a?(Hash)
329
- assert_equal '3', json_response['data']['relationships']['author']['data']['id']
330
328
  assert_equal 'JR is Great', json_response['data']['attributes']['title']
331
329
  assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body']
332
330
  end
@@ -391,11 +389,11 @@ class PostsControllerTest < ActionController::TestCase
391
389
 
392
390
  assert_response :unprocessable_entity
393
391
 
394
- assert_equal "/author", json_response['errors'][0]['path']
392
+ assert_equal "/data/relationships/author", json_response['errors'][0]['source']['pointer']
395
393
  assert_equal "can't be blank", json_response['errors'][0]['detail']
396
394
  assert_equal "author - can't be blank", json_response['errors'][0]['title']
397
395
 
398
- assert_equal "/title", json_response['errors'][1]['path']
396
+ assert_equal "/data/attributes/title", json_response['errors'][1]['source']['pointer']
399
397
  assert_equal "is too long (maximum is 35 characters)", json_response['errors'][1]['detail']
400
398
  assert_equal "title - is too long (maximum is 35 characters)", json_response['errors'][1]['title']
401
399
  end
@@ -431,7 +429,7 @@ class PostsControllerTest < ActionController::TestCase
431
429
  assert_response :created
432
430
  assert json_response['data'].is_a?(Array)
433
431
  assert_equal json_response['data'].size, 2
434
- assert_equal json_response['data'][0]['relationships']['author']['data']['id'], '3'
432
+ assert_nil json_response['data'][0]['relationships']['author']['data']
435
433
  assert_match /JR is Great/, response.body
436
434
  assert_match /Ember is Great/, response.body
437
435
  end
@@ -547,7 +545,7 @@ class PostsControllerTest < ActionController::TestCase
547
545
  assert_match /subject/, json_response['errors'][0]['detail']
548
546
  end
549
547
 
550
- def test_create_with_links_has_many_type_ids
548
+ def test_create_with_links_to_many_type_ids
551
549
  set_content_type_header!
552
550
  post :create,
553
551
  {
@@ -561,7 +559,8 @@ class PostsControllerTest < ActionController::TestCase
561
559
  author: {data: {type: 'people', id: '3'}},
562
560
  tags: {data: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
563
561
  }
564
- }
562
+ },
563
+ include: 'author'
565
564
  }
566
565
 
567
566
  assert_response :created
@@ -571,7 +570,7 @@ class PostsControllerTest < ActionController::TestCase
571
570
  assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['attributes']['body']
572
571
  end
573
572
 
574
- def test_create_with_links_has_many_array
573
+ def test_create_with_links_to_many_array
575
574
  set_content_type_header!
576
575
  post :create,
577
576
  {
@@ -585,7 +584,8 @@ class PostsControllerTest < ActionController::TestCase
585
584
  author: {data: {type: 'people', id: '3'}},
586
585
  tags: {data: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
587
586
  }
588
- }
587
+ },
588
+ include: 'author'
589
589
  }
590
590
 
591
591
  assert_response :created
@@ -639,7 +639,7 @@ class PostsControllerTest < ActionController::TestCase
639
639
  tags: {data: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
640
640
  }
641
641
  },
642
- include: 'tags'
642
+ include: 'tags,author,section'
643
643
  }
644
644
 
645
645
  assert_response :success
@@ -709,7 +709,7 @@ class PostsControllerTest < ActionController::TestCase
709
709
  tags: []
710
710
  }
711
711
  },
712
- include: 'tags'
712
+ include: 'tags,author,section'
713
713
  }
714
714
 
715
715
  assert_response :success
@@ -722,52 +722,52 @@ class PostsControllerTest < ActionController::TestCase
722
722
  json_response['data']['relationships']['tags']['data'])
723
723
  end
724
724
 
725
- def test_update_relationship_has_one
725
+ def test_update_relationship_to_one
726
726
  set_content_type_header!
727
727
  ruby = Section.find_by(name: 'ruby')
728
728
  post_object = Post.find(4)
729
729
  assert_not_equal ruby.id, post_object.section_id
730
730
 
731
- put :update_association, {post_id: 4, association: 'section', data: {type: 'sections', id: "#{ruby.id}"}}
731
+ put :update_relationship, {post_id: 4, relationship: 'section', data: {type: 'sections', id: "#{ruby.id}"}}
732
732
 
733
733
  assert_response :no_content
734
734
  post_object = Post.find(4)
735
735
  assert_equal ruby.id, post_object.section_id
736
736
  end
737
737
 
738
- def test_update_relationship_has_one_invalid_links_hash_keys_ids
738
+ def test_update_relationship_to_one_invalid_links_hash_keys_ids
739
739
  set_content_type_header!
740
- put :update_association, {post_id: 3, association: 'section', data: {type: 'sections', ids: 'foo'}}
740
+ put :update_relationship, {post_id: 3, relationship: 'section', data: {type: 'sections', ids: 'foo'}}
741
741
 
742
742
  assert_response :bad_request
743
743
  assert_match /Invalid Links Object/, response.body
744
744
  end
745
745
 
746
- def test_update_relationship_has_one_invalid_links_hash_count
746
+ def test_update_relationship_to_one_invalid_links_hash_count
747
747
  set_content_type_header!
748
- put :update_association, {post_id: 3, association: 'section', data: {type: 'sections'}}
748
+ put :update_relationship, {post_id: 3, relationship: 'section', data: {type: 'sections'}}
749
749
 
750
750
  assert_response :bad_request
751
751
  assert_match /Invalid Links Object/, response.body
752
752
  end
753
753
 
754
- def test_update_relationship_has_many_not_array
754
+ def test_update_relationship_to_many_not_array
755
755
  set_content_type_header!
756
- put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags', id: 2}}
756
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: {type: 'tags', id: 2}}
757
757
 
758
758
  assert_response :bad_request
759
759
  assert_match /Invalid Links Object/, response.body
760
760
  end
761
761
 
762
- def test_update_relationship_has_one_invalid_links_hash_keys_type_mismatch
762
+ def test_update_relationship_to_one_invalid_links_hash_keys_type_mismatch
763
763
  set_content_type_header!
764
- put :update_association, {post_id: 3, association: 'section', data: {type: 'comment', id: '3'}}
764
+ put :update_relationship, {post_id: 3, relationship: 'section', data: {type: 'comment', id: '3'}}
765
765
 
766
766
  assert_response :bad_request
767
767
  assert_match /Type Mismatch/, response.body
768
768
  end
769
769
 
770
- def test_update_nil_has_many_links
770
+ def test_update_nil_to_many_links
771
771
  set_content_type_header!
772
772
  put :update,
773
773
  {
@@ -785,7 +785,7 @@ class PostsControllerTest < ActionController::TestCase
785
785
  assert_match /Invalid Links Object/, response.body
786
786
  end
787
787
 
788
- def test_update_bad_hash_has_many_links
788
+ def test_update_bad_hash_to_many_links
789
789
  set_content_type_header!
790
790
  put :update,
791
791
  {
@@ -803,7 +803,7 @@ class PostsControllerTest < ActionController::TestCase
803
803
  assert_match /Invalid Links Object/, response.body
804
804
  end
805
805
 
806
- def test_update_other_has_many_links
806
+ def test_update_other_to_many_links
807
807
  set_content_type_header!
808
808
  put :update,
809
809
  {
@@ -821,7 +821,7 @@ class PostsControllerTest < ActionController::TestCase
821
821
  assert_match /Invalid Links Object/, response.body
822
822
  end
823
823
 
824
- def test_update_other_has_many_links_data_nil
824
+ def test_update_other_to_many_links_data_nil
825
825
  set_content_type_header!
826
826
  put :update,
827
827
  {
@@ -839,75 +839,75 @@ class PostsControllerTest < ActionController::TestCase
839
839
  assert_match /Invalid Links Object/, response.body
840
840
  end
841
841
 
842
- def test_update_relationship_has_one_singular_param_id_nil
842
+ def test_update_relationship_to_one_singular_param_id_nil
843
843
  set_content_type_header!
844
844
  ruby = Section.find_by(name: 'ruby')
845
845
  post_object = Post.find(3)
846
846
  post_object.section = ruby
847
847
  post_object.save!
848
848
 
849
- put :update_association, {post_id: 3, association: 'section', data: {type: 'sections', id: nil}}
849
+ put :update_relationship, {post_id: 3, relationship: 'section', data: {type: 'sections', id: nil}}
850
850
 
851
851
  assert_response :no_content
852
852
  assert_equal nil, post_object.reload.section_id
853
853
  end
854
854
 
855
- def test_update_relationship_has_one_data_nil
855
+ def test_update_relationship_to_one_data_nil
856
856
  set_content_type_header!
857
857
  ruby = Section.find_by(name: 'ruby')
858
858
  post_object = Post.find(3)
859
859
  post_object.section = ruby
860
860
  post_object.save!
861
861
 
862
- put :update_association, {post_id: 3, association: 'section', data: nil}
862
+ put :update_relationship, {post_id: 3, relationship: 'section', data: nil}
863
863
 
864
864
  assert_response :no_content
865
865
  assert_equal nil, post_object.reload.section_id
866
866
  end
867
867
 
868
- def test_remove_relationship_has_one
868
+ def test_remove_relationship_to_one
869
869
  set_content_type_header!
870
870
  ruby = Section.find_by(name: 'ruby')
871
871
  post_object = Post.find(3)
872
872
  post_object.section_id = ruby.id
873
873
  post_object.save!
874
874
 
875
- put :destroy_association, {post_id: 3, association: 'section'}
875
+ put :destroy_relationship, {post_id: 3, relationship: 'section'}
876
876
 
877
877
  assert_response :no_content
878
878
  post_object = Post.find(3)
879
879
  assert_equal nil, post_object.section_id
880
880
  end
881
881
 
882
- def test_update_relationship_has_one_singular_param
882
+ def test_update_relationship_to_one_singular_param
883
883
  set_content_type_header!
884
884
  ruby = Section.find_by(name: 'ruby')
885
885
  post_object = Post.find(3)
886
886
  post_object.section_id = nil
887
887
  post_object.save!
888
888
 
889
- put :update_association, {post_id: 3, association: 'section', data: {type: 'sections', id: "#{ruby.id}"}}
889
+ put :update_relationship, {post_id: 3, relationship: 'section', data: {type: 'sections', id: "#{ruby.id}"}}
890
890
 
891
891
  assert_response :no_content
892
892
  post_object = Post.find(3)
893
893
  assert_equal ruby.id, post_object.section_id
894
894
  end
895
895
 
896
- def test_update_relationship_has_many_join_table_single
896
+ def test_update_relationship_to_many_join_table_single
897
897
  set_content_type_header!
898
- put :update_association, {post_id: 3, association: 'tags', data: []}
898
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: []}
899
899
  assert_response :no_content
900
900
 
901
901
  post_object = Post.find(3)
902
902
  assert_equal 0, post_object.tags.length
903
903
 
904
- put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}]}
904
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 2}]}
905
905
 
906
906
  assert_response :no_content
907
907
  post_object = Post.find(3)
908
908
  assert_equal 1, post_object.tags.length
909
909
 
910
- put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 5}]}
910
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 5}]}
911
911
 
912
912
  assert_response :no_content
913
913
  post_object = Post.find(3)
@@ -916,9 +916,9 @@ class PostsControllerTest < ActionController::TestCase
916
916
  assert matches_array? [5], tags
917
917
  end
918
918
 
919
- def test_update_relationship_has_many
919
+ def test_update_relationship_to_many
920
920
  set_content_type_header!
921
- put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
921
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
922
922
 
923
923
  assert_response :no_content
924
924
  post_object = Post.find(3)
@@ -926,16 +926,16 @@ class PostsControllerTest < ActionController::TestCase
926
926
  assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
927
927
  end
928
928
 
929
- def test_create_relationship_has_many_join_table
929
+ def test_create_relationship_to_many_join_table
930
930
  set_content_type_header!
931
- put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
931
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
932
932
 
933
933
  assert_response :no_content
934
934
  post_object = Post.find(3)
935
935
  assert_equal 2, post_object.tags.collect { |tag| tag.id }.length
936
936
  assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
937
937
 
938
- post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 5}]}
938
+ post :create_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 5}]}
939
939
 
940
940
  assert_response :no_content
941
941
  post_object = Post.find(3)
@@ -943,103 +943,103 @@ class PostsControllerTest < ActionController::TestCase
943
943
  assert matches_array? [2, 3, 5], post_object.tags.collect { |tag| tag.id }
944
944
  end
945
945
 
946
- def test_create_relationship_has_many_mismatched_type
946
+ def test_create_relationship_to_many_mismatched_type
947
947
  set_content_type_header!
948
- post :create_association, {post_id: 3, association: 'tags', data: [{type: 'comments', id: 5}]}
948
+ post :create_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'comments', id: 5}]}
949
949
 
950
950
  assert_response :bad_request
951
951
  assert_match /Type Mismatch/, response.body
952
952
  end
953
953
 
954
- def test_create_relationship_has_many_missing_id
954
+ def test_create_relationship_to_many_missing_id
955
955
  set_content_type_header!
956
- post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', idd: 5}]}
956
+ post :create_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', idd: 5}]}
957
957
 
958
958
  assert_response :bad_request
959
959
  assert_match /Data is not a valid Links Object./, response.body
960
960
  end
961
961
 
962
- def test_create_relationship_has_many_not_array
962
+ def test_create_relationship_to_many_not_array
963
963
  set_content_type_header!
964
- post :create_association, {post_id: 3, association: 'tags', data: {type: 'tags', id: 5}}
964
+ post :create_relationship, {post_id: 3, relationship: 'tags', data: {type: 'tags', id: 5}}
965
965
 
966
966
  assert_response :bad_request
967
967
  assert_match /Data is not a valid Links Object./, response.body
968
968
  end
969
969
 
970
- def test_create_relationship_has_many_missing_data
970
+ def test_create_relationship_to_many_missing_data
971
971
  set_content_type_header!
972
- post :create_association, {post_id: 3, association: 'tags'}
972
+ post :create_relationship, {post_id: 3, relationship: 'tags'}
973
973
 
974
974
  assert_response :bad_request
975
975
  assert_match /The required parameter, data, is missing./, response.body
976
976
  end
977
977
 
978
- def test_create_relationship_has_many_join
978
+ def test_create_relationship_to_many_join
979
979
  set_content_type_header!
980
- post :create_association, {post_id: 4, association: 'tags', data: [{type: 'tags', id: 1}, {type: 'tags', id: 2}, {type: 'tags', id: 3}]}
980
+ post :create_relationship, {post_id: 4, relationship: 'tags', data: [{type: 'tags', id: 1}, {type: 'tags', id: 2}, {type: 'tags', id: 3}]}
981
981
  assert_response :no_content
982
982
  end
983
983
 
984
- def test_create_relationship_has_many_join_table_record_exists
984
+ def test_create_relationship_to_many_join_table_record_exists
985
985
  set_content_type_header!
986
- put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
986
+ put :update_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
987
987
 
988
988
  assert_response :no_content
989
989
  post_object = Post.find(3)
990
990
  assert_equal 2, post_object.tags.collect { |tag| tag.id }.length
991
991
  assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
992
992
 
993
- post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 5}]}
993
+ post :create_relationship, {post_id: 3, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 5}]}
994
994
 
995
995
  assert_response :bad_request
996
996
  assert_match /The relation to 2 already exists./, response.body
997
997
  end
998
998
 
999
- def test_update_relationship_has_many_missing_tags
999
+ def test_update_relationship_to_many_missing_tags
1000
1000
  set_content_type_header!
1001
- put :update_association, {post_id: 3, association: 'tags'}
1001
+ put :update_relationship, {post_id: 3, relationship: 'tags'}
1002
1002
 
1003
1003
  assert_response :bad_request
1004
1004
  assert_match /The required parameter, data, is missing./, response.body
1005
1005
  end
1006
1006
 
1007
- def test_delete_relationship_has_many
1007
+ def test_delete_relationship_to_many
1008
1008
  set_content_type_header!
1009
- put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1009
+ put :update_relationship, {post_id: 14, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1010
1010
  assert_response :no_content
1011
1011
  p = Post.find(14)
1012
1012
  assert_equal [2, 3], p.tag_ids
1013
1013
 
1014
- delete :destroy_association, {post_id: 14, association: 'tags', keys: '3'}
1014
+ delete :destroy_relationship, {post_id: 14, relationship: 'tags', keys: '3'}
1015
1015
 
1016
1016
  p.reload
1017
1017
  assert_response :no_content
1018
1018
  assert_equal [2], p.tag_ids
1019
1019
  end
1020
1020
 
1021
- def test_delete_relationship_has_many_does_not_exist
1021
+ def test_delete_relationship_to_many_does_not_exist
1022
1022
  set_content_type_header!
1023
- put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1023
+ put :update_relationship, {post_id: 14, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1024
1024
  assert_response :no_content
1025
1025
  p = Post.find(14)
1026
1026
  assert_equal [2, 3], p.tag_ids
1027
1027
 
1028
- delete :destroy_association, {post_id: 14, association: 'tags', keys: '4'}
1028
+ delete :destroy_relationship, {post_id: 14, relationship: 'tags', keys: '4'}
1029
1029
 
1030
1030
  p.reload
1031
1031
  assert_response :not_found
1032
1032
  assert_equal [2, 3], p.tag_ids
1033
1033
  end
1034
1034
 
1035
- def test_delete_relationship_has_many_with_empty_data
1035
+ def test_delete_relationship_to_many_with_empty_data
1036
1036
  set_content_type_header!
1037
- put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1037
+ put :update_relationship, {post_id: 14, relationship: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
1038
1038
  assert_response :no_content
1039
1039
  p = Post.find(14)
1040
1040
  assert_equal [2, 3], p.tag_ids
1041
1041
 
1042
- put :update_association, {post_id: 14, association: 'tags', data: [] }
1042
+ put :update_relationship, {post_id: 14, relationship: 'tags', data: [] }
1043
1043
 
1044
1044
  p.reload
1045
1045
  assert_response :no_content
@@ -1246,15 +1246,11 @@ class PostsControllerTest < ActionController::TestCase
1246
1246
 
1247
1247
  assert_response :success
1248
1248
  assert_equal json_response['data'].size, 2
1249
- assert_equal json_response['data'][0]['relationships']['author']['data']['id'], '3'
1250
- assert_equal json_response['data'][0]['relationships']['section']['data']['id'], javascript.id.to_s
1251
1249
  assert_equal json_response['data'][0]['attributes']['title'], 'A great new Post QWERTY'
1252
1250
  assert_equal json_response['data'][0]['attributes']['body'], 'AAAA'
1253
1251
  assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
1254
1252
  json_response['data'][0]['relationships']['tags']['data'])
1255
1253
 
1256
- assert_equal json_response['data'][1]['relationships']['author']['data']['id'], '3'
1257
- assert_equal json_response['data'][1]['relationships']['section']['data']['id'], javascript.id.to_s
1258
1254
  assert_equal json_response['data'][1]['attributes']['title'], 'A great new Post ASDFG'
1259
1255
  assert_equal json_response['data'][1]['attributes']['body'], 'Not First!!!!'
1260
1256
  assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
@@ -1438,8 +1434,8 @@ class PostsControllerTest < ActionController::TestCase
1438
1434
  assert_equal initial_count, Post.count
1439
1435
  end
1440
1436
 
1441
- def test_show_has_one_relationship
1442
- get :show_association, {post_id: '1', association: 'author'}
1437
+ def test_show_to_one_relationship
1438
+ get :show_relationship, {post_id: '1', relationship: 'author'}
1443
1439
  assert_response :success
1444
1440
  assert_hash_equals json_response,
1445
1441
  {data: {
@@ -1453,8 +1449,8 @@ class PostsControllerTest < ActionController::TestCase
1453
1449
  }
1454
1450
  end
1455
1451
 
1456
- def test_show_has_many_relationship
1457
- get :show_association, {post_id: '2', association: 'tags'}
1452
+ def test_show_to_many_relationship
1453
+ get :show_relationship, {post_id: '2', relationship: 'tags'}
1458
1454
  assert_response :success
1459
1455
  assert_hash_equals json_response,
1460
1456
  {
@@ -1468,14 +1464,14 @@ class PostsControllerTest < ActionController::TestCase
1468
1464
  }
1469
1465
  end
1470
1466
 
1471
- def test_show_has_many_relationship_invalid_id
1472
- get :show_association, {post_id: '2,1', association: 'tags'}
1467
+ def test_show_to_many_relationship_invalid_id
1468
+ get :show_relationship, {post_id: '2,1', relationship: 'tags'}
1473
1469
  assert_response :bad_request
1474
1470
  assert_match /2,1 is not a valid value for id/, response.body
1475
1471
  end
1476
1472
 
1477
- def test_show_has_one_relationship_nil
1478
- get :show_association, {post_id: '17', association: 'author'}
1473
+ def test_show_to_one_relationship_nil
1474
+ get :show_relationship, {post_id: '17', relationship: 'author'}
1479
1475
  assert_response :success
1480
1476
  assert_hash_equals json_response,
1481
1477
  {
@@ -1554,17 +1550,17 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1554
1550
  assert_equal 2, json_response['included'].size
1555
1551
  end
1556
1552
 
1557
- def test_expense_entries_show_bad_include_missing_association
1553
+ def test_expense_entries_show_bad_include_missing_relationship
1558
1554
  get :show, {id: 1, include: 'isoCurrencies,employees'}
1559
1555
  assert_response :bad_request
1560
- assert_match /isoCurrencies is not a valid association of expenseEntries/, json_response['errors'][0]['detail']
1561
- assert_match /employees is not a valid association of expenseEntries/, json_response['errors'][1]['detail']
1556
+ assert_match /isoCurrencies is not a valid relationship of expenseEntries/, json_response['errors'][0]['detail']
1557
+ assert_match /employees is not a valid relationship of expenseEntries/, json_response['errors'][1]['detail']
1562
1558
  end
1563
1559
 
1564
- def test_expense_entries_show_bad_include_missing_sub_association
1560
+ def test_expense_entries_show_bad_include_missing_sub_relationship
1565
1561
  get :show, {id: 1, include: 'isoCurrency,employee.post'}
1566
1562
  assert_response :bad_request
1567
- assert_match /post is not a valid association of people/, json_response['errors'][0]['detail']
1563
+ assert_match /post is not a valid relationship of people/, json_response['errors'][0]['detail']
1568
1564
  end
1569
1565
 
1570
1566
  def test_expense_entries_show_fields
@@ -1601,7 +1597,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1601
1597
  iso_currency: {data: {type: 'iso_currencies', id: 'USD'}}
1602
1598
  }
1603
1599
  },
1604
- include: 'iso_currency',
1600
+ include: 'iso_currency,employee',
1605
1601
  fields: {expense_entries: 'id,transaction_date,iso_currency,cost,employee'}
1606
1602
  }
1607
1603
 
@@ -1632,7 +1628,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1632
1628
  isoCurrency: {data: {type: 'iso_currencies', id: 'USD'}}
1633
1629
  }
1634
1630
  },
1635
- include: 'isoCurrency',
1631
+ include: 'isoCurrency,employee',
1636
1632
  fields: {expenseEntries: 'id,transactionDate,isoCurrency,cost,employee'}
1637
1633
  }
1638
1634
 
@@ -1663,7 +1659,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1663
1659
  'iso-currency' => {data: {type: 'iso_currencies', id: 'USD'}}
1664
1660
  }
1665
1661
  },
1666
- include: 'iso-currency',
1662
+ include: 'iso-currency,employee',
1667
1663
  fields: {'expense-entries' => 'id,transaction-date,iso-currency,cost,employee'}
1668
1664
  }
1669
1665
 
@@ -1916,7 +1912,7 @@ class PeopleControllerTest < ActionController::TestCase
1916
1912
  def test_get_related_resource
1917
1913
  JSONAPI.configuration.json_key_format = :dasherized_key
1918
1914
  JSONAPI.configuration.route_format = :underscored_key
1919
- get :get_related_resource, {post_id: '2', association: 'author', source:'posts'}
1915
+ get :get_related_resource, {post_id: '2', relationship: 'author', source:'posts'}
1920
1916
  assert_response :success
1921
1917
  assert_hash_equals(
1922
1918
  {
@@ -1948,18 +1944,13 @@ class PeopleControllerTest < ActionController::TestCase
1948
1944
  links: {
1949
1945
  self: 'http://test.host/people/1/relationships/preferences',
1950
1946
  related: 'http://test.host/people/1/preferences'
1951
- },
1952
- data: {
1953
- type: 'preferences',
1954
- id: '1'
1955
1947
  }
1956
1948
  },
1957
1949
  "hair-cut" => {
1958
1950
  "links" => {
1959
1951
  "self" => "http://test.host/people/1/relationships/hair_cut",
1960
1952
  "related" => "http://test.host/people/1/hair_cut"
1961
- },
1962
- "data" => nil
1953
+ }
1963
1954
  },
1964
1955
  vehicles: {
1965
1956
  links: {
@@ -1975,7 +1966,7 @@ class PeopleControllerTest < ActionController::TestCase
1975
1966
  end
1976
1967
 
1977
1968
  def test_get_related_resource_nil
1978
- get :get_related_resource, {post_id: '17', association: 'author', source:'posts'}
1969
+ get :get_related_resource, {post_id: '17', relationship: 'author', source:'posts'}
1979
1970
  assert_response :success
1980
1971
  assert_hash_equals json_response,
1981
1972
  {
@@ -2129,7 +2120,7 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
2129
2120
  assert_equal 'joe@xyz.fake', json_response['included'][0]['attributes']['email']
2130
2121
  end
2131
2122
 
2132
- def test_index_filter_on_association_namespaced
2123
+ def test_index_filter_on_relationship_namespaced
2133
2124
  get :index, {filter: {writer: '1'}}
2134
2125
  assert_response :success
2135
2126
  assert_equal 3, json_response['data'].size
@@ -2160,7 +2151,6 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
2160
2151
 
2161
2152
  assert_response :created
2162
2153
  assert json_response['data'].is_a?(Hash)
2163
- assert_equal '3', json_response['data']['relationships']['writer']['data']['id']
2164
2154
  assert_equal 'JR - now with Namespacing', json_response['data']['attributes']['title']
2165
2155
  assert_equal 'JSONAPIResources is the greatest thing since unsliced bread now that it has namespaced resources.',
2166
2156
  json_response['data']['attributes']['body']