Skip to content

Commit 3132d60

Browse files
authored
Merge pull request #17 from kantorm/orders
Order initialize
2 parents fa36dcf + 8184917 commit 3132d60

File tree

8 files changed

+50
-6
lines changed

8 files changed

+50
-6
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class CategoryController < ApplicationController
2+
end

app/controllers/orders_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class OrdersController < AuthorizedController
2+
end

app/models/order.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Order < ApplicationRecord
2+
end

app/resources/order_resource.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class OrderResource < JSONAPI::Resource
2+
attributes :order_date, :required_date, :shipped_date, :ship_via, :freight, :ship_name, :ship_address, :ship_city,
3+
:ship_region, :ship_postal_code, :ship_country
4+
end

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
jsonapi_resources :products
77
jsonapi_resources :users
88
jsonapi_resources :roles
9+
jsonapi_resources :orders
910
jsonapi_resources :customers
1011
jsonapi_resources :suppliers
1112
end
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateOrders < ActiveRecord::Migration[5.0]
2+
def change
3+
create_table :orders do |t|
4+
t.date :order_date
5+
t.date :required_date
6+
t.date :shipped_date
7+
t.integer :ship_via
8+
t.float :freight
9+
t.string :ship_name
10+
t.string :ship_address
11+
t.string :ship_city
12+
t.string :ship_region
13+
t.string :ship_postal_code
14+
t.string :ship_country
15+
t.timestamps
16+
end
17+
end
18+
end

db/seeds.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
end
1414

1515
25.times do |n|
16-
User.create!(
17-
email: "user#{n}@example.com",
18-
password: 'Secret123',
19-
confirmed_at: Time.now,
20-
tokens: nil
21-
).add_role n == 0 ? :admin : :user
16+
u = User.create!(email: "user#{n}@example.com", password: 'Secret123', confirmed_at: Time.now)
17+
u.add_role n == 0 ? :admin : :user
18+
end
19+
20+
25.times do |n|
21+
FactoryGirl.create(:order)
2222
end
2323

2424
25.times do |n|

spec/factories/order.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FactoryGirl.define do
2+
factory :order do
3+
order_date { Faker::Date.between(10.days.ago, Date.today) }
4+
required_date { Faker::Date.between(10.days.ago, Date.today) }
5+
shipped_date { Faker::Date.between(10.days.ago, Date.today) }
6+
ship_via { 'DHL' }
7+
freight { rand(1000) }
8+
ship_name { 'Titanic' }
9+
ship_address { Faker::Address.street_name }
10+
ship_city { Faker::Address.city }
11+
ship_region { Faker::Address.state }
12+
ship_postal_code { Faker::Address.zip }
13+
ship_country { Faker::Address.country }
14+
end
15+
end

0 commit comments

Comments
 (0)