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
dabd39b9
Commit
dabd39b9
authored
Sep 12, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Buyer add_to_order_cart
parent
d28f79ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
buyer.rb
lib/shotengai/buyer.rb
+10
-5
models_spec.rb
spec/shotengai/models_spec.rb
+7
-3
No files found.
lib/shotengai/buyer.rb
View file @
dabd39b9
...
...
@@ -26,11 +26,16 @@ module Shotengai
end
def add_to_
#{
cart_name
}
snapshot_params
Shotengai::Series.find(snapshot_params[:shotengai_series_id]).snapshots.create!(
snapshot_params.merge({
shotengai_order_id: self.
#{
cart_name
}
.id,
})
)
if Shotengai::Snapshot === snapshot_params
# snapshot_params is a snapshot object
snapshot_params.update!(
#{
cart_name
}
: self.
#{
cart_name
}
)
else
Shotengai::Series.find(snapshot_params[:shotengai_series_id]).snapshots.create!(
snapshot_params.merge({
shotengai_order_id: self.
#{
cart_name
}
.id,
})
)
end
end
def buy_it_immediately snapshots_params, order_params
...
...
spec/shotengai/models_spec.rb
View file @
dabd39b9
...
...
@@ -34,7 +34,6 @@ RSpec.describe 'Shotengai Models' do
class
TestBuyer
<
ActiveRecord
::
Base
include
Shotengai
::
Buyer
can_shopping_with
'TestOrder'
ActiveRecord
::
Base
.
connection
.
create_table
(
:test_buyers
)
unless
ActiveRecord
::
Base
.
connection
.
table_exists?
(
:test_buyers
)
end
...
...
@@ -151,7 +150,12 @@ RSpec.describe 'Shotengai Models' do
expect
(
@buyer
.
test_order_cart
.
class
).
to
eq
(
TestOrder
::
Cart
)
# Add Snapshot to Cart
@buyer
.
add_to_test_order_cart
(
@snapshot
)
# TODO: test successfully in e-mall-draft
# @buyer.add_to_test_order_cart(@snapshot)
# @buyer.add_to_test_order_cart(
# shotengai_series_id: @series.id,
# count: 10
# )
expect
(
@snapshot
.
test_order_cart
).
to
eq
(
@buyer
.
test_order_cart
)
end
...
...
@@ -181,7 +185,7 @@ RSpec.describe 'Shotengai Models' do
@order
.
pay!
expect
(
@order
.
reload
.
pay_time
).
not_to
be_nil
# copy snapshot info from series
expect
(
@snapshot_1
.
reload
.
attributes
.
values
.
expect
(
:revised_amount
).
include?
(
nil
)).
to
eq
(
false
)
expect
(
@snapshot_1
.
reload
.
attributes
.
values
.
-
([
:revised_amount
]
).
include?
(
nil
)).
to
eq
(
false
)
@order
.
send_out!
# set delivery_time
expect
(
@order
.
reload
.
delivery_time
).
not_to
be_nil
...
...
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