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
85c8abfc
Commit
85c8abfc
authored
Sep 27, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the stock validation of series
parent
eb7f797e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
series.rb
lib/shotengai/series.rb
+3
-6
models_spec.rb
spec/shotengai/models_spec.rb
+3
-0
No files found.
lib/shotengai/series.rb
View file @
85c8abfc
...
@@ -28,7 +28,6 @@ module Shotengai
...
@@ -28,7 +28,6 @@ module Shotengai
validate
:check_remark
validate
:check_remark
# Using validates_uniqueness_of do not work if the order of Hash is diff
# Using validates_uniqueness_of do not work if the order of Hash is diff
validate
:uniq_spec
validate
:uniq_spec
validate
:validate_stock
hash_columns
:spec
,
:meta
,
:remark
hash_columns
:spec
,
:meta
,
:remark
...
@@ -86,7 +85,9 @@ module Shotengai
...
@@ -86,7 +85,9 @@ module Shotengai
end
end
def
cut_stock
count
def
cut_stock
count
self
.
stock
.
eql?
(
-
1
)
||
self
.
update!
(
stock:
self
.
stock
-
count
)
return
true
if
self
.
stock
.
eql?
(
-
1
)
raise
Shotengai
::
WebError
.
new
(
'该商品系列库存不足.'
,
-
1
,
400
)
unless
(
stock
=
self
.
stock
-
count
)
>=
0
self
.
update!
(
stock:
stock
)
end
end
def
original_price
def
original_price
...
@@ -119,9 +120,5 @@ module Shotengai
...
@@ -119,9 +120,5 @@ module Shotengai
errors
.
add
(
:spec
,
'Non uniq spec for the product.'
)
errors
.
add
(
:spec
,
'Non uniq spec for the product.'
)
end
end
end
end
def
validate_stock
errors
.
add
(
:stock
,
'该商品系列库存不足.'
)
unless
self
.
stock_was
.
eql?
(
-
1
)
||
self
.
stock
>=
0
end
end
end
end
end
spec/shotengai/models_spec.rb
View file @
85c8abfc
...
@@ -20,6 +20,9 @@ RSpec.describe 'Shotengai Models' do
...
@@ -20,6 +20,9 @@ RSpec.describe 'Shotengai Models' do
ActiveRecord
::
Migration
[
5.1
].
subclasses
.
each
do
|
migrate
|
ActiveRecord
::
Migration
[
5.1
].
subclasses
.
each
do
|
migrate
|
migrate
.
migrate
(
:up
)
migrate
.
migrate
(
:up
)
end
end
class
ApplicationRecord
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
end
end
end
describe
'Product & Order'
do
describe
'Product & Order'
do
...
...
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