Fix calculate_price when order_item without product is provided
This commit is contained in:
parent
0581a7238d
commit
e9aa52736a
2 changed files with 2 additions and 2 deletions
|
@ -36,7 +36,7 @@ class Order < ActiveRecord::Base
|
|||
private
|
||||
|
||||
def calculate_price
|
||||
self.price_cents = self.order_items.map{ |oi| oi.count * oi.product.price_cents }.sum
|
||||
self.price_cents = self.order_items.map{ |oi| oi.count * (oi.product.try(:price_cents) || 0) }.sum
|
||||
end
|
||||
|
||||
def create_api_job
|
||||
|
|
|
@ -48,7 +48,7 @@ describe Order do
|
|||
|
||||
describe 'order_items' do
|
||||
it 'should be validated' do
|
||||
@order.order_items << OrderItem.new(count: -5)
|
||||
@order.order_items.build(count: -5)
|
||||
expect(@order).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue