Fix issue with nil current_order where shipping_method serializer requires a current_order to calculate the shipping fees

This commit is contained in:
luisramos0
2019-09-24 16:57:48 +01:00
parent 2f60a85593
commit baa09b88f7
2 changed files with 9 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ module Api
class OrdersController < BaseController
def show
authorize! :read, order
render json: order, serializer: Api::OrderDetailedSerializer
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
end
def index

View File

@@ -218,8 +218,16 @@ module Api
expect_order
end
it "can view an order with weight calculator (this validates case where options[current_order] is nil on the shipping method serializer)" do
order.shipping_method.update_attribute(:calculator, create(:weight_calculator, calculable: order))
allow(controller).to receive(:current_order).and_return order
get :show, id: order.number
expect_order
end
it "returns an order with all required fields" do
get :show, id: order.number
expect_order
expect(json_response.symbolize_keys.keys).to include(*order_detailed_attributes)