jsonapi-resources 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +1 -3
- data/README.md +118 -23
- data/lib/jsonapi/formatter.rb +10 -1
- data/lib/jsonapi/request.rb +6 -6
- data/lib/jsonapi/resource.rb +8 -4
- data/lib/jsonapi/resource_controller.rb +1 -1
- data/lib/jsonapi/resource_for.rb +1 -1
- data/lib/jsonapi/resource_serializer.rb +22 -5
- data/lib/jsonapi/resources/version.rb +1 -1
- data/test/controllers/controller_test.rb +95 -43
- data/test/fixtures/active_record.rb +49 -5
- data/test/unit/serializer/serializer_test.rb +129 -110
- metadata +2 -2
@@ -182,7 +182,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
182
182
|
get :index, {sort: 'title,body'}
|
183
183
|
|
184
184
|
assert_response :success
|
185
|
-
assert_equal 8, json_response['posts'][0]['id']
|
185
|
+
assert_equal '8', json_response['posts'][0]['id']
|
186
186
|
end
|
187
187
|
|
188
188
|
def test_invalid_sort_param
|
@@ -211,8 +211,8 @@ class PostsControllerTest < ActionController::TestCase
|
|
211
211
|
assert json_response['posts'].is_a?(Hash)
|
212
212
|
assert_equal 'New post', json_response['posts']['title']
|
213
213
|
assert_equal 'A body!!!', json_response['posts']['body']
|
214
|
-
assert_equal [1, 2, 3], json_response['posts']['links']['tags']
|
215
|
-
assert_equal [1, 2], json_response['posts']['links']['comments']
|
214
|
+
assert_equal ['1', '2', '3'], json_response['posts']['links']['tags']
|
215
|
+
assert_equal ['1', '2'], json_response['posts']['links']['comments']
|
216
216
|
assert_nil json_response['linked']
|
217
217
|
end
|
218
218
|
|
@@ -222,8 +222,8 @@ class PostsControllerTest < ActionController::TestCase
|
|
222
222
|
assert json_response['posts'].is_a?(Hash)
|
223
223
|
assert_equal 'New post', json_response['posts']['title']
|
224
224
|
assert_equal 'A body!!!', json_response['posts']['body']
|
225
|
-
assert_equal [1, 2, 3], json_response['posts']['links']['tags']
|
226
|
-
assert_equal [1, 2], json_response['posts']['links']['comments']
|
225
|
+
assert_equal ['1', '2', '3'], json_response['posts']['links']['tags']
|
226
|
+
assert_equal ['1', '2'], json_response['posts']['links']['comments']
|
227
227
|
assert_equal 2, json_response['linked']['comments'].size
|
228
228
|
assert_nil json_response['linked']['tags']
|
229
229
|
end
|
@@ -234,7 +234,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
234
234
|
assert json_response['posts'].is_a?(Hash)
|
235
235
|
assert_nil json_response['posts']['title']
|
236
236
|
assert_nil json_response['posts']['body']
|
237
|
-
assert_equal 1, json_response['posts']['links']['author']
|
237
|
+
assert_equal '1', json_response['posts']['links']['author']
|
238
238
|
end
|
239
239
|
|
240
240
|
def test_show_single_invalid_id_format
|
@@ -275,7 +275,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
275
275
|
|
276
276
|
assert_response :created
|
277
277
|
assert json_response['posts'].is_a?(Hash)
|
278
|
-
assert_equal 3, json_response['posts']['links']['author']
|
278
|
+
assert_equal '3', json_response['posts']['links']['author']
|
279
279
|
assert_equal 'JR is Great', json_response['posts']['title']
|
280
280
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['posts']['body']
|
281
281
|
end
|
@@ -361,7 +361,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
361
361
|
assert_response :created
|
362
362
|
assert json_response['posts'].is_a?(Array)
|
363
363
|
assert_equal json_response['posts'].size, 2
|
364
|
-
assert_equal json_response['posts'][0]['links']['author'], 3
|
364
|
+
assert_equal json_response['posts'][0]['links']['author'], '3'
|
365
365
|
assert_match /JR is Great/, response.body
|
366
366
|
assert_match /Ember is Great/, response.body
|
367
367
|
end
|
@@ -438,10 +438,10 @@ class PostsControllerTest < ActionController::TestCase
|
|
438
438
|
|
439
439
|
assert_response :created
|
440
440
|
assert json_response['posts'].is_a?(Hash)
|
441
|
-
assert_equal 3, json_response['posts']['links']['author']
|
441
|
+
assert_equal '3', json_response['posts']['links']['author']
|
442
442
|
assert_equal 'JR is Great', json_response['posts']['title']
|
443
443
|
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.', json_response['posts']['body']
|
444
|
-
assert_equal [3, 4], json_response['posts']['links']['tags']
|
444
|
+
assert_equal ['3', '4'], json_response['posts']['links']['tags']
|
445
445
|
end
|
446
446
|
|
447
447
|
def test_create_with_links_include_and_fields
|
@@ -461,7 +461,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
461
461
|
|
462
462
|
assert_response :created
|
463
463
|
assert json_response['posts'].is_a?(Hash)
|
464
|
-
assert_equal 3, json_response['posts']['links']['author']
|
464
|
+
assert_equal '3', json_response['posts']['links']['author']
|
465
465
|
assert_equal 'JR is Great!', json_response['posts']['title']
|
466
466
|
assert_equal nil, json_response['posts']['body']
|
467
467
|
assert_equal nil, json_response['posts']['links']['tags']
|
@@ -487,11 +487,11 @@ class PostsControllerTest < ActionController::TestCase
|
|
487
487
|
|
488
488
|
assert_response :success
|
489
489
|
assert json_response['posts'].is_a?(Hash)
|
490
|
-
assert_equal 3, json_response['posts']['links']['author']
|
491
|
-
assert_equal javascript.id, json_response['posts']['links']['section']
|
490
|
+
assert_equal '3', json_response['posts']['links']['author']
|
491
|
+
assert_equal javascript.id.to_s, json_response['posts']['links']['section']
|
492
492
|
assert_equal 'A great new Post', json_response['posts']['title']
|
493
493
|
assert_equal 'AAAA', json_response['posts']['body']
|
494
|
-
assert matches_array?([3, 4], json_response['posts']['links']['tags'])
|
494
|
+
assert matches_array?(['3', '4'], json_response['posts']['links']['tags'])
|
495
495
|
end
|
496
496
|
|
497
497
|
def test_update_remove_links
|
@@ -509,7 +509,7 @@ class PostsControllerTest < ActionController::TestCase
|
|
509
509
|
|
510
510
|
assert_response :success
|
511
511
|
assert json_response['posts'].is_a?(Hash)
|
512
|
-
assert_equal 3, json_response['posts']['links']['author']
|
512
|
+
assert_equal '3', json_response['posts']['links']['author']
|
513
513
|
assert_equal nil, json_response['posts']['links']['section']
|
514
514
|
assert_equal 'A great new Post', json_response['posts']['title']
|
515
515
|
assert_equal 'AAAA', json_response['posts']['body']
|
@@ -806,17 +806,17 @@ class PostsControllerTest < ActionController::TestCase
|
|
806
806
|
|
807
807
|
assert_response :success
|
808
808
|
assert_equal json_response['posts'].size, 2
|
809
|
-
assert_equal json_response['posts'][0]['links']['author'], 3
|
810
|
-
assert_equal json_response['posts'][0]['links']['section'], javascript.id
|
809
|
+
assert_equal json_response['posts'][0]['links']['author'], '3'
|
810
|
+
assert_equal json_response['posts'][0]['links']['section'], javascript.id.to_s
|
811
811
|
assert_equal json_response['posts'][0]['title'], 'A great new Post QWERTY'
|
812
812
|
assert_equal json_response['posts'][0]['body'], 'AAAA'
|
813
|
-
assert_equal json_response['posts'][0]['links']['tags'], [3, 4]
|
813
|
+
assert_equal json_response['posts'][0]['links']['tags'], ['3', '4']
|
814
814
|
|
815
|
-
assert_equal json_response['posts'][1]['links']['author'], 3
|
816
|
-
assert_equal json_response['posts'][1]['links']['section'], javascript.id
|
815
|
+
assert_equal json_response['posts'][1]['links']['author'], '3'
|
816
|
+
assert_equal json_response['posts'][1]['links']['section'], javascript.id.to_s
|
817
817
|
assert_equal json_response['posts'][1]['title'], 'A great new Post ASDFG'
|
818
818
|
assert_equal json_response['posts'][1]['body'], 'AAAA'
|
819
|
-
assert_equal json_response['posts'][1]['links']['tags'], [3, 4]
|
819
|
+
assert_equal json_response['posts'][1]['links']['tags'], ['3', '4']
|
820
820
|
end
|
821
821
|
|
822
822
|
def test_update_multiple_missing_keys
|
@@ -1104,7 +1104,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1104
1104
|
|
1105
1105
|
assert_response :created
|
1106
1106
|
assert json_response['expense_entries'].is_a?(Hash)
|
1107
|
-
assert_equal 3, json_response['expense_entries']['links']['employee']
|
1107
|
+
assert_equal '3', json_response['expense_entries']['links']['employee']
|
1108
1108
|
assert_equal 'USD', json_response['expense_entries']['links']['iso_currency']
|
1109
1109
|
assert_equal 50.58, json_response['expense_entries']['cost']
|
1110
1110
|
|
@@ -1131,7 +1131,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1131
1131
|
|
1132
1132
|
assert_response :created
|
1133
1133
|
assert json_response['expenseEntries'].is_a?(Hash)
|
1134
|
-
assert_equal 3, json_response['expenseEntries']['links']['employee']
|
1134
|
+
assert_equal '3', json_response['expenseEntries']['links']['employee']
|
1135
1135
|
assert_equal 'USD', json_response['expenseEntries']['links']['isoCurrency']
|
1136
1136
|
assert_equal 50.58, json_response['expenseEntries']['cost']
|
1137
1137
|
|
@@ -1158,7 +1158,7 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
|
|
1158
1158
|
|
1159
1159
|
assert_response :created
|
1160
1160
|
assert json_response['expense-entries'].is_a?(Hash)
|
1161
|
-
assert_equal 3, json_response['expense-entries']['links']['employee']
|
1161
|
+
assert_equal '3', json_response['expense-entries']['links']['employee']
|
1162
1162
|
assert_equal 'USD', json_response['expense-entries']['links']['iso-currency']
|
1163
1163
|
assert_equal 50.58, json_response['expense-entries']['cost']
|
1164
1164
|
|
@@ -1346,7 +1346,7 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1346
1346
|
get :index, {name: 'Joe Author'}
|
1347
1347
|
assert_response :success
|
1348
1348
|
assert_equal json_response['people'].size, 1
|
1349
|
-
assert_equal json_response['people'][0]['id'], 1
|
1349
|
+
assert_equal json_response['people'][0]['id'], '1'
|
1350
1350
|
assert_equal json_response['people'][0]['name'], 'Joe Author'
|
1351
1351
|
end
|
1352
1352
|
end
|
@@ -1356,29 +1356,18 @@ class AuthorsControllerTest < ActionController::TestCase
|
|
1356
1356
|
get :index, {id: '1'}
|
1357
1357
|
assert_response :success
|
1358
1358
|
assert_equal 1, json_response['authors'].size
|
1359
|
-
assert_equal 1, json_response['authors'][0]['id']
|
1359
|
+
assert_equal '1', json_response['authors'][0]['id']
|
1360
1360
|
assert_equal 'Joe Author', json_response['authors'][0]['name']
|
1361
1361
|
assert_equal nil, json_response['authors'][0]['email']
|
1362
1362
|
assert_equal 1, json_response['authors'][0]['links'].size
|
1363
1363
|
assert_equal 3, json_response['authors'][0]['links']['posts'].size
|
1364
1364
|
end
|
1365
1365
|
|
1366
|
-
def test_get_person_as_author_variable_email
|
1367
|
-
get :index, {id: '4'}
|
1368
|
-
assert_response :success
|
1369
|
-
assert_equal 1, json_response['authors'].size
|
1370
|
-
assert_equal 4, json_response['authors'][0]['id']
|
1371
|
-
assert_equal 'Tag Crazy Author', json_response['authors'][0]['name']
|
1372
|
-
assert_equal 'taggy@xyz.fake', json_response['authors'][0]['email']
|
1373
|
-
assert_equal 1, json_response['authors'][0]['links'].size
|
1374
|
-
assert_equal 2, json_response['authors'][0]['links']['posts'].size
|
1375
|
-
end
|
1376
|
-
|
1377
1366
|
def test_get_person_as_author_by_name_filter
|
1378
1367
|
get :index, {name: 'thor'}
|
1379
1368
|
assert_response :success
|
1380
1369
|
assert_equal 3, json_response['authors'].size
|
1381
|
-
assert_equal 1, json_response['authors'][0]['id']
|
1370
|
+
assert_equal '1', json_response['authors'][0]['id']
|
1382
1371
|
assert_equal 'Joe Author', json_response['authors'][0]['name']
|
1383
1372
|
assert_equal 1, json_response['authors'][0]['links'].size
|
1384
1373
|
assert_equal 3, json_response['authors'][0]['links']['posts'].size
|
@@ -1391,7 +1380,7 @@ class BreedsControllerTest < ActionController::TestCase
|
|
1391
1380
|
def test_poro_index
|
1392
1381
|
get :index
|
1393
1382
|
assert_response :success
|
1394
|
-
assert_equal 0, json_response['breeds'][0]['id']
|
1383
|
+
assert_equal '0', json_response['breeds'][0]['id']
|
1395
1384
|
assert_equal 'Persian', json_response['breeds'][0]['name']
|
1396
1385
|
end
|
1397
1386
|
|
@@ -1399,7 +1388,7 @@ class BreedsControllerTest < ActionController::TestCase
|
|
1399
1388
|
get :show, {id: '0'}
|
1400
1389
|
assert_response :success
|
1401
1390
|
assert json_response['breeds'].is_a?(Hash)
|
1402
|
-
assert_equal 0, json_response['breeds']['id']
|
1391
|
+
assert_equal '0', json_response['breeds']['id']
|
1403
1392
|
assert_equal 'Persian', json_response['breeds']['name']
|
1404
1393
|
end
|
1405
1394
|
|
@@ -1408,9 +1397,9 @@ class BreedsControllerTest < ActionController::TestCase
|
|
1408
1397
|
assert_response :success
|
1409
1398
|
assert json_response['breeds'].is_a?(Array)
|
1410
1399
|
assert_equal 2, json_response['breeds'].size
|
1411
|
-
assert_equal 0, json_response['breeds'][0]['id']
|
1400
|
+
assert_equal '0', json_response['breeds'][0]['id']
|
1412
1401
|
assert_equal 'Persian', json_response['breeds'][0]['name']
|
1413
|
-
assert_equal 2, json_response['breeds'][1]['id']
|
1402
|
+
assert_equal '2', json_response['breeds'][1]['id']
|
1414
1403
|
assert_equal 'Sphinx', json_response['breeds'][1]['name']
|
1415
1404
|
end
|
1416
1405
|
|
@@ -1467,6 +1456,70 @@ class Api::V2::PreferencesControllerTest < ActionController::TestCase
|
|
1467
1456
|
end
|
1468
1457
|
end
|
1469
1458
|
|
1459
|
+
class Api::V1::PostsControllerTest < ActionController::TestCase
|
1460
|
+
def test_show_post_namespaced
|
1461
|
+
get :show, {id: '1'}
|
1462
|
+
assert_response :success
|
1463
|
+
assert_hash_equals(
|
1464
|
+
{
|
1465
|
+
posts: {
|
1466
|
+
id: '1',
|
1467
|
+
title: 'New post',
|
1468
|
+
body: 'A body!!!',
|
1469
|
+
subject: 'New post',
|
1470
|
+
links: {
|
1471
|
+
section: nil,
|
1472
|
+
writer: '1',
|
1473
|
+
comments: ['1', '2']
|
1474
|
+
}
|
1475
|
+
}
|
1476
|
+
}, json_response
|
1477
|
+
)
|
1478
|
+
end
|
1479
|
+
|
1480
|
+
def test_show_post_namespaced_include
|
1481
|
+
get :show, {id: '1', include: 'writer'}
|
1482
|
+
assert_response :success
|
1483
|
+
assert_equal '1', json_response['posts']['links']['writer']
|
1484
|
+
assert_nil json_response['posts']['links']['tags']
|
1485
|
+
assert_equal '1', json_response['linked']['writers'][0]['id']
|
1486
|
+
assert_equal 'joe@xyz.fake', json_response['linked']['writers'][0]['email']
|
1487
|
+
end
|
1488
|
+
|
1489
|
+
def test_index_filter_on_association_namespaced
|
1490
|
+
get :index, {writer: '1'}
|
1491
|
+
assert_response :success
|
1492
|
+
assert_equal 3, json_response['posts'].size
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
def test_sorting_desc_namespaced
|
1496
|
+
get :index, {sort: '-title'}
|
1497
|
+
|
1498
|
+
assert_response :success
|
1499
|
+
assert_equal "Update This Later - Multiple", json_response['posts'][0]['title']
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
def test_create_simple_namespaced
|
1503
|
+
post :create,
|
1504
|
+
{
|
1505
|
+
posts: {
|
1506
|
+
title: 'JR - now with Namespacing',
|
1507
|
+
body: 'JSONAPIResources is the greatest thing since unsliced bread now that it has namespaced resources.',
|
1508
|
+
links: {
|
1509
|
+
writer: '3'
|
1510
|
+
}
|
1511
|
+
}
|
1512
|
+
}
|
1513
|
+
|
1514
|
+
assert_response :created
|
1515
|
+
assert json_response['posts'].is_a?(Hash)
|
1516
|
+
assert_equal '3', json_response['posts']['links']['writer']
|
1517
|
+
assert_equal 'JR - now with Namespacing', json_response['posts']['title']
|
1518
|
+
assert_equal 'JSONAPIResources is the greatest thing since unsliced bread now that it has namespaced resources.', json_response['posts']['body']
|
1519
|
+
end
|
1520
|
+
|
1521
|
+
end
|
1522
|
+
|
1470
1523
|
class FactsControllerTest < ActionController::TestCase
|
1471
1524
|
def test_type_formatting
|
1472
1525
|
get :show, {id: '1'}
|
@@ -1483,4 +1536,3 @@ class FactsControllerTest < ActionController::TestCase
|
|
1483
1536
|
assert_equal false, json_response['facts']['cool']
|
1484
1537
|
end
|
1485
1538
|
end
|
1486
|
-
|
@@ -121,6 +121,7 @@ end
|
|
121
121
|
|
122
122
|
class Post < ActiveRecord::Base
|
123
123
|
belongs_to :author, class_name: 'Person', foreign_key: 'author_id'
|
124
|
+
belongs_to :writer, class_name: 'Person', foreign_key: 'author_id'
|
124
125
|
has_many :comments
|
125
126
|
has_and_belongs_to_many :tags, join_table: :posts_tags
|
126
127
|
belongs_to :section
|
@@ -373,11 +374,7 @@ class AuthorResource < JSONAPI::Resource
|
|
373
374
|
end
|
374
375
|
|
375
376
|
def fetchable_fields
|
376
|
-
|
377
|
-
super - [:email]
|
378
|
-
else
|
379
|
-
super
|
380
|
-
end
|
377
|
+
super - [:email]
|
381
378
|
end
|
382
379
|
end
|
383
380
|
|
@@ -546,6 +543,53 @@ class FactResource < JSONAPI::Resource
|
|
546
543
|
attribute :cool
|
547
544
|
end
|
548
545
|
|
546
|
+
module Api
|
547
|
+
module V1
|
548
|
+
class WriterResource < JSONAPI::Resource
|
549
|
+
attributes :id, :name, :email
|
550
|
+
model_name 'Person'
|
551
|
+
has_many :posts
|
552
|
+
|
553
|
+
filter :name
|
554
|
+
end
|
555
|
+
|
556
|
+
class PostResource < JSONAPI::Resource
|
557
|
+
# V1 no longer supports tags and now calls author 'writer'
|
558
|
+
attribute :id
|
559
|
+
attribute :title
|
560
|
+
attribute :body
|
561
|
+
attribute :subject
|
562
|
+
|
563
|
+
has_one :writer, foreign_key: 'author_id'
|
564
|
+
has_one :section
|
565
|
+
has_many :comments, acts_as_set: false
|
566
|
+
|
567
|
+
def subject
|
568
|
+
@model.title
|
569
|
+
end
|
570
|
+
|
571
|
+
filters :writer
|
572
|
+
end
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
module Api
|
577
|
+
module V2
|
578
|
+
class PreferencesResource < PreferencesResource
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
module Api
|
584
|
+
module V4
|
585
|
+
class IsoCurrencyResource < IsoCurrencyResource
|
586
|
+
end
|
587
|
+
|
588
|
+
class ExpenseEntryResource < ExpenseEntryResource
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
549
593
|
warn 'start testing Name Collisions'
|
550
594
|
# The name collisions only emmit warnings. Exceptions would change the flow of the tests
|
551
595
|
|
@@ -22,15 +22,15 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
22
22
|
assert_hash_equals(
|
23
23
|
{
|
24
24
|
posts: {
|
25
|
-
id: 1,
|
25
|
+
id: '1',
|
26
26
|
title: 'New post',
|
27
27
|
body: 'A body!!!',
|
28
28
|
subject: 'New post',
|
29
29
|
links: {
|
30
30
|
section: nil,
|
31
|
-
author: 1,
|
32
|
-
tags: [1, 2, 3],
|
33
|
-
comments: [1, 2]
|
31
|
+
author: '1',
|
32
|
+
tags: ['1', '2', '3'],
|
33
|
+
comments: ['1', '2']
|
34
34
|
}
|
35
35
|
}
|
36
36
|
},
|
@@ -38,15 +38,34 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
38
38
|
PostResource.new(@post)))
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_serializer_namespaced_resource
|
42
|
+
assert_hash_equals(
|
43
|
+
{
|
44
|
+
posts: {
|
45
|
+
id: '1',
|
46
|
+
title: 'New post',
|
47
|
+
body: 'A body!!!',
|
48
|
+
subject: 'New post',
|
49
|
+
links: {
|
50
|
+
section: nil,
|
51
|
+
writer: '1',
|
52
|
+
comments: ['1', '2']
|
53
|
+
}
|
54
|
+
}
|
55
|
+
},
|
56
|
+
JSONAPI::ResourceSerializer.new(Api::V1::PostResource).serialize_to_hash(
|
57
|
+
Api::V1::PostResource.new(@post)))
|
58
|
+
end
|
59
|
+
|
41
60
|
def test_serializer_limited_fieldset
|
42
61
|
|
43
62
|
assert_hash_equals(
|
44
63
|
{
|
45
64
|
posts: {
|
46
|
-
id: 1,
|
65
|
+
id: '1',
|
47
66
|
title: 'New post',
|
48
67
|
links: {
|
49
|
-
author: 1
|
68
|
+
author: '1'
|
50
69
|
}
|
51
70
|
}
|
52
71
|
},
|
@@ -60,26 +79,26 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
60
79
|
assert_hash_equals(
|
61
80
|
{
|
62
81
|
posts: {
|
63
|
-
id: 1,
|
82
|
+
id: '1',
|
64
83
|
title: 'New post',
|
65
84
|
body: 'A body!!!',
|
66
85
|
subject: 'New post',
|
67
86
|
links: {
|
68
|
-
author: 1,
|
69
|
-
tags: [1, 2, 3],
|
70
|
-
comments: [1, 2],
|
87
|
+
author: '1',
|
88
|
+
tags: ['1', '2', '3'],
|
89
|
+
comments: ['1', '2'],
|
71
90
|
section: nil
|
72
91
|
}
|
73
92
|
},
|
74
93
|
linked: {
|
75
94
|
people: [{
|
76
|
-
id: 1,
|
95
|
+
id: '1',
|
77
96
|
name: 'Joe Author',
|
78
97
|
email: 'joe@xyz.fake',
|
79
98
|
dateJoined: '2013-08-07 16:25:00 -0400',
|
80
99
|
links: {
|
81
|
-
comments: [1],
|
82
|
-
posts: [1, 2, 11]
|
100
|
+
comments: ['1'],
|
101
|
+
posts: ['1', '2', '11']
|
83
102
|
}
|
84
103
|
}]
|
85
104
|
}
|
@@ -93,26 +112,26 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
93
112
|
assert_hash_equals(
|
94
113
|
{
|
95
114
|
posts: {
|
96
|
-
id: 1,
|
115
|
+
id: '1',
|
97
116
|
title: 'New post',
|
98
117
|
body: 'A body!!!',
|
99
118
|
subject: 'New post',
|
100
119
|
links: {
|
101
|
-
author: 1,
|
102
|
-
tags: [1, 2, 3],
|
103
|
-
comments: [1, 2],
|
120
|
+
author: '1',
|
121
|
+
tags: ['1', '2', '3'],
|
122
|
+
comments: ['1', '2'],
|
104
123
|
section: nil
|
105
124
|
}
|
106
125
|
},
|
107
126
|
linked: {
|
108
127
|
people: [{
|
109
|
-
id: 1,
|
128
|
+
id: '1',
|
110
129
|
name: 'Joe Author',
|
111
130
|
email: 'joe@xyz.fake',
|
112
131
|
date_joined: '2013-08-07 16:25:00 -0400',
|
113
132
|
links: {
|
114
|
-
comments: [1],
|
115
|
-
posts: [1, 2, 11]
|
133
|
+
comments: ['1'],
|
134
|
+
posts: ['1', '2', '11']
|
116
135
|
}
|
117
136
|
}]
|
118
137
|
}
|
@@ -128,35 +147,35 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
128
147
|
assert_hash_equals(
|
129
148
|
{
|
130
149
|
posts: {
|
131
|
-
id: 1,
|
150
|
+
id: '1',
|
132
151
|
title: 'New post',
|
133
152
|
body: 'A body!!!',
|
134
153
|
subject: 'New post',
|
135
154
|
links: {
|
136
|
-
author: 1,
|
137
|
-
tags: [1, 2, 3],
|
138
|
-
comments: [1, 2],
|
155
|
+
author: '1',
|
156
|
+
tags: ['1', '2', '3'],
|
157
|
+
comments: ['1', '2'],
|
139
158
|
section: nil
|
140
159
|
}
|
141
160
|
},
|
142
161
|
linked: {
|
143
162
|
tags: [
|
144
163
|
{
|
145
|
-
id: 1,
|
164
|
+
id: '1',
|
146
165
|
name: 'short',
|
147
166
|
links: {
|
148
167
|
posts: :not_nil
|
149
168
|
}
|
150
169
|
},
|
151
170
|
{
|
152
|
-
id: 2,
|
171
|
+
id: '2',
|
153
172
|
name: 'whiny',
|
154
173
|
links: {
|
155
174
|
posts: :not_nil
|
156
175
|
}
|
157
176
|
},
|
158
177
|
{
|
159
|
-
id: 4,
|
178
|
+
id: '4',
|
160
179
|
name: 'happy',
|
161
180
|
links: {
|
162
181
|
posts: :not_nil
|
@@ -165,21 +184,21 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
165
184
|
],
|
166
185
|
comments: [
|
167
186
|
{
|
168
|
-
id: 1,
|
187
|
+
id: '1',
|
169
188
|
body: 'what a dumb post',
|
170
189
|
links: {
|
171
|
-
author: 1,
|
172
|
-
post: 1,
|
173
|
-
tags: [2, 1]
|
190
|
+
author: '1',
|
191
|
+
post: '1',
|
192
|
+
tags: ['2', '1']
|
174
193
|
}
|
175
194
|
},
|
176
195
|
{
|
177
|
-
id: 2,
|
196
|
+
id: '2',
|
178
197
|
body: 'i liked it',
|
179
198
|
links: {
|
180
|
-
author: 2,
|
181
|
-
post: 1,
|
182
|
-
tags: [4, 1]
|
199
|
+
author: '2',
|
200
|
+
post: '1',
|
201
|
+
tags: ['4', '1']
|
183
202
|
}
|
184
203
|
}
|
185
204
|
]
|
@@ -194,35 +213,35 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
194
213
|
assert_hash_equals(
|
195
214
|
{
|
196
215
|
posts: {
|
197
|
-
id: 1,
|
216
|
+
id: '1',
|
198
217
|
title: 'New post',
|
199
218
|
body: 'A body!!!',
|
200
219
|
subject: 'New post',
|
201
220
|
links: {
|
202
|
-
author: 1,
|
203
|
-
tags: [1, 2, 3],
|
204
|
-
comments: [1, 2],
|
221
|
+
author: '1',
|
222
|
+
tags: ['1', '2', '3'],
|
223
|
+
comments: ['1', '2'],
|
205
224
|
section: nil
|
206
225
|
}
|
207
226
|
},
|
208
227
|
linked: {
|
209
228
|
tags: [
|
210
229
|
{
|
211
|
-
id: 1,
|
230
|
+
id: '1',
|
212
231
|
name: 'short',
|
213
232
|
links: {
|
214
233
|
posts: :not_nil
|
215
234
|
}
|
216
235
|
},
|
217
236
|
{
|
218
|
-
id: 2,
|
237
|
+
id: '2',
|
219
238
|
name: 'whiny',
|
220
239
|
links: {
|
221
240
|
posts: :not_nil
|
222
241
|
}
|
223
242
|
},
|
224
243
|
{
|
225
|
-
id: 4,
|
244
|
+
id: '4',
|
226
245
|
name: 'happy',
|
227
246
|
links: {
|
228
247
|
posts: :not_nil
|
@@ -240,26 +259,26 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
240
259
|
assert_hash_equals(
|
241
260
|
{
|
242
261
|
posts: {
|
243
|
-
id: 1,
|
262
|
+
id: '1',
|
244
263
|
title: 'New post',
|
245
264
|
body: 'A body!!!',
|
246
265
|
subject: 'New post',
|
247
266
|
links: {
|
248
|
-
author: 1,
|
249
|
-
tags: [1, 2, 3],
|
250
|
-
comments: [1, 2],
|
267
|
+
author: '1',
|
268
|
+
tags: ['1', '2', '3'],
|
269
|
+
comments: ['1', '2'],
|
251
270
|
section: nil
|
252
271
|
}
|
253
272
|
},
|
254
273
|
linked: {
|
255
274
|
comments: [
|
256
275
|
{
|
257
|
-
id: 1,
|
276
|
+
id: '1',
|
258
277
|
body: 'what a dumb post',
|
259
278
|
links: {
|
260
|
-
author: 1,
|
261
|
-
post: 1,
|
262
|
-
tags: [2, 1]
|
279
|
+
author: '1',
|
280
|
+
post: '1',
|
281
|
+
tags: ['2', '1']
|
263
282
|
}
|
264
283
|
}
|
265
284
|
]
|
@@ -274,32 +293,32 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
274
293
|
assert_hash_equals(
|
275
294
|
{
|
276
295
|
people: {
|
277
|
-
id: 2,
|
296
|
+
id: '2',
|
278
297
|
name: 'Fred Reader',
|
279
298
|
email: 'fred@xyz.fake',
|
280
299
|
dateJoined: '2013-10-31 16:25:00 -0400',
|
281
300
|
links: {
|
282
301
|
posts: [],
|
283
|
-
comments: [2, 3]
|
302
|
+
comments: ['2', '3']
|
284
303
|
}
|
285
304
|
},
|
286
305
|
linked: {
|
287
306
|
comments: [{
|
288
|
-
id: 2,
|
307
|
+
id: '2',
|
289
308
|
body: 'i liked it',
|
290
309
|
links: {
|
291
|
-
author: 2,
|
292
|
-
post: 1,
|
293
|
-
tags: [4, 1]
|
310
|
+
author: '2',
|
311
|
+
post: '1',
|
312
|
+
tags: ['4', '1']
|
294
313
|
}
|
295
314
|
},
|
296
315
|
{
|
297
|
-
id: 3,
|
316
|
+
id: '3',
|
298
317
|
body: 'Thanks man. Great post. But what is JR?',
|
299
318
|
links: {
|
300
|
-
author: 2,
|
301
|
-
post: 2,
|
302
|
-
tags: [5]
|
319
|
+
author: '2',
|
320
|
+
post: '2',
|
321
|
+
tags: ['5']
|
303
322
|
}
|
304
323
|
}
|
305
324
|
]
|
@@ -319,86 +338,86 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
319
338
|
assert_hash_equals(
|
320
339
|
{
|
321
340
|
posts: [{
|
322
|
-
id: 1,
|
341
|
+
id: '1',
|
323
342
|
title: 'New post',
|
324
343
|
body: 'A body!!!',
|
325
344
|
subject: 'New post',
|
326
345
|
links: {
|
327
|
-
author: 1,
|
328
|
-
tags: [1, 2, 3],
|
329
|
-
comments: [1, 2],
|
346
|
+
author: '1',
|
347
|
+
tags: ['1', '2', '3'],
|
348
|
+
comments: ['1', '2'],
|
330
349
|
section: nil
|
331
350
|
}
|
332
351
|
},
|
333
352
|
{
|
334
|
-
id: 2,
|
353
|
+
id: '2',
|
335
354
|
title: 'JR Solves your serialization woes!',
|
336
355
|
body: 'Use JR',
|
337
356
|
subject: 'JR Solves your serialization woes!',
|
338
357
|
links: {
|
339
|
-
author: 1,
|
340
|
-
tags: [5],
|
341
|
-
comments: [3],
|
342
|
-
section: 3
|
358
|
+
author: '1',
|
359
|
+
tags: ['5'],
|
360
|
+
comments: ['3'],
|
361
|
+
section: '3'
|
343
362
|
}
|
344
363
|
}],
|
345
364
|
linked: {
|
346
365
|
tags: [
|
347
366
|
{
|
348
|
-
id: 1,
|
367
|
+
id: '1',
|
349
368
|
name: 'short',
|
350
369
|
links: {
|
351
370
|
posts: :not_nil
|
352
371
|
}
|
353
372
|
},
|
354
373
|
{
|
355
|
-
id: 2,
|
374
|
+
id: '2',
|
356
375
|
name: 'whiny',
|
357
376
|
links: {
|
358
377
|
posts: :not_nil
|
359
378
|
}
|
360
379
|
},
|
361
380
|
{
|
362
|
-
id: 4,
|
381
|
+
id: '4',
|
363
382
|
name: 'happy',
|
364
383
|
links: {
|
365
384
|
posts: :not_nil
|
366
385
|
}
|
367
386
|
},
|
368
387
|
{
|
369
|
-
id: 5,
|
388
|
+
id: '5',
|
370
389
|
name: 'JR',
|
371
390
|
links: {
|
372
|
-
posts: [2, 11]
|
391
|
+
posts: ['2', '11']
|
373
392
|
}
|
374
393
|
}
|
375
394
|
],
|
376
395
|
comments: [
|
377
396
|
{
|
378
|
-
id: 1,
|
397
|
+
id: '1',
|
379
398
|
body: 'what a dumb post',
|
380
399
|
links: {
|
381
|
-
author: 1,
|
382
|
-
post: 1,
|
383
|
-
tags: [2, 1]
|
400
|
+
author: '1',
|
401
|
+
post: '1',
|
402
|
+
tags: ['2', '1']
|
384
403
|
}
|
385
404
|
},
|
386
405
|
{
|
387
|
-
id: 2,
|
406
|
+
id: '2',
|
388
407
|
body: 'i liked it',
|
389
408
|
links: {
|
390
|
-
author: 2,
|
391
|
-
post: 1,
|
392
|
-
tags: [4, 1]
|
409
|
+
author: '2',
|
410
|
+
post: '1',
|
411
|
+
tags: ['4', '1']
|
393
412
|
}
|
394
413
|
},
|
395
414
|
{
|
396
|
-
id: 3,
|
415
|
+
id: '3',
|
397
416
|
body: 'Thanks man. Great post. But what is JR?',
|
398
417
|
links: {
|
399
|
-
author: 2,
|
400
|
-
post: 2,
|
401
|
-
tags: [5]
|
418
|
+
author: '2',
|
419
|
+
post: '2',
|
420
|
+
tags: ['5']
|
402
421
|
}
|
403
422
|
}
|
404
423
|
]
|
@@ -418,17 +437,17 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
418
437
|
assert_hash_equals(
|
419
438
|
{
|
420
439
|
posts: [{
|
421
|
-
id: 1,
|
440
|
+
id: '1',
|
422
441
|
title: 'New post',
|
423
442
|
links: {
|
424
|
-
author: 1
|
443
|
+
author: '1'
|
425
444
|
}
|
426
445
|
},
|
427
446
|
{
|
428
|
-
id: 2,
|
447
|
+
id: '2',
|
429
448
|
title: 'JR Solves your serialization woes!',
|
430
449
|
links: {
|
431
|
-
author: 1
|
450
|
+
author: '1'
|
432
451
|
}
|
433
452
|
}],
|
434
453
|
linked: {
|
@@ -448,42 +467,42 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
448
467
|
],
|
449
468
|
comments: [
|
450
469
|
{
|
451
|
-
id: 1,
|
470
|
+
id: '1',
|
452
471
|
body: 'what a dumb post',
|
453
472
|
links: {
|
454
|
-
post: 1
|
473
|
+
post: '1'
|
455
474
|
}
|
456
475
|
},
|
457
476
|
{
|
458
|
-
id: 2,
|
477
|
+
id: '2',
|
459
478
|
body: 'i liked it',
|
460
479
|
links: {
|
461
|
-
post: 1
|
480
|
+
post: '1'
|
462
481
|
}
|
463
482
|
},
|
464
483
|
{
|
465
|
-
id: 3,
|
484
|
+
id: '3',
|
466
485
|
body: 'Thanks man. Great post. But what is JR?',
|
467
486
|
links: {
|
468
|
-
post: 2
|
487
|
+
post: '2'
|
469
488
|
}
|
470
489
|
}
|
471
490
|
],
|
472
491
|
posts: [
|
473
492
|
{
|
474
|
-
id: 11,
|
493
|
+
id: '11',
|
475
494
|
title: 'JR How To',
|
476
495
|
links: {
|
477
|
-
author: 1
|
496
|
+
author: '1'
|
478
497
|
}
|
479
498
|
}
|
480
499
|
],
|
481
500
|
people: [
|
482
501
|
{
|
483
|
-
id: 1,
|
502
|
+
id: '1',
|
484
503
|
email: 'joe@xyz.fake',
|
485
504
|
links: {
|
486
|
-
comments: [1]
|
505
|
+
comments: ['1']
|
487
506
|
}
|
488
507
|
}]
|
489
508
|
}
|
@@ -503,12 +522,12 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
503
522
|
assert_hash_equals(
|
504
523
|
{
|
505
524
|
expenseEntries: {
|
506
|
-
id: 1,
|
525
|
+
id: '1',
|
507
526
|
transactionDate: '04/15/2014',
|
508
527
|
cost: 12.05,
|
509
528
|
links: {
|
510
529
|
isoCurrency: 'USD',
|
511
|
-
employee: 3
|
530
|
+
employee: '3'
|
512
531
|
}
|
513
532
|
},
|
514
533
|
linked: {
|
@@ -519,7 +538,7 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
519
538
|
minorUnit: 'cent'
|
520
539
|
}],
|
521
540
|
people: [{
|
522
|
-
id: 3,
|
541
|
+
id: '3',
|
523
542
|
name: 'Lazy Author',
|
524
543
|
email: 'lazy@xyz.fake',
|
525
544
|
dateJoined: '2013-10-31 17:25:00 -0400',
|
@@ -541,7 +560,7 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
541
560
|
assert_hash_equals(
|
542
561
|
{
|
543
562
|
planets: {
|
544
|
-
id: 8,
|
563
|
+
id: '8',
|
545
564
|
name: 'Beta W',
|
546
565
|
description: 'Newly discovered Planet W',
|
547
566
|
links: {
|
@@ -572,17 +591,17 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
572
591
|
assert_hash_equals(
|
573
592
|
{
|
574
593
|
planets: [{
|
575
|
-
id: 7,
|
594
|
+
id: '7',
|
576
595
|
name: 'Beta X',
|
577
596
|
description: 'Newly discovered Planet Z',
|
578
597
|
links: {
|
579
|
-
planetType: 1,
|
598
|
+
planetType: '1',
|
580
599
|
tags: [],
|
581
600
|
moons: []
|
582
601
|
}
|
583
602
|
},
|
584
603
|
{
|
585
|
-
id: 8,
|
604
|
+
id: '8',
|
586
605
|
name: 'Beta W',
|
587
606
|
description: 'Newly discovered Planet W',
|
588
607
|
links: {
|
@@ -593,7 +612,7 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
593
612
|
}],
|
594
613
|
linked: {
|
595
614
|
planetTypes: [
|
596
|
-
{ id: 1, name: "Gas Giant" }
|
615
|
+
{ id: '1', name: "Gas Giant" }
|
597
616
|
]
|
598
617
|
}
|
599
618
|
}, planet_hash)
|
@@ -611,7 +630,7 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
611
630
|
assert_hash_equals(
|
612
631
|
{
|
613
632
|
preferences: {
|
614
|
-
id: 1,
|
633
|
+
id: '1',
|
615
634
|
advanced_mode: false,
|
616
635
|
links: {
|
617
636
|
author: nil,
|
@@ -630,7 +649,7 @@ class SerializerTest < MiniTest::Unit::TestCase
|
|
630
649
|
assert_hash_equals(
|
631
650
|
{
|
632
651
|
facts: {
|
633
|
-
id: 1,
|
652
|
+
id: '1',
|
634
653
|
spouse_name: 'Jane Author',
|
635
654
|
bio: 'First man to run across Antartica.',
|
636
655
|
quality_rating: 23.89/45.6,
|