Skip to content

Commit 6b2083b

Browse files
committed
Add multiword models and resources to better test formatters
1 parent 6ebf986 commit 6b2083b

5 files changed

Lines changed: 119 additions & 0 deletions

File tree

test/fixtures/active_record.rb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,35 @@
113113
t.integer :author_id
114114
t.timestamps null: false
115115
end
116+
117+
create_table :customers, force: true do |t|
118+
t.string :name
119+
end
120+
121+
create_table :purchase_orders, force: true do |t|
122+
t.date :order_date
123+
t.date :requested_delivery_date
124+
t.date :delivery_date
125+
t.integer :customer_id
126+
t.string :delivery_name
127+
t.string :delivery_address_1
128+
t.string :delivery_address_2
129+
t.string :delivery_city
130+
t.string :delivery_state
131+
t.string :delivery_postal_code
132+
t.float :delivery_fee
133+
t.float :tax
134+
t.float :total
135+
t.timestamps null: false
136+
end
137+
138+
create_table :line_items, force: true do |t|
139+
t.integer :purchase_order_id
140+
t.string :part_number
141+
t.string :quantity
142+
t.float :item_cost
143+
t.timestamps null: false
144+
end
116145
end
117146

118147
### MODELS
@@ -239,7 +268,15 @@ def add(breed)
239268
def remove(id)
240269
@breeds.delete(id)
241270
end
271+
end
242272

273+
class CustomerOrder < ActiveRecord::Base
274+
end
275+
276+
class PurchaseOrder < ActiveRecord::Base
277+
end
278+
279+
class LineItem < ActiveRecord::Base
243280
end
244281

245282
### PORO Data - don't do this in a production app
@@ -369,6 +406,14 @@ class ExpenseEntriesController < JSONAPI::ResourceController
369406
class IsoCurrenciesController < JSONAPI::ResourceController
370407
end
371408
end
409+
410+
module V6
411+
class PurchaseOrdersController < JSONAPI::ResourceController
412+
end
413+
414+
class LineItemsController < JSONAPI::ResourceController
415+
end
416+
end
372417
end
373418

374419
### RESOURCES
@@ -721,6 +766,42 @@ def fetchable_fields
721766
end
722767
end
723768

769+
module Api
770+
module V6
771+
class CustomerResource < JSONAPI::Resource
772+
attribute :name
773+
774+
has_many :purchase_orders
775+
end
776+
777+
class PurchaseOrderResource < JSONAPI::Resource
778+
attribute :order_date
779+
attribute :requested_delivery_date
780+
attribute :delivery_date
781+
attribute :delivery_name
782+
attribute :delivery_address_1
783+
attribute :delivery_address_2
784+
attribute :delivery_city
785+
attribute :delivery_state
786+
attribute :delivery_postal_code
787+
attribute :delivery_fee
788+
attribute :tax
789+
attribute :total
790+
791+
has_one :customer
792+
has_many :line_items
793+
end
794+
795+
class LineItemResource < JSONAPI::Resource
796+
attribute :part_number
797+
attribute :quantity
798+
attribute :item_cost
799+
800+
has_one :purchase_order
801+
end
802+
end
803+
end
804+
724805
warn 'start testing Name Collisions'
725806
# The name collisions only emmit warnings. Exceptions would change the flow of the tests
726807

test/fixtures/customers.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
xyz_corp:
2+
id: 1
3+
name: XYZ Corporation
4+
5+
abc_corp:
6+
id: 2
7+
name: ABC Corporation

test/fixtures/line_items.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
po_1_li_1:
2+
purchase_order_id: 1
3+
part_number: 556324
4+
quantity: 1
5+
item_cost: 45.67
6+
7+
po_1_li_2:
8+
purchase_order_id: 1
9+
part_number: 79324231A
10+
quantity: 3
11+
item_cost: 19.99

test/fixtures/purchase_orders.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
po_1:
2+
id: 1
3+
requested_delivery_date:
4+
delivery_date: nil
5+
customer_id: 1
6+
7+
po_2:
8+
id: 2
9+
requested_delivery_date:
10+
delivery_date: nil
11+
customer_id: 1

test/test_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ def as_json(options = nil)
146146

147147
end
148148
JSONAPI.configuration.route_format = :underscored_route
149+
150+
JSONAPI.configuration.route_format = :dasherized_route
151+
namespace :v6 do
152+
jsonapi_resources :customers
153+
jsonapi_resources :purchase_orders
154+
jsonapi_resources :line_items
155+
end
156+
JSONAPI.configuration.route_format = :underscored_route
157+
149158
end
150159
end
151160

0 commit comments

Comments
 (0)