Removed unnecessary currency from CartService constructor, using order.currency instead

This commit is contained in:
luisramos0
2018-08-16 22:13:16 +01:00
parent ec069b1e3e
commit 910297572e
5 changed files with 11 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ class CartController < BaseController
# costly Spree::Order#update!, which only needs to be run once. We avoid this by disabling
# callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success.
Spree::Adjustment.without_callbacks do
cart_service = CartService.new(current_order(true), current_currency)
cart_service = CartService.new(current_order(true))
if cart_service.populate(params.slice(:products, :variants, :quantity), true)
fire_event('spree.cart.add')

View File

@@ -5,9 +5,9 @@ class CartService
attr_reader :variants_h
attr_reader :errors
def initialize(order, currency)
def initialize(order)
@order = order
@currency = currency
@currency = order.currency
@errors = ActiveModel::Errors.new(self)
end

View File

@@ -36,7 +36,7 @@ describe ProductDistribution do
# When I add the product to the order, an adjustment should be made
expect do
cart_service = CartService.new order, 'AU'
cart_service = CartService.new order
cart_service.populate products: {product.id => product.master.id}, quantity: 1, distributor_id: distributor.id
# Normally the controller would fire this event when the order's contents are changed

View File

@@ -6,13 +6,17 @@ describe CartService do
let(:params) { {} }
let(:distributor) { double(:distributor) }
let(:order_cycle) { double(:order_cycle) }
let(:cart_service) { CartService.new(order, currency) }
let(:cart_service) { CartService.new(order) }
before do
allow(order).to receive(:currency).and_return( currency )
end
context "end-to-end" do
let(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
let(:distributor) { create(:distributor_enterprise) }
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [v]) }
let(:cart_service) { CartService.new(order, nil) }
let(:cart_service) { CartService.new(order) }
let(:v) { create(:variant) }
describe "populate" do

View File

@@ -17,7 +17,7 @@ module ShopWorkflow
end
def add_product_to_cart(order, product, quantity: 1)
cart_service = CartService.new(order, order.currency)
cart_service = CartService.new(order)
cart_service.populate(variants: {product.variants.first.id => quantity})
# Recalculate fee totals