jsonapi-resources 0.2.0 → 0.3.0.pre1
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +5 -2
- data/Gemfile +3 -1
- data/README.md +52 -13
- data/jsonapi-resources.gemspec +1 -1
- data/lib/jsonapi-resources.rb +1 -0
- data/lib/jsonapi/association.rb +1 -9
- data/lib/jsonapi/error_codes.rb +1 -0
- data/lib/jsonapi/exceptions.rb +9 -5
- data/lib/jsonapi/formatter.rb +9 -18
- data/lib/jsonapi/paginator.rb +4 -15
- data/lib/jsonapi/request.rb +26 -42
- data/lib/jsonapi/resource.rb +35 -45
- data/lib/jsonapi/resource_controller.rb +6 -32
- data/lib/jsonapi/resource_serializer.rb +62 -33
- data/lib/jsonapi/resources/version.rb +1 -1
- data/lib/jsonapi/routing_ext.rb +4 -4
- data/test/config/database.yml +2 -1
- data/test/controllers/controller_test.rb +200 -160
- data/test/fixtures/active_record.rb +44 -201
- data/test/fixtures/book_comments.yml +11 -0
- data/test/fixtures/books.yml +6 -0
- data/test/fixtures/comments.yml +17 -0
- data/test/fixtures/comments_tags.yml +20 -0
- data/test/fixtures/expense_entries.yml +13 -0
- data/test/fixtures/facts.yml +11 -0
- data/test/fixtures/iso_currencies.yml +17 -0
- data/test/fixtures/people.yml +24 -0
- data/test/fixtures/posts.yml +96 -0
- data/test/fixtures/posts_tags.yml +59 -0
- data/test/fixtures/preferences.yml +18 -0
- data/test/fixtures/sections.yml +8 -0
- data/test/fixtures/tags.yml +39 -0
- data/test/helpers/hash_helpers.rb +0 -7
- data/test/integration/requests/request_test.rb +86 -28
- data/test/integration/routes/routes_test.rb +14 -25
- data/test/test_helper.rb +41 -17
- data/test/unit/jsonapi_request/jsonapi_request_test.rb +152 -0
- data/test/unit/operation/operations_processor_test.rb +13 -2
- data/test/unit/resource/resource_test.rb +68 -13
- data/test/unit/serializer/serializer_test.rb +328 -220
- metadata +33 -6
- data/lib/jsonapi/resource_for.rb +0 -29
data/lib/jsonapi/routing_ext.rb
CHANGED
@@ -102,7 +102,7 @@ module ActionDispatch
|
|
102
102
|
|
103
103
|
if methods.include?(:update)
|
104
104
|
match "links/#{formatted_association_name}", controller: res._type.to_s,
|
105
|
-
action: 'update_association', association: link_type.to_s, via: [:put]
|
105
|
+
action: 'update_association', association: link_type.to_s, via: [:put, :patch]
|
106
106
|
end
|
107
107
|
|
108
108
|
if methods.include?(:destroy)
|
@@ -132,7 +132,7 @@ module ActionDispatch
|
|
132
132
|
|
133
133
|
if methods.include?(:update) && res._association(link_type).acts_as_set
|
134
134
|
match "links/#{formatted_association_name}", controller: res._type.to_s,
|
135
|
-
action: 'update_association', association: link_type.to_s, via: [:put]
|
135
|
+
action: 'update_association', association: link_type.to_s, via: [:put, :patch]
|
136
136
|
end
|
137
137
|
|
138
138
|
if methods.include?(:destroy)
|
@@ -148,7 +148,7 @@ module ActionDispatch
|
|
148
148
|
association = source._associations[association_name]
|
149
149
|
|
150
150
|
formatted_association_name = format_route(association.name)
|
151
|
-
related_resource = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(association.
|
151
|
+
related_resource = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(association.class_name.underscore.pluralize))
|
152
152
|
|
153
153
|
match "#{formatted_association_name}", controller: related_resource._type.to_s,
|
154
154
|
association: association.name, source: resource_type_with_module_prefix(source._type),
|
@@ -162,7 +162,7 @@ module ActionDispatch
|
|
162
162
|
association = source._associations[association_name]
|
163
163
|
|
164
164
|
formatted_association_name = format_route(association.name)
|
165
|
-
related_resource = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(association.
|
165
|
+
related_resource = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(association.class_name.underscore))
|
166
166
|
|
167
167
|
match "#{formatted_association_name}", controller: related_resource._type.to_s,
|
168
168
|
association: association.name, source: resource_type_with_module_prefix(source._type),
|
data/test/config/database.yml
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require File.expand_path('../../fixtures/active_record', __FILE__)
|
3
2
|
|
4
3
|
def set_content_type_header!
|
5
4
|
@request.headers['Content-Type'] = JSONAPI::MEDIA_TYPE
|
@@ -44,18 +43,18 @@ class PostsControllerTest < ActionController::TestCase
|
|
44
43
|
get :index, {filter: {id: '2'}, include: 'comments'}
|
45
44
|
assert_response :success
|
46
45
|
assert_equal 1, json_response['data'].size
|
47
|
-
assert_equal 1, json_response['
|
46
|
+
assert_equal 1, json_response['included'].size
|
48
47
|
end
|
49
48
|
|
50
49
|
def test_index_filter_by_ids_and_include_related_different_type
|
51
50
|
get :index, {filter: {id: '1,2'}, include: 'author'}
|
52
51
|
assert_response :success
|
53
52
|
assert_equal 2, json_response['data'].size
|
54
|
-
assert_equal 1, json_response['
|
53
|
+
assert_equal 1, json_response['included'].size
|
55
54
|
end
|
56
55
|
|
57
56
|
def test_index_filter_by_ids_and_fields
|
58
|
-
get :index, {filter: {id: '1,2'},
|
57
|
+
get :index, {filter: {id: '1,2'}, fields: {posts: 'id,title,author'}}
|
59
58
|
assert_response :success
|
60
59
|
assert_equal 2, json_response['data'].size
|
61
60
|
|
@@ -87,7 +86,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
87
86
|
end
|
88
87
|
|
89
88
|
def test_index_filter_by_ids_and_fields_2
|
90
|
-
get :index, {filter: {id: '1,2'},
|
89
|
+
get :index, {filter: {id: '1,2'}, fields: {posts: 'author'}}
|
91
90
|
assert_response :success
|
92
91
|
assert_equal 2, json_response['data'].size
|
93
92
|
|
@@ -150,12 +149,6 @@ class PostsControllerTest < ActionController::TestCase
|
|
150
149
|
assert_match /5412333 could not be found/, json_response['errors'][0]['detail']
|
151
150
|
end
|
152
151
|
|
153
|
-
def test_index_malformed_fields
|
154
|
-
get :index, {filter: {id: '1,2'}, 'fields' => 'posts'}
|
155
|
-
assert_response :bad_request
|
156
|
-
assert_match /posts is not a valid field for posts./, json_response['errors'][0]['detail']
|
157
|
-
end
|
158
|
-
|
159
152
|
def test_field_not_supported
|
160
153
|
get :index, {filter: {id: '1,2'}, 'fields' => {'posts' => 'id,title,rank,author'}}
|
161
154
|
assert_response :bad_request
|
@@ -178,7 +171,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
178
171
|
get :index, {sort: '+title'}
|
179
172
|
|
180
173
|
assert_response :success
|
181
|
-
assert_equal "
|
174
|
+
assert_equal "A First Post", json_response['data'][0]['title']
|
182
175
|
end
|
183
176
|
|
184
177
|
def test_sorting_desc
|
@@ -192,7 +185,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
192
185
|
get :index, {sort: '+title,+body'}
|
193
186
|
|
194
187
|
assert_response :success
|
195
|
-
assert_equal '
|
188
|
+
assert_equal '14', json_response['data'][0]['id']
|
196
189
|
end
|
197
190
|
|
198
191
|
def test_invalid_sort_param
|
@@ -216,19 +209,13 @@ class PostsControllerTest < ActionController::TestCase
|
|
216
209
|
assert_match /id is not a valid sort criteria for post/, response.body
|
217
210
|
end
|
218
211
|
|
219
|
-
# ToDo: test validating the parameter values
|
220
|
-
# def test_index_invalid_filter_value
|
221
|
-
# get :index, {ids: [1,'asdfg1']}
|
222
|
-
# assert_response :bad_request
|
223
|
-
# end
|
224
|
-
|
225
212
|
def test_show_single
|
226
213
|
get :show, {id: '1'}
|
227
214
|
assert_response :success
|
228
215
|
assert json_response['data'].is_a?(Hash)
|
229
216
|
assert_equal 'New post', json_response['data']['title']
|
230
217
|
assert_equal 'A body!!!', json_response['data']['body']
|
231
|
-
assert_nil json_response['
|
218
|
+
assert_nil json_response['included']
|
232
219
|
end
|
233
220
|
|
234
221
|
def test_show_single_with_includes
|
@@ -237,18 +224,25 @@ class PostsControllerTest < ActionController::TestCase
|
|
237
224
|
assert json_response['data'].is_a?(Hash)
|
238
225
|
assert_equal 'New post', json_response['data']['title']
|
239
226
|
assert_equal 'A body!!!', json_response['data']['body']
|
240
|
-
assert_nil json_response['data']['links']['tags']['
|
241
|
-
|
242
|
-
|
227
|
+
assert_nil json_response['data']['links']['tags']['linkage']
|
228
|
+
assert matches_array?([{'type' => 'comments', 'id' => '1'}, {'type' => 'comments', 'id' => '2'}],
|
229
|
+
json_response['data']['links']['comments']['linkage'])
|
230
|
+
assert_equal 2, json_response['included'].size
|
243
231
|
end
|
244
232
|
|
245
233
|
def test_show_single_with_fields
|
246
|
-
get :show, {id: '1', fields: 'author'}
|
234
|
+
get :show, {id: '1', fields: {posts: 'author'}}
|
247
235
|
assert_response :success
|
248
236
|
assert json_response['data'].is_a?(Hash)
|
249
237
|
assert_nil json_response['data']['title']
|
250
238
|
assert_nil json_response['data']['body']
|
251
|
-
assert_equal '1', json_response['data']['links']['author']['id']
|
239
|
+
assert_equal '1', json_response['data']['links']['author']['linkage']['id']
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_show_single_with_fields_string
|
243
|
+
get :show, {id: '1', fields: 'author'}
|
244
|
+
assert_response :bad_request
|
245
|
+
assert_match /Fields must specify a type./, json_response['errors'][0]['detail']
|
252
246
|
end
|
253
247
|
|
254
248
|
def test_show_single_invalid_id_format
|
@@ -266,7 +260,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
266
260
|
def test_show_malformed_fields_not_list
|
267
261
|
get :show, {id: '1', 'fields' => ''}
|
268
262
|
assert_response :bad_request
|
269
|
-
assert_match /
|
263
|
+
assert_match /Fields must specify a type./, json_response['errors'][0]['detail']
|
270
264
|
end
|
271
265
|
|
272
266
|
def test_show_malformed_fields_type_not_list
|
@@ -291,7 +285,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
291
285
|
|
292
286
|
assert_response :created
|
293
287
|
assert json_response['data'].is_a?(Hash)
|
294
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
288
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
295
289
|
assert_equal 'JR is Great', json_response['data']['title']
|
296
290
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['body']
|
297
291
|
end
|
@@ -386,7 +380,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
386
380
|
assert_response :created
|
387
381
|
assert json_response['data'].is_a?(Array)
|
388
382
|
assert_equal json_response['data'].size, 2
|
389
|
-
assert_equal json_response['data'][0]['links']['author']['id'], '3'
|
383
|
+
assert_equal json_response['data'][0]['links']['author']['linkage']['id'], '3'
|
390
384
|
assert_match /JR is Great/, response.body
|
391
385
|
assert_match /Ember is Great/, response.body
|
392
386
|
end
|
@@ -500,14 +494,14 @@ class PostsControllerTest < ActionController::TestCase
|
|
500
494
|
body: 'JSONAPIResources is the greatest thing since unsliced bread.',
|
501
495
|
links: {
|
502
496
|
author: {type: 'people', id: '3'},
|
503
|
-
tags: {type: 'tags',
|
497
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
504
498
|
}
|
505
499
|
}
|
506
500
|
}
|
507
501
|
|
508
502
|
assert_response :created
|
509
503
|
assert json_response['data'].is_a?(Hash)
|
510
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
504
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
511
505
|
assert_equal 'JR is Great', json_response['data']['title']
|
512
506
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['body']
|
513
507
|
end
|
@@ -529,7 +523,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
529
523
|
|
530
524
|
assert_response :created
|
531
525
|
assert json_response['data'].is_a?(Hash)
|
532
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
526
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
533
527
|
assert_equal 'JR is Great', json_response['data']['title']
|
534
528
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['data']['body']
|
535
529
|
end
|
@@ -544,18 +538,18 @@ class PostsControllerTest < ActionController::TestCase
|
|
544
538
|
body: 'JSONAPIResources is the greatest thing since unsliced bread!',
|
545
539
|
links: {
|
546
540
|
author: {type: 'people', id: '3'},
|
547
|
-
tags: {type: 'tags',
|
541
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
548
542
|
}
|
549
543
|
},
|
550
544
|
include: 'author,author.posts',
|
551
|
-
fields: 'id,title,author'
|
545
|
+
fields: {posts: 'id,title,author'}
|
552
546
|
}
|
553
547
|
|
554
548
|
assert_response :created
|
555
549
|
assert json_response['data'].is_a?(Hash)
|
556
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
550
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
557
551
|
assert_equal 'JR is Great!', json_response['data']['title']
|
558
|
-
assert_not_nil json_response['
|
552
|
+
assert_not_nil json_response['included'].size
|
559
553
|
end
|
560
554
|
|
561
555
|
def test_update_with_links
|
@@ -571,7 +565,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
571
565
|
title: 'A great new Post',
|
572
566
|
links: {
|
573
567
|
section: {type: 'sections', id: "#{javascript.id}"},
|
574
|
-
tags: {type: 'tags',
|
568
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
575
569
|
}
|
576
570
|
},
|
577
571
|
include: 'tags'
|
@@ -579,11 +573,12 @@ class PostsControllerTest < ActionController::TestCase
|
|
579
573
|
|
580
574
|
assert_response :success
|
581
575
|
assert json_response['data'].is_a?(Hash)
|
582
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
583
|
-
assert_equal javascript.id.to_s, json_response['data']['links']['section']['id']
|
576
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
577
|
+
assert_equal javascript.id.to_s, json_response['data']['links']['section']['linkage']['id']
|
584
578
|
assert_equal 'A great new Post', json_response['data']['title']
|
585
579
|
assert_equal 'AAAA', json_response['data']['body']
|
586
|
-
assert matches_array?(['
|
580
|
+
assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
|
581
|
+
json_response['data']['links']['tags']['linkage'])
|
587
582
|
end
|
588
583
|
|
589
584
|
def test_update_remove_links
|
@@ -605,29 +600,30 @@ class PostsControllerTest < ActionController::TestCase
|
|
605
600
|
|
606
601
|
assert_response :success
|
607
602
|
assert json_response['data'].is_a?(Hash)
|
608
|
-
assert_equal '3', json_response['data']['links']['author']['id']
|
609
|
-
assert_equal nil, json_response['data']['links']['section']['id']
|
603
|
+
assert_equal '3', json_response['data']['links']['author']['linkage']['id']
|
604
|
+
assert_equal nil, json_response['data']['links']['section']['linkage']['id']
|
610
605
|
assert_equal 'A great new Post', json_response['data']['title']
|
611
606
|
assert_equal 'AAAA', json_response['data']['body']
|
612
|
-
assert matches_array?([],
|
607
|
+
assert matches_array?([],
|
608
|
+
json_response['data']['links']['tags']['linkage'])
|
613
609
|
end
|
614
610
|
|
615
611
|
def test_update_relationship_has_one
|
616
612
|
set_content_type_header!
|
617
613
|
ruby = Section.find_by(name: 'ruby')
|
618
|
-
post_object = Post.find(
|
614
|
+
post_object = Post.find(4)
|
619
615
|
assert_not_equal ruby.id, post_object.section_id
|
620
616
|
|
621
|
-
put :update_association, {post_id:
|
617
|
+
put :update_association, {post_id: 4, association: 'section', data: {type: 'sections', id: "#{ruby.id}"}}
|
622
618
|
|
623
619
|
assert_response :no_content
|
624
|
-
post_object = Post.find(
|
620
|
+
post_object = Post.find(4)
|
625
621
|
assert_equal ruby.id, post_object.section_id
|
626
622
|
end
|
627
623
|
|
628
624
|
def test_update_relationship_has_one_invalid_links_hash_keys_ids
|
629
625
|
set_content_type_header!
|
630
|
-
put :update_association, {post_id: 3, association: 'section', data: {
|
626
|
+
put :update_association, {post_id: 3, association: 'section', data: {type: 'sections', ids: 'foo'}}
|
631
627
|
|
632
628
|
assert_response :bad_request
|
633
629
|
assert_match /Invalid Links Object/, response.body
|
@@ -635,7 +631,15 @@ class PostsControllerTest < ActionController::TestCase
|
|
635
631
|
|
636
632
|
def test_update_relationship_has_one_invalid_links_hash_count
|
637
633
|
set_content_type_header!
|
638
|
-
put :update_association, {post_id: 3, association: 'section', data: {
|
634
|
+
put :update_association, {post_id: 3, association: 'section', data: {type: 'sections'}}
|
635
|
+
|
636
|
+
assert_response :bad_request
|
637
|
+
assert_match /Invalid Links Object/, response.body
|
638
|
+
end
|
639
|
+
|
640
|
+
def test_update_relationship_has_many_not_array
|
641
|
+
set_content_type_header!
|
642
|
+
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags', id: 2}}
|
639
643
|
|
640
644
|
assert_response :bad_request
|
641
645
|
assert_match /Invalid Links Object/, response.body
|
@@ -707,14 +711,26 @@ class PostsControllerTest < ActionController::TestCase
|
|
707
711
|
set_content_type_header!
|
708
712
|
ruby = Section.find_by(name: 'ruby')
|
709
713
|
post_object = Post.find(3)
|
710
|
-
post_object.
|
714
|
+
post_object.section = ruby
|
711
715
|
post_object.save!
|
712
716
|
|
713
717
|
put :update_association, {post_id: 3, association: 'section', data: {type: 'sections', id: nil}}
|
714
718
|
|
715
719
|
assert_response :no_content
|
720
|
+
assert_equal nil, post_object.reload.section_id
|
721
|
+
end
|
722
|
+
|
723
|
+
def test_update_relationship_has_one_data_nil
|
724
|
+
set_content_type_header!
|
725
|
+
ruby = Section.find_by(name: 'ruby')
|
716
726
|
post_object = Post.find(3)
|
717
|
-
|
727
|
+
post_object.section = ruby
|
728
|
+
post_object.save!
|
729
|
+
|
730
|
+
put :update_association, {post_id: 3, association: 'section', data: nil}
|
731
|
+
|
732
|
+
assert_response :no_content
|
733
|
+
assert_equal nil, post_object.reload.section_id
|
718
734
|
end
|
719
735
|
|
720
736
|
def test_remove_relationship_has_one
|
@@ -747,19 +763,19 @@ class PostsControllerTest < ActionController::TestCase
|
|
747
763
|
|
748
764
|
def test_update_relationship_has_many_join_table_single
|
749
765
|
set_content_type_header!
|
750
|
-
put :update_association, {post_id: 3, association: 'tags', data:
|
766
|
+
put :update_association, {post_id: 3, association: 'tags', data: []}
|
751
767
|
assert_response :no_content
|
752
768
|
|
753
769
|
post_object = Post.find(3)
|
754
770
|
assert_equal 0, post_object.tags.length
|
755
771
|
|
756
|
-
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
772
|
+
put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}]}
|
757
773
|
|
758
774
|
assert_response :no_content
|
759
775
|
post_object = Post.find(3)
|
760
776
|
assert_equal 1, post_object.tags.length
|
761
777
|
|
762
|
-
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
778
|
+
put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 5}]}
|
763
779
|
|
764
780
|
assert_response :no_content
|
765
781
|
post_object = Post.find(3)
|
@@ -768,17 +784,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
768
784
|
assert matches_array? [5], tags
|
769
785
|
end
|
770
786
|
|
771
|
-
def
|
772
|
-
set_content_type_header!
|
773
|
-
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags', ids: [2, 3]}}
|
774
|
-
|
775
|
-
assert_response :no_content
|
776
|
-
post_object = Post.find(3)
|
777
|
-
assert_equal 2, post_object.tags.collect { |tag| tag.id }.length
|
778
|
-
assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
|
779
|
-
end
|
780
|
-
|
781
|
-
def test_update_relationship_has_many_join_table_heterogenous
|
787
|
+
def test_update_relationship_has_many
|
782
788
|
set_content_type_header!
|
783
789
|
put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
784
790
|
|
@@ -790,14 +796,14 @@ class PostsControllerTest < ActionController::TestCase
|
|
790
796
|
|
791
797
|
def test_create_relationship_has_many_join_table
|
792
798
|
set_content_type_header!
|
793
|
-
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
799
|
+
put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
794
800
|
|
795
801
|
assert_response :no_content
|
796
802
|
post_object = Post.find(3)
|
797
803
|
assert_equal 2, post_object.tags.collect { |tag| tag.id }.length
|
798
804
|
assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
|
799
805
|
|
800
|
-
post :create_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
806
|
+
post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 5}]}
|
801
807
|
|
802
808
|
assert_response :no_content
|
803
809
|
post_object = Post.find(3)
|
@@ -807,7 +813,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
807
813
|
|
808
814
|
def test_create_relationship_has_many_mismatched_type
|
809
815
|
set_content_type_header!
|
810
|
-
post :create_association, {post_id: 3, association: 'tags', data: {type: 'comments',
|
816
|
+
post :create_association, {post_id: 3, association: 'tags', data: [{type: 'comments', id: 5}]}
|
811
817
|
|
812
818
|
assert_response :bad_request
|
813
819
|
assert_match /Type Mismatch/, response.body
|
@@ -815,10 +821,18 @@ class PostsControllerTest < ActionController::TestCase
|
|
815
821
|
|
816
822
|
def test_create_relationship_has_many_missing_id
|
817
823
|
set_content_type_header!
|
818
|
-
post :create_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
824
|
+
post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', idd: 5}]}
|
819
825
|
|
820
826
|
assert_response :bad_request
|
821
|
-
assert_match /
|
827
|
+
assert_match /Data is not a valid Links Object./, response.body
|
828
|
+
end
|
829
|
+
|
830
|
+
def test_create_relationship_has_many_not_array
|
831
|
+
set_content_type_header!
|
832
|
+
post :create_association, {post_id: 3, association: 'tags', data: {type: 'tags', id: 5}}
|
833
|
+
|
834
|
+
assert_response :bad_request
|
835
|
+
assert_match /Data is not a valid Links Object./, response.body
|
822
836
|
end
|
823
837
|
|
824
838
|
def test_create_relationship_has_many_missing_data
|
@@ -831,20 +845,20 @@ class PostsControllerTest < ActionController::TestCase
|
|
831
845
|
|
832
846
|
def test_create_relationship_has_many_join
|
833
847
|
set_content_type_header!
|
834
|
-
post :create_association, {post_id: 4, association: 'tags', data: {type: 'tags',
|
848
|
+
post :create_association, {post_id: 4, association: 'tags', data: [{type: 'tags', id: 1}, {type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
835
849
|
assert_response :no_content
|
836
850
|
end
|
837
851
|
|
838
852
|
def test_create_relationship_has_many_join_table_record_exists
|
839
853
|
set_content_type_header!
|
840
|
-
put :update_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
854
|
+
put :update_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
841
855
|
|
842
856
|
assert_response :no_content
|
843
857
|
post_object = Post.find(3)
|
844
858
|
assert_equal 2, post_object.tags.collect { |tag| tag.id }.length
|
845
859
|
assert matches_array? [2, 3], post_object.tags.collect { |tag| tag.id }
|
846
860
|
|
847
|
-
post :create_association, {post_id: 3, association: 'tags', data: {type: 'tags',
|
861
|
+
post :create_association, {post_id: 3, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 5}]}
|
848
862
|
|
849
863
|
assert_response :bad_request
|
850
864
|
assert_match /The relation to 2 already exists./, response.body
|
@@ -860,12 +874,12 @@ class PostsControllerTest < ActionController::TestCase
|
|
860
874
|
|
861
875
|
def test_delete_relationship_has_many
|
862
876
|
set_content_type_header!
|
863
|
-
put :update_association, {post_id:
|
877
|
+
put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
864
878
|
assert_response :no_content
|
865
|
-
p = Post.find(
|
879
|
+
p = Post.find(14)
|
866
880
|
assert_equal [2, 3], p.tag_ids
|
867
881
|
|
868
|
-
delete :destroy_association, {post_id:
|
882
|
+
delete :destroy_association, {post_id: 14, association: 'tags', keys: '3'}
|
869
883
|
|
870
884
|
p.reload
|
871
885
|
assert_response :no_content
|
@@ -874,18 +888,32 @@ class PostsControllerTest < ActionController::TestCase
|
|
874
888
|
|
875
889
|
def test_delete_relationship_has_many_does_not_exist
|
876
890
|
set_content_type_header!
|
877
|
-
put :update_association, {post_id:
|
891
|
+
put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
878
892
|
assert_response :no_content
|
879
|
-
p = Post.find(
|
893
|
+
p = Post.find(14)
|
880
894
|
assert_equal [2, 3], p.tag_ids
|
881
895
|
|
882
|
-
delete :destroy_association, {post_id:
|
896
|
+
delete :destroy_association, {post_id: 14, association: 'tags', keys: '4'}
|
883
897
|
|
884
898
|
p.reload
|
885
899
|
assert_response :not_found
|
886
900
|
assert_equal [2, 3], p.tag_ids
|
887
901
|
end
|
888
902
|
|
903
|
+
def test_delete_relationship_has_many_with_empty_data
|
904
|
+
set_content_type_header!
|
905
|
+
put :update_association, {post_id: 14, association: 'tags', data: [{type: 'tags', id: 2}, {type: 'tags', id: 3}]}
|
906
|
+
assert_response :no_content
|
907
|
+
p = Post.find(14)
|
908
|
+
assert_equal [2, 3], p.tag_ids
|
909
|
+
|
910
|
+
put :update_association, {post_id: 14, association: 'tags', data: [] }
|
911
|
+
|
912
|
+
p.reload
|
913
|
+
assert_response :no_content
|
914
|
+
assert_equal [], p.tag_ids
|
915
|
+
end
|
916
|
+
|
889
917
|
def test_update_mismatched_keys
|
890
918
|
set_content_type_header!
|
891
919
|
javascript = Section.find_by(name: 'javascript')
|
@@ -899,7 +927,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
899
927
|
title: 'A great new Post',
|
900
928
|
links: {
|
901
929
|
section: {type: 'sections', id: "#{javascript.id}"},
|
902
|
-
tags: {type: 'tags',
|
930
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
903
931
|
}
|
904
932
|
}
|
905
933
|
}
|
@@ -922,7 +950,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
922
950
|
title: 'A great new Post',
|
923
951
|
links: {
|
924
952
|
section: {type: 'sections', id: "#{javascript.id}"},
|
925
|
-
tags: {type: 'tags',
|
953
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
926
954
|
}
|
927
955
|
}
|
928
956
|
}
|
@@ -945,7 +973,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
945
973
|
links: {
|
946
974
|
asdfg: 'aaaa',
|
947
975
|
section: {type: 'sections', id: "#{javascript.id}"},
|
948
|
-
tags: {type: 'tags',
|
976
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
949
977
|
}
|
950
978
|
}
|
951
979
|
}
|
@@ -966,7 +994,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
966
994
|
title: 'A great new Post',
|
967
995
|
links: {
|
968
996
|
section: {type: 'sections', id: "#{javascript.id}"},
|
969
|
-
tags: {type: 'tags',
|
997
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
970
998
|
}
|
971
999
|
}
|
972
1000
|
}
|
@@ -1004,7 +1032,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1004
1032
|
title: 'A great new Post',
|
1005
1033
|
links: {
|
1006
1034
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1007
|
-
tags: {type: 'tags',
|
1035
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1008
1036
|
}
|
1009
1037
|
}
|
1010
1038
|
}
|
@@ -1019,7 +1047,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1019
1047
|
|
1020
1048
|
put :update,
|
1021
1049
|
{
|
1022
|
-
id: [3,
|
1050
|
+
id: [3, 16],
|
1023
1051
|
data: [
|
1024
1052
|
{
|
1025
1053
|
type: 'posts',
|
@@ -1027,16 +1055,16 @@ class PostsControllerTest < ActionController::TestCase
|
|
1027
1055
|
title: 'A great new Post QWERTY',
|
1028
1056
|
links: {
|
1029
1057
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1030
|
-
tags: {type: 'tags',
|
1058
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1031
1059
|
}
|
1032
1060
|
},
|
1033
1061
|
{
|
1034
1062
|
type: 'posts',
|
1035
|
-
id:
|
1063
|
+
id: 16,
|
1036
1064
|
title: 'A great new Post ASDFG',
|
1037
1065
|
links: {
|
1038
1066
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1039
|
-
tags: {type: 'tags',
|
1067
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1040
1068
|
}
|
1041
1069
|
}
|
1042
1070
|
],
|
@@ -1045,17 +1073,19 @@ class PostsControllerTest < ActionController::TestCase
|
|
1045
1073
|
|
1046
1074
|
assert_response :success
|
1047
1075
|
assert_equal json_response['data'].size, 2
|
1048
|
-
assert_equal json_response['data'][0]['links']['author']['id'], '3'
|
1049
|
-
assert_equal json_response['data'][0]['links']['section']['id'], javascript.id.to_s
|
1076
|
+
assert_equal json_response['data'][0]['links']['author']['linkage']['id'], '3'
|
1077
|
+
assert_equal json_response['data'][0]['links']['section']['linkage']['id'], javascript.id.to_s
|
1050
1078
|
assert_equal json_response['data'][0]['title'], 'A great new Post QWERTY'
|
1051
1079
|
assert_equal json_response['data'][0]['body'], 'AAAA'
|
1052
|
-
|
1080
|
+
assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
|
1081
|
+
json_response['data'][0]['links']['tags']['linkage'])
|
1053
1082
|
|
1054
|
-
assert_equal json_response['data'][1]['links']['author']['id'], '3'
|
1055
|
-
assert_equal json_response['data'][1]['links']['section']['id'], javascript.id.to_s
|
1083
|
+
assert_equal json_response['data'][1]['links']['author']['linkage']['id'], '3'
|
1084
|
+
assert_equal json_response['data'][1]['links']['section']['linkage']['id'], javascript.id.to_s
|
1056
1085
|
assert_equal json_response['data'][1]['title'], 'A great new Post ASDFG'
|
1057
|
-
assert_equal json_response['data'][1]['body'], '
|
1058
|
-
|
1086
|
+
assert_equal json_response['data'][1]['body'], 'Not First!!!!'
|
1087
|
+
assert matches_array?([{'type' => 'tags', 'id' => '3'}, {'type' => 'tags', 'id' => '4'}],
|
1088
|
+
json_response['data'][1]['links']['tags']['linkage'])
|
1059
1089
|
end
|
1060
1090
|
|
1061
1091
|
def test_update_multiple_missing_keys
|
@@ -1071,7 +1101,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1071
1101
|
title: 'A great new Post ASDFG',
|
1072
1102
|
links: {
|
1073
1103
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1074
|
-
tags: {type: 'tags',
|
1104
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1075
1105
|
}
|
1076
1106
|
},
|
1077
1107
|
{
|
@@ -1079,7 +1109,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1079
1109
|
title: 'A great new Post QWERTY',
|
1080
1110
|
links: {
|
1081
1111
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1082
|
-
tags: {type: 'tags',
|
1112
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1083
1113
|
}
|
1084
1114
|
}
|
1085
1115
|
]}
|
@@ -1102,7 +1132,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1102
1132
|
title: 'A great new Post ASDFG',
|
1103
1133
|
links: {
|
1104
1134
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1105
|
-
tags: {type: 'tags',
|
1135
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1106
1136
|
}
|
1107
1137
|
},
|
1108
1138
|
{
|
@@ -1111,7 +1141,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1111
1141
|
title: 'A great new Post QWERTY',
|
1112
1142
|
links: {
|
1113
1143
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1114
|
-
tags: {type: 'tags',
|
1144
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1115
1145
|
}
|
1116
1146
|
}
|
1117
1147
|
]}
|
@@ -1134,7 +1164,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1134
1164
|
title: 'A great new Post QWERTY',
|
1135
1165
|
links: {
|
1136
1166
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1137
|
-
tags: {type: 'tags',
|
1167
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1138
1168
|
}
|
1139
1169
|
},
|
1140
1170
|
{
|
@@ -1143,7 +1173,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1143
1173
|
title: 'A great new Post ASDFG',
|
1144
1174
|
links: {
|
1145
1175
|
section: {type: 'sections', id: "#{javascript.id}"},
|
1146
|
-
tags: {type: 'tags',
|
1176
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1147
1177
|
}
|
1148
1178
|
}
|
1149
1179
|
]}
|
@@ -1163,7 +1193,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1163
1193
|
subject: 'A great new Post',
|
1164
1194
|
links: {
|
1165
1195
|
author: {type: 'people', id: '1'},
|
1166
|
-
tags: {type: 'tags',
|
1196
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1167
1197
|
}
|
1168
1198
|
}
|
1169
1199
|
}
|
@@ -1183,7 +1213,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
1183
1213
|
subject: 'A great new Post',
|
1184
1214
|
linked_objects: {
|
1185
1215
|
author: {type: 'people', id: '1'},
|
1186
|
-
tags: {type: 'tags',
|
1216
|
+
tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
|
1187
1217
|
}
|
1188
1218
|
}
|
1189
1219
|
}
|
@@ -1224,26 +1254,36 @@ class PostsControllerTest < ActionController::TestCase
|
|
1224
1254
|
assert_response :success
|
1225
1255
|
assert_hash_equals json_response,
|
1226
1256
|
{data: {
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1257
|
+
type: 'people',
|
1258
|
+
id: '1'
|
1259
|
+
},
|
1260
|
+
links: {
|
1261
|
+
self: 'http://test.host/posts/1/links/author',
|
1262
|
+
related: 'http://test.host/posts/1/author'
|
1263
|
+
}
|
1232
1264
|
}
|
1233
1265
|
end
|
1234
1266
|
|
1235
1267
|
def test_show_has_many_relationship
|
1236
|
-
get :show_association, {post_id: '
|
1268
|
+
get :show_association, {post_id: '2', association: 'tags'}
|
1237
1269
|
assert_response :success
|
1238
1270
|
assert_hash_equals json_response,
|
1239
|
-
{
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1271
|
+
{
|
1272
|
+
data: [
|
1273
|
+
{type: 'tags', id: '5'}
|
1274
|
+
],
|
1275
|
+
links: {
|
1276
|
+
self: 'http://test.host/posts/2/links/tags',
|
1277
|
+
related: 'http://test.host/posts/2/tags'
|
1244
1278
|
}
|
1245
1279
|
}
|
1246
1280
|
end
|
1281
|
+
|
1282
|
+
def test_show_has_many_relationship_invalid_id
|
1283
|
+
get :show_association, {post_id: '2,1', association: 'tags'}
|
1284
|
+
assert_response :bad_request
|
1285
|
+
assert_match /2,1 is not a valid value for id/, response.body
|
1286
|
+
end
|
1247
1287
|
end
|
1248
1288
|
|
1249
1289
|
class TagsControllerTest < ActionController::TestCase
|
@@ -1251,33 +1291,36 @@ class TagsControllerTest < ActionController::TestCase
|
|
1251
1291
|
get :index, {filter: {id: '6,7,8,9'}, include: 'posts,posts.tags,posts.author.posts'}
|
1252
1292
|
assert_response :success
|
1253
1293
|
assert_equal 4, json_response['data'].size
|
1254
|
-
assert_equal 2, json_response['
|
1294
|
+
assert_equal 2, json_response['included'].size
|
1255
1295
|
end
|
1256
1296
|
|
1257
1297
|
def test_tags_show_multiple
|
1258
1298
|
get :show, {id: '6,7,8,9'}
|
1259
|
-
assert_response :
|
1260
|
-
|
1261
|
-
assert_equal 4, json_response['data'].size
|
1299
|
+
assert_response :bad_request
|
1300
|
+
assert_match /6,7,8,9 is not a valid value for id/, response.body
|
1262
1301
|
end
|
1263
1302
|
|
1264
1303
|
def test_tags_show_multiple_with_include
|
1265
1304
|
get :show, {id: '6,7,8,9', include: 'posts,posts.tags,posts.author.posts'}
|
1266
|
-
assert_response :
|
1267
|
-
|
1268
|
-
assert_equal 4, json_response['data'].size
|
1269
|
-
assert_equal 2, json_response['linked'].size
|
1305
|
+
assert_response :bad_request
|
1306
|
+
assert_match /6,7,8,9 is not a valid value for id/, response.body
|
1270
1307
|
end
|
1271
1308
|
|
1272
1309
|
def test_tags_show_multiple_with_nonexistent_ids
|
1273
1310
|
get :show, {id: '6,99,9,100'}
|
1274
|
-
assert_response :
|
1275
|
-
assert_match /
|
1311
|
+
assert_response :bad_request
|
1312
|
+
assert_match /6,99,9,100 is not a valid value for id/, response.body
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
def test_tags_show_multiple_with_nonexistent_ids_at_the_beginning
|
1316
|
+
get :show, {id: '99,9,100'}
|
1317
|
+
assert_response :bad_request
|
1318
|
+
assert_match /99,9,100 is not a valid value for id/, response.body
|
1276
1319
|
end
|
1277
1320
|
end
|
1278
1321
|
|
1279
1322
|
class ExpenseEntriesControllerTest < ActionController::TestCase
|
1280
|
-
def
|
1323
|
+
def setup
|
1281
1324
|
JSONAPI.configuration.json_key_format = :camelized_key
|
1282
1325
|
end
|
1283
1326
|
|
@@ -1298,7 +1341,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1298
1341
|
get :show, {id: 1, include: 'isoCurrency,employee'}
|
1299
1342
|
assert_response :success
|
1300
1343
|
assert json_response['data'].is_a?(Hash)
|
1301
|
-
assert_equal 2, json_response['
|
1344
|
+
assert_equal 2, json_response['included'].size
|
1302
1345
|
end
|
1303
1346
|
|
1304
1347
|
def test_expense_entries_show_bad_include_missing_association
|
@@ -1315,18 +1358,11 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1315
1358
|
end
|
1316
1359
|
|
1317
1360
|
def test_expense_entries_show_fields
|
1318
|
-
get :show, {id: 1, include: 'isoCurrency,employee', 'fields' => 'transactionDate'}
|
1319
|
-
assert_response :success
|
1320
|
-
assert json_response['data'].is_a?(Hash)
|
1321
|
-
assert json_response['data'].has_key?('transactionDate')
|
1322
|
-
end
|
1323
|
-
|
1324
|
-
def test_expense_entries_show_fields_type
|
1325
1361
|
get :show, {id: 1, include: 'isoCurrency,employee', 'fields' => {'expenseEntries' => 'transactionDate'}}
|
1326
1362
|
assert_response :success
|
1327
1363
|
assert json_response['data'].is_a?(Hash)
|
1328
1364
|
assert json_response['data'].has_key?('transactionDate')
|
1329
|
-
assert_equal 2, json_response['
|
1365
|
+
assert_equal 2, json_response['included'].size
|
1330
1366
|
end
|
1331
1367
|
|
1332
1368
|
def test_expense_entries_show_fields_type_many
|
@@ -1335,7 +1371,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1335
1371
|
assert_response :success
|
1336
1372
|
assert json_response['data'].is_a?(Hash)
|
1337
1373
|
assert json_response['data'].has_key?('transactionDate')
|
1338
|
-
assert_equal 2, json_response['
|
1374
|
+
assert_equal 2, json_response['included'].size
|
1339
1375
|
end
|
1340
1376
|
|
1341
1377
|
def test_create_expense_entries_underscored
|
@@ -1354,14 +1390,14 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1354
1390
|
}
|
1355
1391
|
},
|
1356
1392
|
include: 'iso_currency',
|
1357
|
-
fields: 'id,transaction_date,iso_currency,cost,employee'
|
1393
|
+
fields: {expense_entries: 'id,transaction_date,iso_currency,cost,employee'}
|
1358
1394
|
}
|
1359
1395
|
|
1360
1396
|
assert_response :created
|
1361
1397
|
assert json_response['data'].is_a?(Hash)
|
1362
|
-
assert_equal '3', json_response['data']['links']['employee']['id']
|
1363
|
-
assert_equal 'USD', json_response['data']['links']['iso_currency']['id']
|
1364
|
-
assert_equal 50.58, json_response['data']['cost']
|
1398
|
+
assert_equal '3', json_response['data']['links']['employee']['linkage']['id']
|
1399
|
+
assert_equal 'USD', json_response['data']['links']['iso_currency']['linkage']['id']
|
1400
|
+
assert_equal '50.58', json_response['data']['cost']
|
1365
1401
|
|
1366
1402
|
delete :destroy, {id: json_response['data']['id']}
|
1367
1403
|
assert_response :no_content
|
@@ -1383,14 +1419,14 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1383
1419
|
}
|
1384
1420
|
},
|
1385
1421
|
include: 'isoCurrency',
|
1386
|
-
fields: 'id,transactionDate,isoCurrency,cost,employee'
|
1422
|
+
fields: {expenseEntries: 'id,transactionDate,isoCurrency,cost,employee'}
|
1387
1423
|
}
|
1388
1424
|
|
1389
1425
|
assert_response :created
|
1390
1426
|
assert json_response['data'].is_a?(Hash)
|
1391
|
-
assert_equal '3', json_response['data']['links']['employee']['id']
|
1392
|
-
assert_equal 'USD', json_response['data']['links']['isoCurrency']['id']
|
1393
|
-
assert_equal 50.58, json_response['data']['cost']
|
1427
|
+
assert_equal '3', json_response['data']['links']['employee']['linkage']['id']
|
1428
|
+
assert_equal 'USD', json_response['data']['links']['isoCurrency']['linkage']['id']
|
1429
|
+
assert_equal '50.58', json_response['data']['cost']
|
1394
1430
|
|
1395
1431
|
delete :destroy, {id: json_response['data']['id']}
|
1396
1432
|
assert_response :no_content
|
@@ -1412,14 +1448,14 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1412
1448
|
}
|
1413
1449
|
},
|
1414
1450
|
include: 'iso-currency',
|
1415
|
-
fields: 'id,transaction-date,iso-currency,cost,employee'
|
1451
|
+
fields: {'expense-entries' => 'id,transaction-date,iso-currency,cost,employee'}
|
1416
1452
|
}
|
1417
1453
|
|
1418
1454
|
assert_response :created
|
1419
1455
|
assert json_response['data'].is_a?(Hash)
|
1420
|
-
assert_equal '3', json_response['data']['links']['employee']['id']
|
1421
|
-
assert_equal 'USD', json_response['data']['links']['iso-currency']['id']
|
1422
|
-
assert_equal 50.58, json_response['data']['cost']
|
1456
|
+
assert_equal '3', json_response['data']['links']['employee']['linkage']['id']
|
1457
|
+
assert_equal 'USD', json_response['data']['links']['iso-currency']['linkage']['id']
|
1458
|
+
assert_equal '50.58', json_response['data']['cost']
|
1423
1459
|
|
1424
1460
|
delete :destroy, {id: json_response['data']['id']}
|
1425
1461
|
assert_response :no_content
|
@@ -1517,6 +1553,10 @@ class IsoCurrenciesControllerTest < ActionController::TestCase
|
|
1517
1553
|
end
|
1518
1554
|
|
1519
1555
|
class PeopleControllerTest < ActionController::TestCase
|
1556
|
+
def setup
|
1557
|
+
JSONAPI.configuration.json_key_format = :camelized_key
|
1558
|
+
end
|
1559
|
+
|
1520
1560
|
def test_create_validations
|
1521
1561
|
set_content_type_header!
|
1522
1562
|
post :create,
|
@@ -1589,7 +1629,7 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1589
1629
|
end
|
1590
1630
|
end
|
1591
1631
|
|
1592
|
-
class AuthorsControllerTest < ActionController::TestCase
|
1632
|
+
class Api::V5::AuthorsControllerTest < ActionController::TestCase
|
1593
1633
|
def test_get_person_as_author
|
1594
1634
|
get :index, {filter: {id: '1'}}
|
1595
1635
|
assert_response :success
|
@@ -1629,13 +1669,9 @@ class BreedsControllerTest < ActionController::TestCase
|
|
1629
1669
|
|
1630
1670
|
def test_poro_show_multiple
|
1631
1671
|
get :show, {id: '0,2'}
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
assert_equal '0', json_response['data'][0]['id']
|
1636
|
-
assert_equal 'Persian', json_response['data'][0]['name']
|
1637
|
-
assert_equal '2', json_response['data'][1]['id']
|
1638
|
-
assert_equal 'Sphinx', json_response['data'][1]['name']
|
1672
|
+
|
1673
|
+
assert_response :bad_request
|
1674
|
+
assert_match /0,2 is not a valid value for id/, response.body
|
1639
1675
|
end
|
1640
1676
|
|
1641
1677
|
def test_poro_create_simple
|
@@ -1707,11 +1743,11 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
|
|
1707
1743
|
def test_show_post_namespaced_include
|
1708
1744
|
get :show, {id: '1', include: 'writer'}
|
1709
1745
|
assert_response :success
|
1710
|
-
assert_equal '1', json_response['data']['links']['writer']['id']
|
1746
|
+
assert_equal '1', json_response['data']['links']['writer']['linkage']['id']
|
1711
1747
|
assert_nil json_response['data']['links']['tags']
|
1712
|
-
assert_equal '1', json_response['
|
1713
|
-
assert_equal 'writers', json_response['
|
1714
|
-
assert_equal 'joe@xyz.fake', json_response['
|
1748
|
+
assert_equal '1', json_response['included'][0]['id']
|
1749
|
+
assert_equal 'writers', json_response['included'][0]['type']
|
1750
|
+
assert_equal 'joe@xyz.fake', json_response['included'][0]['email']
|
1715
1751
|
end
|
1716
1752
|
|
1717
1753
|
def test_index_filter_on_association_namespaced
|
@@ -1743,7 +1779,7 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
|
|
1743
1779
|
|
1744
1780
|
assert_response :created
|
1745
1781
|
assert json_response['data'].is_a?(Hash)
|
1746
|
-
assert_equal '3', json_response['data']['links']['writer']['id']
|
1782
|
+
assert_equal '3', json_response['data']['links']['writer']['linkage']['id']
|
1747
1783
|
assert_equal 'JR - now with Namespacing', json_response['data']['title']
|
1748
1784
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread now that it has namespaced resources.',
|
1749
1785
|
json_response['data']['body']
|
@@ -1752,6 +1788,10 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
|
|
1752
1788
|
end
|
1753
1789
|
|
1754
1790
|
class FactsControllerTest < ActionController::TestCase
|
1791
|
+
def setup
|
1792
|
+
JSONAPI.configuration.json_key_format = :camelized_key
|
1793
|
+
end
|
1794
|
+
|
1755
1795
|
def test_type_formatting
|
1756
1796
|
get :show, {id: '1'}
|
1757
1797
|
assert_response :success
|
@@ -1759,8 +1799,8 @@ class FactsControllerTest < ActionController::TestCase
|
|
1759
1799
|
assert_equal 'Jane Author', json_response['data']['spouseName']
|
1760
1800
|
assert_equal 'First man to run across Antartica.', json_response['data']['bio']
|
1761
1801
|
assert_equal 23.89/45.6, json_response['data']['qualityRating']
|
1762
|
-
assert_equal 47000.56, json_response['data']['salary']
|
1763
|
-
assert_equal '2013-08-07T20:25:
|
1802
|
+
assert_equal '47000.56', json_response['data']['salary']
|
1803
|
+
assert_equal '2013-08-07T20:25:00Z', json_response['data']['dateTimeJoined']
|
1764
1804
|
assert_equal '1965-06-30', json_response['data']['birthday']
|
1765
1805
|
assert_equal '2000-01-01T20:00:00Z', json_response['data']['bedtime']
|
1766
1806
|
assert_equal 'abc', json_response['data']['photo']
|