jsonapi-resources 0.3.0.pre1 → 0.3.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7979f6e3a6f09ec2999fb78b2e0a06aa8f6f8be4
4
- data.tar.gz: 6819f84c905130eaf614059393c59e55de8c457c
3
+ metadata.gz: 9adad069e77c8437a28d82ed522448f10282551d
4
+ data.tar.gz: d5cbb50ba9bec003e03d50f54c930dd2b47f16ad
5
5
  SHA512:
6
- metadata.gz: 7389937f7df1ce1ece2ee0a481e626c7c8385cdddda73c12ec7625192eea77d27c4daa9d3bc73a5a10a0eb6aeab8fa4944459b52d0e8fefa8d36469f84dcf230
7
- data.tar.gz: 0e3c2330066fc109530a627b9d5126e9cb60365c7dd5727230df9f9f9de27b3c9089637de1d447677774d76784d9816107d6d06df3a411d67fc779d481c2c329
6
+ metadata.gz: a8453158ff6be52c6fa81fdbcda63543fb9d2952dd9ff3c10c411c543e718bbf52ca0eb1c8104a02e80d856c33a18498dbff5644ec0b6a5645266e3c79d0380a
7
+ data.tar.gz: d42d5196aa3f1728356d5378f45f16fcd5180304dcdc9d380b2d937934f2bdc9a6cb14f4748dcb0c4b43c3a46efc14214dc96a573d224ac7ad17ed3ff6b57a2c
data/README.md CHANGED
@@ -10,6 +10,10 @@ JR is designed to work with Rails, and provides custom routes, controllers, and
10
10
 
11
11
  We have a simple demo app, called [Peeps](https://github.com/cerebris/peeps), available to show how JR is used.
12
12
 
13
+ ## Client Libraries
14
+
15
+ JSON API maintains a (non-verified) listing of [client libraries](http://jsonapi.org/implementations/#client-libraries) which *should* be compatible with JSON API compliant server implementations such as JR.
16
+
13
17
  ## Installation
14
18
 
15
19
  Add JR to your application's `Gemfile`:
@@ -278,7 +278,13 @@ module JSONAPI
278
278
  association = @resource_klass._association(param)
279
279
 
280
280
  if association.is_a?(JSONAPI::Association::HasOne)
281
- links_object = parse_has_one_links_object(link_value)
281
+ if link_value.nil?
282
+ linkage = nil
283
+ else
284
+ linkage = link_value[:linkage]
285
+ end
286
+
287
+ links_object = parse_has_one_links_object(linkage)
282
288
  # Since we do not yet support polymorphic associations we will raise an error if the type does not match the
283
289
  # association's type.
284
290
  # ToDo: Support Polymorphic associations
@@ -293,7 +299,15 @@ module JSONAPI
293
299
  checked_has_one_associations[param] = nil
294
300
  end
295
301
  elsif association.is_a?(JSONAPI::Association::HasMany)
296
- links_object = parse_has_many_links_object(link_value)
302
+ if link_value.is_a?(Array) && link_value.length == 0
303
+ linkage = []
304
+ elsif link_value.is_a?(Hash)
305
+ linkage = link_value[:linkage]
306
+ else
307
+ raise JSONAPI::Exceptions::InvalidLinksObject.new
308
+ end
309
+
310
+ links_object = parse_has_many_links_object(linkage)
297
311
 
298
312
  # Since we do not yet support polymorphic associations we will raise an error if the type does not match the
299
313
  # association's type.
@@ -350,7 +364,7 @@ module JSONAPI
350
364
  association = resource_klass._association(association_type)
351
365
 
352
366
  if association.is_a?(JSONAPI::Association::HasMany)
353
- object_params = {links: {association.name => data}}
367
+ object_params = {links: {association.name => {linkage: data}}}
354
368
  verified_param_set = parse_params(object_params, @resource_klass.updateable_fields(@context))
355
369
 
356
370
  @operations.push JSONAPI::CreateHasManyAssociationOperation.new(resource_klass,
@@ -364,7 +378,7 @@ module JSONAPI
364
378
  association = resource_klass._association(association_type)
365
379
 
366
380
  if association.is_a?(JSONAPI::Association::HasOne)
367
- object_params = {links: {association.name => data}}
381
+ object_params = {links: {association.name => {linkage: data}}}
368
382
 
369
383
  verified_param_set = parse_params(object_params, @resource_klass.updateable_fields(@context))
370
384
 
@@ -373,7 +387,7 @@ module JSONAPI
373
387
  association_type,
374
388
  verified_param_set[:has_one].values[0])
375
389
  else
376
- object_params = {links: {association.name => data}}
390
+ object_params = {links: {association.name => {linkage: data}}}
377
391
  verified_param_set = parse_params(object_params, @resource_klass.updateable_fields(@context))
378
392
 
379
393
  @operations.push JSONAPI::ReplaceHasManyAssociationOperation.new(resource_klass,
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = "0.3.0.pre1"
3
+ VERSION = "0.3.0.pre2"
4
4
  end
5
5
  end
@@ -278,7 +278,7 @@ class PostsControllerTest < ActionController::TestCase
278
278
  title: 'JR is Great',
279
279
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
280
280
  links: {
281
- author: {type: 'people', id: '3'}
281
+ author: {linkage: {type: 'people', id: '3'}}
282
282
  }
283
283
  }
284
284
  }
@@ -299,7 +299,7 @@ class PostsControllerTest < ActionController::TestCase
299
299
  title: 'JR is Great',
300
300
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
301
301
  links: {
302
- author: {type: 'people', id: '304567'}
302
+ author: {linkage: {type: 'people', id: '304567'}}
303
303
  }
304
304
  }
305
305
  }
@@ -319,7 +319,7 @@ class PostsControllerTest < ActionController::TestCase
319
319
  title: 'JR is Great',
320
320
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
321
321
  links: {
322
- author: {type: 'people', id: '3'}
322
+ author: {linkage: {type: 'people', id: '3'}}
323
323
  }
324
324
  }
325
325
  }
@@ -363,7 +363,7 @@ class PostsControllerTest < ActionController::TestCase
363
363
  title: 'JR is Great',
364
364
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
365
365
  links: {
366
- author: {type: 'people', id: '3'}
366
+ author: {linkage: {type: 'people', id: '3'}}
367
367
  }
368
368
  },
369
369
  {
@@ -371,7 +371,7 @@ class PostsControllerTest < ActionController::TestCase
371
371
  title: 'Ember is Great',
372
372
  body: 'Ember is the greatest thing since unsliced bread.',
373
373
  links: {
374
- author: {type: 'people', id: '3'}
374
+ author: {linkage: {type: 'people', id: '3'}}
375
375
  }
376
376
  }
377
377
  ]
@@ -395,7 +395,7 @@ class PostsControllerTest < ActionController::TestCase
395
395
  Title: 'JR is Great',
396
396
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
397
397
  links: {
398
- author: {type: 'people', id: '3'}
398
+ author: {linkage: {type: 'people', id: '3'}}
399
399
  }
400
400
  },
401
401
  {
@@ -403,7 +403,7 @@ class PostsControllerTest < ActionController::TestCase
403
403
  title: 'Ember is Great',
404
404
  BODY: 'Ember is the greatest thing since unsliced bread.',
405
405
  links: {
406
- author: {type: 'people', id: '3'}
406
+ author: {linkage: {type: 'people', id: '3'}}
407
407
  }
408
408
  }
409
409
  ]
@@ -422,7 +422,7 @@ class PostsControllerTest < ActionController::TestCase
422
422
  title: 'JR is Great',
423
423
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
424
424
  links: {
425
- author: {type: 'people', id: '3'}
425
+ author: {linkage: {type: 'people', id: '3'}}
426
426
  }
427
427
  }
428
428
  }
@@ -440,7 +440,7 @@ class PostsControllerTest < ActionController::TestCase
440
440
  title: 'JR is Great',
441
441
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
442
442
  links: {
443
- author: {type: 'people', id: '3'}
443
+ author: {linkage: {type: 'people', id: '3'}}
444
444
  }
445
445
  }
446
446
  }
@@ -457,7 +457,7 @@ class PostsControllerTest < ActionController::TestCase
457
457
  title: 'JR is Great',
458
458
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
459
459
  links: {
460
- author: {type: 'people', id: '3'}
460
+ author: {linkage: {type: 'people', id: '3'}}
461
461
  }
462
462
  }
463
463
  }
@@ -475,7 +475,7 @@ class PostsControllerTest < ActionController::TestCase
475
475
  subject: 'JR is Great',
476
476
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
477
477
  links: {
478
- author: {type: 'people', id: '3'}
478
+ author: {linkage: {type: 'people', id: '3'}}
479
479
  }
480
480
  }
481
481
  }
@@ -493,8 +493,8 @@ class PostsControllerTest < ActionController::TestCase
493
493
  title: 'JR is Great',
494
494
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
495
495
  links: {
496
- author: {type: 'people', id: '3'},
497
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
496
+ author: {linkage: {type: 'people', id: '3'}},
497
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
498
498
  }
499
499
  }
500
500
  }
@@ -515,8 +515,8 @@ class PostsControllerTest < ActionController::TestCase
515
515
  title: 'JR is Great',
516
516
  body: 'JSONAPIResources is the greatest thing since unsliced bread.',
517
517
  links: {
518
- author: {type: 'people', id: '3'},
519
- tags: [{type: 'tags', id: '3'}, {type: 'tags', id: '4'}]
518
+ author: {linkage: {type: 'people', id: '3'}},
519
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
520
520
  }
521
521
  }
522
522
  }
@@ -537,8 +537,8 @@ class PostsControllerTest < ActionController::TestCase
537
537
  title: 'JR is Great!',
538
538
  body: 'JSONAPIResources is the greatest thing since unsliced bread!',
539
539
  links: {
540
- author: {type: 'people', id: '3'},
541
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
540
+ author: {linkage: {type: 'people', id: '3'}},
541
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
542
542
  }
543
543
  },
544
544
  include: 'author,author.posts',
@@ -564,8 +564,8 @@ class PostsControllerTest < ActionController::TestCase
564
564
  type: 'posts',
565
565
  title: 'A great new Post',
566
566
  links: {
567
- section: {type: 'sections', id: "#{javascript.id}"},
568
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
567
+ section: {linkage: {type: 'sections', id: "#{javascript.id}"}},
568
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
569
569
  }
570
570
  },
571
571
  include: 'tags'
@@ -583,6 +583,23 @@ class PostsControllerTest < ActionController::TestCase
583
583
 
584
584
  def test_update_remove_links
585
585
  set_content_type_header!
586
+ put :update,
587
+ {
588
+ id: 3,
589
+ data: {
590
+ id: '3',
591
+ type: 'posts',
592
+ title: 'A great new Post',
593
+ links: {
594
+ section: {linkage: {type: 'sections', id: 1}},
595
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
596
+ }
597
+ },
598
+ include: 'tags'
599
+ }
600
+
601
+ assert_response :success
602
+
586
603
  put :update,
587
604
  {
588
605
  id: 3,
@@ -680,7 +697,7 @@ class PostsControllerTest < ActionController::TestCase
680
697
  type: 'posts',
681
698
  id: 3,
682
699
  links: {
683
- tags: {typ: 'bad link', idd: 'as'}
700
+ tags: {linkage: {typ: 'bad link', idd: 'as'}}
684
701
  }
685
702
  }
686
703
  }
@@ -707,6 +724,24 @@ class PostsControllerTest < ActionController::TestCase
707
724
  assert_match /Invalid Links Object/, response.body
708
725
  end
709
726
 
727
+ def test_update_other_has_many_links_linkage_nil
728
+ set_content_type_header!
729
+ put :update,
730
+ {
731
+ id: 3,
732
+ data: {
733
+ type: 'posts',
734
+ id: 3,
735
+ links: {
736
+ tags: {linkage: nil}
737
+ }
738
+ }
739
+ }
740
+
741
+ assert_response :bad_request
742
+ assert_match /Invalid Links Object/, response.body
743
+ end
744
+
710
745
  def test_update_relationship_has_one_singular_param_id_nil
711
746
  set_content_type_header!
712
747
  ruby = Section.find_by(name: 'ruby')
@@ -1054,8 +1089,8 @@ class PostsControllerTest < ActionController::TestCase
1054
1089
  id: 3,
1055
1090
  title: 'A great new Post QWERTY',
1056
1091
  links: {
1057
- section: {type: 'sections', id: "#{javascript.id}"},
1058
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
1092
+ section: {linkage: {type: 'sections', id: "#{javascript.id}"}},
1093
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
1059
1094
  }
1060
1095
  },
1061
1096
  {
@@ -1063,8 +1098,8 @@ class PostsControllerTest < ActionController::TestCase
1063
1098
  id: 16,
1064
1099
  title: 'A great new Post ASDFG',
1065
1100
  links: {
1066
- section: {type: 'sections', id: "#{javascript.id}"},
1067
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
1101
+ section: {linkage: {type: 'sections', id: "#{javascript.id}"}},
1102
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
1068
1103
  }
1069
1104
  }
1070
1105
  ],
@@ -1131,8 +1166,8 @@ class PostsControllerTest < ActionController::TestCase
1131
1166
  id: 3,
1132
1167
  title: 'A great new Post ASDFG',
1133
1168
  links: {
1134
- section: {type: 'sections', id: "#{javascript.id}"},
1135
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
1169
+ section: {linkage: {type: 'sections', id: "#{javascript.id}"}},
1170
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
1136
1171
  }
1137
1172
  },
1138
1173
  {
@@ -1140,8 +1175,8 @@ class PostsControllerTest < ActionController::TestCase
1140
1175
  id: 8,
1141
1176
  title: 'A great new Post QWERTY',
1142
1177
  links: {
1143
- section: {type: 'sections', id: "#{javascript.id}"},
1144
- tags: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]
1178
+ section: {linkage: {type: 'sections', id: "#{javascript.id}"}},
1179
+ tags: {linkage: [{type: 'tags', id: 3}, {type: 'tags', id: 4}]}
1145
1180
  }
1146
1181
  }
1147
1182
  ]}
@@ -1385,8 +1420,8 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1385
1420
  transaction_date: '2014/04/15',
1386
1421
  cost: 50.58,
1387
1422
  links: {
1388
- employee: {type: 'people', id: '3'},
1389
- iso_currency: {type: 'iso_currencies', id: 'USD'}
1423
+ employee: {linkage: {type: 'people', id: '3'}},
1424
+ iso_currency: {linkage: {type: 'iso_currencies', id: 'USD'}}
1390
1425
  }
1391
1426
  },
1392
1427
  include: 'iso_currency',
@@ -1414,8 +1449,8 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1414
1449
  transactionDate: '2014/04/15',
1415
1450
  cost: 50.58,
1416
1451
  links: {
1417
- employee: {type: 'people', id: '3'},
1418
- isoCurrency: {type: 'iso_currencies', id: 'USD'}
1452
+ employee: {linkage: {type: 'people', id: '3'}},
1453
+ isoCurrency: {linkage: {type: 'iso_currencies', id: 'USD'}}
1419
1454
  }
1420
1455
  },
1421
1456
  include: 'isoCurrency',
@@ -1443,8 +1478,8 @@ class ExpenseEntriesControllerTest < ActionController::TestCase
1443
1478
  'transaction-date' => '2014/04/15',
1444
1479
  cost: 50.58,
1445
1480
  links: {
1446
- employee: {type: 'people', id: '3'},
1447
- 'iso-currency' => {type: 'iso_currencies', id: 'USD'}
1481
+ employee: {linkage: {type: 'people', id: '3'}},
1482
+ 'iso-currency' => {linkage: {type: 'iso_currencies', id: 'USD'}}
1448
1483
  }
1449
1484
  },
1450
1485
  include: 'iso-currency',
@@ -1772,7 +1807,7 @@ class Api::V1::PostsControllerTest < ActionController::TestCase
1772
1807
  title: 'JR - now with Namespacing',
1773
1808
  body: 'JSONAPIResources is the greatest thing since unsliced bread now that it has namespaced resources.',
1774
1809
  links: {
1775
- writer: {type: 'writers', id: '3'}
1810
+ writer: { linkage: {type: 'writers', id: '3'}}
1776
1811
  }
1777
1812
  }
1778
1813
  }
@@ -108,10 +108,12 @@ class RequestTest < ActionDispatch::IntegrationTest
108
108
  'id' => '3',
109
109
  'title' => 'A great new Post',
110
110
  'links' => {
111
- 'tags' => [
112
- {type: 'tags', id: 3},
113
- {type: 'tags', id: 4}
114
- ]
111
+ 'tags' => {
112
+ 'linkage' => [
113
+ {type: 'tags', id: 3},
114
+ {type: 'tags', id: 4}
115
+ ]
116
+ }
115
117
  }
116
118
  }
117
119
  }.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
@@ -125,10 +127,12 @@ class RequestTest < ActionDispatch::IntegrationTest
125
127
  'posts' => {
126
128
  'title' => 'A great new Post',
127
129
  'links' => {
128
- 'tags' => [
129
- {type: 'tags', id: 3},
130
- {type: 'tags', id: 4}
131
- ]
130
+ 'tags' => {
131
+ 'linkage' => [
132
+ {type: 'tags', id: 3},
133
+ {type: 'tags', id: 4}
134
+ ]
135
+ }
132
136
  }
133
137
  }
134
138
  }.to_json, "CONTENT_TYPE" => "application/json"
@@ -144,7 +148,7 @@ class RequestTest < ActionDispatch::IntegrationTest
144
148
  'title' => 'A great new Post',
145
149
  'body' => 'JSONAPIResources is the greatest thing since unsliced bread.',
146
150
  'links' => {
147
- 'author' => {type: 'people', id: '3'}
151
+ 'author' => {'linkage' => {type: 'people', id: '3'}}
148
152
  }
149
153
  }
150
154
  }.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
@@ -191,10 +195,12 @@ class RequestTest < ActionDispatch::IntegrationTest
191
195
  'id' => '3',
192
196
  'title' => 'A great new Post',
193
197
  'links' => {
194
- 'tags' => [
195
- {type: 'tags', id: 3},
196
- {type: 'tags', id: 4}
197
- ]
198
+ 'tags' => {
199
+ 'linkage' => [
200
+ {type: 'tags', id: 3},
201
+ {type: 'tags', id: 4}
202
+ ]
203
+ }
198
204
  }
199
205
  }
200
206
  }.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
@@ -210,10 +216,12 @@ class RequestTest < ActionDispatch::IntegrationTest
210
216
  'id' => '3',
211
217
  'title' => 'A great new Post',
212
218
  'links' => {
213
- 'tags' => [
214
- {type: 'tags', id: 3},
215
- {type: 'tags', id: 4}
216
- ]
219
+ 'tags' => {
220
+ 'linkage' => [
221
+ {type: 'tags', id: 3},
222
+ {type: 'tags', id: 4}
223
+ ]
224
+ }
217
225
  }
218
226
  }
219
227
  }.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
@@ -228,7 +236,7 @@ class RequestTest < ActionDispatch::IntegrationTest
228
236
  'type' => 'posts',
229
237
  'title' => 'A great new Post',
230
238
  'links' => {
231
- 'author' => {type: 'people', id: '3'}
239
+ 'author' => {'linkage' => {type: 'people', id: '3'}}
232
240
  }
233
241
  }
234
242
  }.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre1
4
+ version: 0.3.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gebhardt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-23 00:00:00.000000000 Z
12
+ date: 2015-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler