jsonapi-resources 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jsonapi/exceptions.rb +6 -1
- data/lib/jsonapi/request.rb +1 -1
- data/lib/jsonapi/resources/version.rb +1 -1
- data/test/controllers/controller_test.rb +1 -1
- data/test/fixtures/active_record.rb +33 -0
- data/test/fixtures/line_items.yml +15 -1
- data/test/fixtures/order_flags.yml +7 -0
- data/test/integration/requests/request_test.rb +47 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7354d2936f1ae7ba14a27b816ba9e9a0b34b0b13
|
4
|
+
data.tar.gz: 5dc38e6256771df238ddefd326eae64c72955113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ffb7b64c39241f8579ca839c46926c2f90a83335bcff101b46b8eb708f4478c8c9b80ba493aa1991a46a0f995b7d395367372d71b6c01ab97edb7266c1674dc
|
7
|
+
data.tar.gz: 73b910fe3ef9a75f4b10b2a4bd576e68c42cdcb33224d3f72dc38743cd7808c5b8d54722ca9502787f66183e5a9f28d6131e4afebdda927f3427edabe2fd8349
|
data/lib/jsonapi/exceptions.rb
CHANGED
@@ -284,6 +284,11 @@ module JSONAPI
|
|
284
284
|
attr_accessor :messages
|
285
285
|
def initialize(messages)
|
286
286
|
@messages = messages
|
287
|
+
@key_formatter = JSONAPI.configuration.key_formatter
|
288
|
+
end
|
289
|
+
|
290
|
+
def format_key(key)
|
291
|
+
@key_formatter.format(key)
|
287
292
|
end
|
288
293
|
|
289
294
|
def errors
|
@@ -292,7 +297,7 @@ module JSONAPI
|
|
292
297
|
element[1].map do |message|
|
293
298
|
JSONAPI::Error.new(code: JSONAPI::VALIDATION_ERROR,
|
294
299
|
status: :unprocessable_entity,
|
295
|
-
title: "#{element[0]} - #{message}",
|
300
|
+
title: "#{format_key(element[0])} - #{message}",
|
296
301
|
detail: message,
|
297
302
|
path: "/#{element[0]}")
|
298
303
|
end
|
data/lib/jsonapi/request.rb
CHANGED
@@ -309,7 +309,7 @@ module JSONAPI
|
|
309
309
|
if links_object.length == 0
|
310
310
|
checked_has_many_associations[param] = []
|
311
311
|
else
|
312
|
-
if links_object.length > 1 || !links_object.has_key?(
|
312
|
+
if links_object.length > 1 || !links_object.has_key?(unformat_key(association.type).to_s)
|
313
313
|
raise JSONAPI::Exceptions::TypeMismatch.new(links_object[:type])
|
314
314
|
end
|
315
315
|
|
@@ -1684,7 +1684,7 @@ class PeopleControllerTest < ActionController::TestCase
|
|
1684
1684
|
assert_equal 2, json_response['errors'].size
|
1685
1685
|
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][0]['code']
|
1686
1686
|
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][1]['code']
|
1687
|
-
assert_match /
|
1687
|
+
assert_match /dateJoined - can't be blank/, response.body
|
1688
1688
|
assert_match /name - can't be blank/, response.body
|
1689
1689
|
end
|
1690
1690
|
|
@@ -136,6 +136,15 @@ ActiveRecord::Schema.define do
|
|
136
136
|
t.timestamps null: false
|
137
137
|
end
|
138
138
|
|
139
|
+
create_table :order_flags, force: true do |t|
|
140
|
+
t.string :name
|
141
|
+
end
|
142
|
+
|
143
|
+
create_table :purchase_orders_order_flags, force: true do |t|
|
144
|
+
t.references :purchase_order, :order_flag, index: true
|
145
|
+
end
|
146
|
+
add_index :purchase_orders_order_flags, [:purchase_order_id, :order_flag_id], unique: true, name: "po_flags_idx"
|
147
|
+
|
139
148
|
create_table :line_items, force: true do |t|
|
140
149
|
t.integer :purchase_order_id
|
141
150
|
t.string :part_number
|
@@ -277,12 +286,22 @@ class BreedData
|
|
277
286
|
end
|
278
287
|
|
279
288
|
class CustomerOrder < ActiveRecord::Base
|
289
|
+
has_many :purchase_orders
|
280
290
|
end
|
281
291
|
|
282
292
|
class PurchaseOrder < ActiveRecord::Base
|
293
|
+
belongs_to :customer
|
294
|
+
has_many :line_items
|
295
|
+
|
296
|
+
has_and_belongs_to_many :order_flags, join_table: :purchase_orders_order_flags
|
297
|
+
end
|
298
|
+
|
299
|
+
class OrderFlag < ActiveRecord::Base
|
300
|
+
has_and_belongs_to_many :purchase_orders, join_table: :purchase_orders_order_flags
|
283
301
|
end
|
284
302
|
|
285
303
|
class LineItem < ActiveRecord::Base
|
304
|
+
belongs_to :purchase_order
|
286
305
|
end
|
287
306
|
|
288
307
|
### PORO Data - don't do this in a production app
|
@@ -422,6 +441,9 @@ module Api
|
|
422
441
|
|
423
442
|
class LineItemsController < JSONAPI::ResourceController
|
424
443
|
end
|
444
|
+
|
445
|
+
class OrderFlagsController < JSONAPI::ResourceController
|
446
|
+
end
|
425
447
|
end
|
426
448
|
|
427
449
|
module V7
|
@@ -433,6 +455,9 @@ module Api
|
|
433
455
|
|
434
456
|
class LineItemsController < JSONAPI::ResourceController
|
435
457
|
end
|
458
|
+
|
459
|
+
class OrderFlagsController < JSONAPI::ResourceController
|
460
|
+
end
|
436
461
|
end
|
437
462
|
end
|
438
463
|
|
@@ -817,6 +842,13 @@ module Api
|
|
817
842
|
|
818
843
|
has_one :customer
|
819
844
|
has_many :line_items
|
845
|
+
has_many :order_flags, acts_as_set: true
|
846
|
+
end
|
847
|
+
|
848
|
+
class OrderFlagResource < JSONAPI::Resource
|
849
|
+
attributes :name
|
850
|
+
|
851
|
+
has_many :purchase_orders
|
820
852
|
end
|
821
853
|
|
822
854
|
class LineItemResource < JSONAPI::Resource
|
@@ -831,6 +863,7 @@ module Api
|
|
831
863
|
module V7
|
832
864
|
CustomerResource = V6::CustomerResource.dup
|
833
865
|
PurchaseOrderResource = V6::PurchaseOrderResource.dup
|
866
|
+
OrderFlagResource = V6::OrderFlagResource.dup
|
834
867
|
LineItemResource = V6::LineItemResource.dup
|
835
868
|
end
|
836
869
|
end
|
@@ -1,11 +1,25 @@
|
|
1
1
|
po_1_li_1:
|
2
|
+
id: 1
|
2
3
|
purchase_order_id: 1
|
3
4
|
part_number: 556324
|
4
5
|
quantity: 1
|
5
6
|
item_cost: 45.67
|
6
7
|
|
7
8
|
po_1_li_2:
|
9
|
+
id: 2
|
8
10
|
purchase_order_id: 1
|
9
11
|
part_number: 79324231A
|
10
12
|
quantity: 3
|
11
|
-
item_cost: 19.99
|
13
|
+
item_cost: 19.99
|
14
|
+
|
15
|
+
li_3:
|
16
|
+
id: 3
|
17
|
+
part_number: 79324231A
|
18
|
+
quantity: 67
|
19
|
+
item_cost: 19.99
|
20
|
+
|
21
|
+
li_4:
|
22
|
+
id: 4
|
23
|
+
part_number: 5678
|
24
|
+
quantity: 2
|
25
|
+
item_cost: 199.99
|
@@ -564,4 +564,51 @@ class RequestTest < ActionDispatch::IntegrationTest
|
|
564
564
|
assert_equal 200, status
|
565
565
|
end
|
566
566
|
|
567
|
+
def test_patch_formatted_dasherized_links
|
568
|
+
JSONAPI.configuration.route_format = :dasherized_route
|
569
|
+
JSONAPI.configuration.json_key_format = :dasherized_key
|
570
|
+
patch '/api/v6/line-items/1',
|
571
|
+
{
|
572
|
+
'data' => {
|
573
|
+
'id' => '1',
|
574
|
+
'type' => 'line-items',
|
575
|
+
'item-cost' => '23.57',
|
576
|
+
'links' => {
|
577
|
+
'purchase-order' => {
|
578
|
+
'linkage' => {'type' => 'purchase-orders', 'id' => '2'}
|
579
|
+
}
|
580
|
+
}
|
581
|
+
}
|
582
|
+
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
583
|
+
|
584
|
+
assert_equal 200, status
|
585
|
+
end
|
586
|
+
|
587
|
+
def test_patch_formatted_dasherized_replace_has_many
|
588
|
+
JSONAPI.configuration.route_format = :dasherized_route
|
589
|
+
JSONAPI.configuration.json_key_format = :dasherized_key
|
590
|
+
patch '/api/v6/purchase-orders/2?include=line-items,order-flags',
|
591
|
+
{
|
592
|
+
'data' => {
|
593
|
+
'id' => '2',
|
594
|
+
'type' => 'purchase-orders',
|
595
|
+
'links' => {
|
596
|
+
'line-items' => {
|
597
|
+
'linkage' => [
|
598
|
+
{'type' => 'line-items', 'id' => '3'},
|
599
|
+
{'type' => 'line-items', 'id' => '4'}
|
600
|
+
]
|
601
|
+
},
|
602
|
+
'order-flags' => {
|
603
|
+
'linkage' => [
|
604
|
+
{'type' => 'order-flags', 'id' => '1'},
|
605
|
+
{'type' => 'order-flags', 'id' => '2'}
|
606
|
+
]
|
607
|
+
}
|
608
|
+
}
|
609
|
+
}
|
610
|
+
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
|
611
|
+
|
612
|
+
assert_equal 200, status
|
613
|
+
end
|
567
614
|
end
|
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.
|
4
|
+
version: 0.3.3
|
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-04-
|
12
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- test/fixtures/hair_cuts.yml
|
159
159
|
- test/fixtures/iso_currencies.yml
|
160
160
|
- test/fixtures/line_items.yml
|
161
|
+
- test/fixtures/order_flags.yml
|
161
162
|
- test/fixtures/people.yml
|
162
163
|
- test/fixtures/posts.yml
|
163
164
|
- test/fixtures/posts_tags.yml
|
@@ -214,6 +215,7 @@ test_files:
|
|
214
215
|
- test/fixtures/hair_cuts.yml
|
215
216
|
- test/fixtures/iso_currencies.yml
|
216
217
|
- test/fixtures/line_items.yml
|
218
|
+
- test/fixtures/order_flags.yml
|
217
219
|
- test/fixtures/people.yml
|
218
220
|
- test/fixtures/posts.yml
|
219
221
|
- test/fixtures/posts_tags.yml
|