Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
970bb3d2
Commit
970bb3d2
authored
Sep 12, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve spec
parent
dabd39b9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
272 additions
and
232 deletions
+272
-232
order_spec.rb
...generators/templates/spec/requests/customer/order_spec.rb
+41
-4
product_snapshot_spec.rb
...templates/spec/requests/customer/product_snapshot_spec.rb
+230
-227
product_snapshot_spec.rb
...templates/spec/requests/merchant/product_snapshot_spec.rb
+1
-1
No files found.
lib/generators/templates/spec/requests/customer/order_spec.rb
View file @
970bb3d2
...
@@ -54,7 +54,7 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
...
@@ -54,7 +54,7 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
path
"/
#{
namespace
}
/cart/product_snapshots"
do
path
"/
#{
namespace
}
/cart/product_snapshots"
do
post
(
summary:
'用户 添加快照至购物车( using series_id & count )'
)
do
post
(
summary:
'用户 添加快照至购物车( using s
hotengai_s
eries_id & count )'
)
do
produces
'application/json'
produces
'application/json'
consumes
'application/json'
consumes
'application/json'
parameter
:buyer_type
,
in: :query
,
type: :string
parameter
:buyer_type
,
in: :query
,
type: :string
...
@@ -92,6 +92,9 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
...
@@ -92,6 +92,9 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
end
end
path
"/
#{
namespace
}
/orders/{id}/product_snapshots"
do
path
"/
#{
namespace
}
/orders/{id}/product_snapshots"
do
parameter
:id
,
in: :path
,
type: :integer
let
(
:id
)
{
@order_1
.
id
}
get
(
summary:
'某订单的 order 所有snapshots'
)
do
get
(
summary:
'某订单的 order 所有snapshots'
)
do
produces
'application/json'
produces
'application/json'
consumes
'application/json'
consumes
'application/json'
...
@@ -100,14 +103,12 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
...
@@ -100,14 +103,12 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
let
(
:buyer_id
)
{
@user
.
id
}
let
(
:buyer_id
)
{
@user
.
id
}
let
(
:buyer_type
)
{
@user
.
class
.
name
}
let
(
:buyer_type
)
{
@user
.
class
.
name
}
parameter
:id
,
in: :path
,
type: :integer
parameter
:page
,
in: :query
,
type: :string
parameter
:page
,
in: :query
,
type: :string
parameter
:per_page
,
in: :query
,
type: :string
parameter
:per_page
,
in: :query
,
type: :string
let
(
:page
)
{
1
}
let
(
:page
)
{
1
}
let
(
:per_page
)
{
100
}
let
(
:per_page
)
{
100
}
let
(
:id
)
{
@order_1
.
id
}
before
do
before
do
@orders
.
last
.
product_snapshots
.
create!
(
@orders
.
last
.
product_snapshots
.
create!
(
...
@@ -123,6 +124,42 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
...
@@ -123,6 +124,42 @@ RSpec.describe "#{namespace}/orders", type: :request, capture_examples: true, ta
}
}
end
end
end
end
post
(
summary:
'用户 添加快照至订单( using shotengai_series_id & count )'
)
do
produces
'application/json'
consumes
'application/json'
parameter
:buyer_type
,
in: :query
,
type: :string
parameter
:buyer_id
,
in: :query
,
type: :integer
let
(
:buyer_id
)
{
@user
.
id
}
let
(
:buyer_type
)
{
@user
.
class
.
name
}
parameter
:product_snapshot
,
in: :body
,
schema:
{
type: :object
,
properties:
{
product_snapshot:
{
type: :object
,
properties:
{
shotengai_series_id:
{
type: :integer
},
count:
{
type: :integer
},
}
}
}
}
before
{
@order_1_snapshots_count_was
=
@order_1
.
snapshots
.
count
}
response
(
201
,
description:
'Create snapshot and add it to the cart'
)
do
let
(
:product_snapshot
)
{
{
product_snapshot:
{
shotengai_series_id:
@series_1
.
id
,
count:
10
,
}
}
}
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'count'
]).
to
eq
(
10
)
expect
(
@order_1
.
snapshots
.
count
).
to
eq
(
@order_1_snapshots_count_was
+
1
)
}
end
end
end
end
path
"/
#{
namespace
}
/orders"
do
path
"/
#{
namespace
}
/orders"
do
...
...
lib/generators/templates/spec/requests/customer/product_snapshot_spec.rb
View file @
970bb3d2
require
'swagger_helper'
# require 'swagger_helper'
namespace
=
'<%= @namespace %>'
# namespace = '<%= @namespace %>'
RSpec
.
describe
"
#{
namespace
}
/product_snapshots"
,
type: :request
,
capture_examples:
true
,
tags:
[
"
#{
namespace
}
API"
,
"product_snapshots"
]
do
# RSpec.describe "#{namespace}/product_snapshots", type: :request, capture_examples: true, tags: ["#{namespace} API", "product_snapshots"] do
before
do
# before do
@user
=
create
(
:user
)
# @user = create(:user)
@products
=
create_list
(
:product
,
3
)
# @products = create_list(:product, 3)
@product_1
=
@products
.
first
# @product_1 = @products.first
@series_1
=
create
(
# @series_1 = create(
:product_series
,
# :product_series,
product:
@product_1
,
# product: @product_1,
spec:
{
# spec: {
"颜色"
=>
"白色"
,
# "颜色" => "白色",
"大小"
=>
"S"
,
# "大小" => "S",
}
# }
)
# )
@series_2
=
create
(
# @series_2 = create(
:product_series
,
{
# :product_series, {
product:
@product_1
,
# product: @product_1,
spec:
{
# spec: {
"颜色"
=>
"黑色"
,
# "颜色" => "黑色",
"大小"
=>
"S"
,
# "大小" => "S",
}
# }
}
# }
)
# )
@snapshot_1
=
create
(
:product_snapshot
,
series:
@series_1
,
count:
2
)
# @snapshot_1 = create(:product_snapshot, series: @series_1, count: 2)
@snapshot_2
=
create
(
:product_snapshot
,
series:
@series_1
,
count:
5
)
# @snapshot_2 = create(:product_snapshot, series: @series_1, count: 5)
@snapshot_other
=
create
(
:product_snapshot
,
series:
@series_2
,
count:
5
)
# @snapshot_other = create(:product_snapshot, series: @series_2, count: 5)
@order
=
create
(
:order
)
# @order = create(:order)
@cart
=
@user
.
order_cart
# @cart = @user.order_cart
@snapshot_1
.
update!
(
order:
@order
)
# @snapshot_1.update!(order: @order)
@snapshot_other
.
update!
(
order:
@order
)
# @snapshot_other.update!(order: @order)
@snapshot_2
.
update!
(
order_cart:
@cart
)
# @snapshot_2.update!(order_cart: @cart)
end
# end
path
"/
#{
namespace
}
/product_snapshots"
do
# path "/#{namespace}/product_snapshots" do
get
(
summary:
'用户 快照列表 三参数可仍以任意组合'
)
do
# get(summary: '用户 快照列表 三参数可仍以任意组合') do
parameter
:buyer_type
,
in: :query
,
type: :string
# parameter :buyer_type, in: :query, type: :string
parameter
:buyer_id
,
in: :query
,
type: :integer
# parameter :buyer_id, in: :query, type: :integer
let
(
:buyer_id
)
{
@user
.
id
}
# let(:buyer_id) { @user.id }
let
(
:buyer_type
)
{
@user
.
class
.
name
}
# let(:buyer_type) { @user.class.name }
parameter
:page
,
in: :query
,
type: :string
# parameter :page, in: :query, type: :string
parameter
:per_page
,
in: :query
,
type: :string
# parameter :per_page, in: :query, type: :string
parameter
:series_id
,
in: :query
,
type: :integer
# parameter :series_id, in: :query, type: :integer
parameter
:order_id
,
in: :query
,
type: :string
# parameter :order_id, in: :query, type: :string
parameter
:in_cart
,
in: :query
,
type: :boolean
# parameter :in_cart, in: :query, type: :boolean
let
(
:page
)
{
1
}
# let(:page) { 1 }
let
(
:per_page
)
{
100
}
# let(:per_page) { 100 }
produces
'application/json'
# produces 'application/json'
consumes
'application/json'
# consumes 'application/json'
response
(
200
,
description:
'successful, query by product_series_id'
)
do
# response(200, description: 'successful, query by product_series_id') do
let
(
:series_id
)
{
@series_1
.
id
}
# let(:series_id) { @series_1.id }
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'product_snapshots'
].
count
).
to
eq
(
@series_1
.
snapshots
.
in_order
.
count
)
# it {
}
# p JSON.parse(response.body)
end
# p '-------'
# expect(JSON.parse(response.body)['product_snapshots'].count).to eq(@series_1.snapshots.in_order.count)
response
(
200
,
description:
'successful, query by order_id'
)
do
# }
let
(
:order_id
)
{
@order
.
id
}
# end
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'product_snapshots'
].
count
).
to
eq
(
@order
.
snapshots
.
count
)
# response(200, description: 'successful, query by order_id') do
}
# let(:order_id) { @order.id }
end
# it {
# expect(JSON.parse(response.body)['product_snapshots'].count).to eq(@order.snapshots.count)
response
(
200
,
description:
'successful, in_cart'
)
do
# }
let
(
:in_cart
)
{
true
}
# end
it
{
expect
(
JSON
.
parse
(
response
.
body
)[
'product_snapshots'
].
count
).
to
eq
(
@cart
.
snapshots
.
count
)
# response(200, description: 'successful, in_cart') do
}
# let(:in_cart) { true }
end
# it {
end
# expect(JSON.parse(response.body)['product_snapshots'].count).to eq(@cart.snapshots.count)
# }
end
# end
# end
path
"/
#{
namespace
}
/product_snapshots/{id}"
do
parameter
:buyer_type
,
in: :query
,
type: :string
# end
parameter
:buyer_id
,
in: :query
,
type: :integer
let
(
:buyer_id
)
{
@user
.
id
}
# path "/#{namespace}/product_snapshots/{id}" do
let
(
:buyer_type
)
{
@user
.
class
.
name
}
# parameter :buyer_type, in: :query, type: :string
# parameter :buyer_id, in: :query, type: :integer
let
(
:id
)
{
@snapshot_1
.
id
}
# let(:buyer_id) { @user.id }
# let(:buyer_type) { @user.class.name }
get
(
summary:
'商户 商品快照的详情'
)
do
produces
'application/json'
# let(:id) { @snapshot_1.id }
consumes
'application/json'
response
(
200
,
description:
'successful'
)
do
# get(summary: '商户 商品快照的详情') do
it
{
expect
(
JSON
(
response
.
body
)[
'total_price'
]).
to
eq
(
'%.1f'
%
@snapshot_1
.
total_price
)
}
# produces 'application/json'
end
# consumes 'application/json'
end
# response(200, description: 'successful') do
end
# it { expect(JSON(response.body)['total_price']).to eq('%.1f'% @snapshot_1.total_price) }
# end
# path "/#{namespace}/product_series/{product_series_id}/product_snapshots" do
# end
# parameter :product_series_id, in: :path, type: :integer
# end
# parameter :order_id, in: :path, type: :string
# parameter :in_cart, in: :path, type: :boolean
# # path "/#{namespace}/product_series/{product_series_id}/product_snapshots" do
# # parameter :product_series_id, in: :path, type: :integer
# let(:product_series_id) { @series_1.id }
# # parameter :order_id, in: :path, type: :string
# # parameter :in_cart, in: :path, type: :boolean
# get(summary: '用户 快照列表 三参数可仍以任意组合') do
# # let(:product_series_id) { @series_1.id }
# parameter :page, in: :query, type: :string
# parameter :per_page, in: :query, type: :string
# # get(summary: '用户 快照列表 三参数可仍以任意组合') do
# let(:page) { 1 }
# # parameter :page, in: :query, type: :string
# let(:per_page) { 100 }
# # parameter :per_page, in: :query, type: :string
# produces 'application/json'
# # let(:page) { 1 }
# consumes 'application/json'
# # let(:per_page) { 100 }
# response(200, description: 'successful') do
# it {
# # produces 'application/json'
# expect(JSON.parse(response.body)['product_snapshots'].count).to eq(1)
# # consumes 'application/json'
# }
# # response(200, description: 'successful') do
# end
# # it {
# end
# # expect(JSON.parse(response.body)['product_snapshots'].count).to eq(1)
# # }
# post(summary: '用户 创建快照 ') do
# # end
# # end
# parameter :product_snapshot, in: :body, schema: {
# type: :object, properties: {
# # post(summary: '用户 创建快照 ') do
# product_snapshot: {
# type: :object, properties: {
# # parameter :product_snapshot, in: :body, schema: {
# count: { type: :integer },
# # type: :object, properties: {
# buyer_id: { type: :integer },
# # product_snapshot: {
# buyer_type: { type: :string },
# # type: :object, properties: {
# }
# # count: { type: :integer },
# }
# # buyer_id: { type: :integer },
# }
# # buyer_type: { type: :string },
# }
# # }
# produces 'application/json'
# # }
# consumes 'application/json'
# # }
# response(200, description: 'successful') do
# # }
# let(:product_snapshot) {
# # produces 'application/json'
# {
# # consumes 'application/json'
# product_snapshot: {
# # response(200, description: 'successful') do
# count: 10,
# # let(:product_snapshot) {
# buyer_id: @user.id,
# # {
# buyer_type: @user.class.name,
# # product_snapshot: {
# }
# # count: 10,
# }
# # buyer_id: @user.id,
# }
# # buyer_type: @user.class.name,
# it {
# # }
# expect(JSON.parse(response.body)[':shotengai_series_id']).to eq(@series_1.id)
# # }
# expect(JSON.parse(response.body)['count']).to eq(10)
# # }
# }
# # it {
# end
# # expect(JSON.parse(response.body)[':shotengai_series_id']).to eq(@series_1.id)
# end
# # expect(JSON.parse(response.body)['count']).to eq(10)
# # }
# end
# # end
# # end
# path "/#{namespace}/orders/{order_id}/product_snapshots" do
# parameter :order_id, in: :path, type: :string
# # end
# let(:order_id) { @order.id }
# # path "/#{namespace}/orders/{order_id}/product_snapshots" do
# get(summary: '用户 (某订单中) 的快照列表') do
# # parameter :order_id, in: :path, type: :string
# # let(:order_id) { @order.id }
# parameter :page, in: :query, type: :string
# parameter :per_page, in: :query, type: :string
# # get(summary: '用户 (某订单中) 的快照列表') do
# let(:page) { 1 }
# # parameter :page, in: :query, type: :string
# let(:per_page) { 100 }
# # parameter :per_page, in: :query, type: :string
# produces 'application/json'
# # let(:page) { 1 }
# consumes 'application/json'
# # let(:per_page) { 100 }
# response(200, description: 'successful') do
# it {
# # produces 'application/json'
# expect(JSON.parse(response.body)['product_snapshots'].count).to eq(2)
# # consumes 'application/json'
# }
# # response(200, description: 'successful') do
# end
# # it {
# end
# # expect(JSON.parse(response.body)['product_snapshots'].count).to eq(2)
# end
# # }
# # end
# path "/#{namespace}/product_series/{product_series_id}/product_snapshots/{id}" do
# # end
# parameter :product_series_id, in: :path, type: :string
# # end
# parameter :id, in: :path, type: :string
# # path "/#{namespace}/product_series/{product_series_id}/product_snapshots/{id}" do
# let(:product_series_id) { @series_1.id }
# # parameter :product_series_id, in: :path, type: :string
# let(:id) { @snapshot_1.id }
# # parameter :id, in: :path, type: :string
# get(summary: '商户 商品快照的详情') do
# # let(:product_series_id) { @series_1.id }
# produces 'application/json'
# # let(:id) { @snapshot_1.id }
# consumes 'application/json'
# response(200, description: 'successful') do
# # get(summary: '商户 商品快照的详情') do
# it { expect(JSON(response.body)['product_status_zh']).to eq('未上架'), 'check product_status_zh' }
# # produces 'application/json'
# end
# # consumes 'application/json'
# end
# # response(200, description: 'successful') do
# # it { expect(JSON(response.body)['product_status_zh']).to eq('未上架'), 'check product_status_zh' }
# patch(summary: 'update product_snapshot 修改 revised_amount') do
# # end
# produces 'application/json'
# # end
# consumes 'application/json'
# # patch(summary: 'update product_snapshot 修改 revised_amount') do
# parameter :product_snapshot, in: :body, schema: {
# # produces 'application/json'
# type: :object, properties: {
# # consumes 'application/json'
# product_snapshot: {
# type: :object, properties: {
# # parameter :product_snapshot, in: :body, schema: {
# revised_amount: { type: :decimal }
# # type: :object, properties: {
# }
# # product_snapshot: {
# }
# # type: :object, properties: {
# }
# # revised_amount: { type: :decimal }
# }
# # }
# # }
# response(200, description: 'successful') do
# # }
# let(:product_snapshot) {
# # }
# { product_snapshot: { revised_amount: 233 } }
# }
# # response(200, description: 'successful') do
# it 'revised_amount as the total_price' do
# # let(:product_snapshot) {
# expect(@snapshot_1.reload.revised_amount).to eq(233)
# # { product_snapshot: { revised_amount: 233 } }
# end
# # }
# end
# # it 'revised_amount as the total_price' do
# # expect(@snapshot_1.reload.revised_amount).to eq(233)
# response(403, description: 'failed, can update a snapshot of unpaid order only ') do
# # end
# let(:product_snapshot) {
# # end
# { product_snapshot: { revised_amount: 233 } }
# }
# # response(403, description: 'failed, can update a snapshot of unpaid order only ') do
# before { @snapshot_1.order.pay! }
# # let(:product_snapshot) {
# # { product_snapshot: { revised_amount: 233 } }
# it 'revised_amount as the total_price' do
# # }
# expect(response.status).to eq(403)
# # before { @snapshot_1.order.pay! }
# end
# end
# # it 'revised_amount as the total_price' do
# end
# # expect(response.status).to eq(403)
# end
# # end
end
# # end
# # end
# # end
# end
lib/generators/templates/spec/requests/merchant/product_snapshot_spec.rb
View file @
970bb3d2
...
@@ -27,7 +27,7 @@ RSpec.describe "#{namespace}/product_snapshots", type: :request, capture_example
...
@@ -27,7 +27,7 @@ RSpec.describe "#{namespace}/product_snapshots", type: :request, capture_example
@snapshot_other
=
create
(
:product_snapshot
,
series:
@series_2
,
count:
5
)
@snapshot_other
=
create
(
:product_snapshot
,
series:
@series_2
,
count:
5
)
@order
=
create
(
:order
)
@order
=
create
(
:order
)
@cart
=
Order
::
Cart
.
create!
@cart
=
create
(
:user
).
order_cart
@snapshot_1
.
update!
(
order:
@order
)
@snapshot_1
.
update!
(
order:
@order
)
@snapshot_other
.
update!
(
order:
@order
)
@snapshot_other
.
update!
(
order:
@order
)
@snapshot_2
.
update!
(
order_cart:
@cart
)
@snapshot_2
.
update!
(
order_cart:
@cart
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment