From 3f73689fd341a0ce5a4f0ca96f7520751230d7fa Mon Sep 17 00:00:00 2001 From: loic Date: Mon, 8 Jan 2018 19:55:52 +0100 Subject: [PATCH] creating an order should activate promotions --- api/app/controllers/spree/api/orders_controller.rb | 2 +- .../requests/spree/api/orders_controller_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/app/controllers/spree/api/orders_controller.rb b/api/app/controllers/spree/api/orders_controller.rb index b52f9491444..cc112f3be72 100644 --- a/api/app/controllers/spree/api/orders_controller.rb +++ b/api/app/controllers/spree/api/orders_controller.rb @@ -33,7 +33,7 @@ def create respond_with(@order, default_template: :show, status: 201) else @order = Spree::Order.create!(user: current_api_user, store: current_store) - if OrderUpdateAttributes.new(@order, order_params).apply + if @order.contents.update_cart order_params respond_with(@order, default_template: :show, status: 201) else invalid_resource!(@order) diff --git a/api/spec/requests/spree/api/orders_controller_spec.rb b/api/spec/requests/spree/api/orders_controller_spec.rb index b69493d216e..e41c7bbad44 100644 --- a/api/spec/requests/spree/api/orders_controller_spec.rb +++ b/api/spec/requests/spree/api/orders_controller_spec.rb @@ -76,6 +76,20 @@ module Spree end end end + + context "with existing promotion" do + let(:discount) { 2 } + before do + create(:promotion, :with_line_item_adjustment, apply_automatically: true, adjustment_rate: discount ) + end + + it "activates the promotion" do + post spree.api_orders_path, params: { order: { line_items: { "0" => { variant_id: variant.to_param, quantity: 1 } } } } + order = Order.last + line_item = order.line_items.first + expect(order.total).to eq(line_item.price - discount) + end + end end context "when the current user can administrate the order" do