mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Spree does not call after_<order.state> methods any more as of https://github.com/spree/spree/pull/2557, so our #after_complete method is never triggered and thus the order never reset. This makes the condition: ```ruby if current_order.andand.distributor == @order.distributor ``` in app/views/spree/orders/form/_update_buttons.html.haml return false and as a result the "Back To Cart" button is not shown. This commit resets the order (emptying the session[:order_id] and creating a new order, aka. cart) right from the CheckoutController#update rather than relying on infernal callbacks (of what the Spree core team itself was unhappy about since long ago https://github.com/spree/spree/issues/2488). There is the first place where we know the order has been successfully completed.
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
require 'spec_helper'
|
|
require 'spree/api/testing_support/helpers'
|
|
require 'support/request/authentication_workflow'
|
|
|
|
|
|
describe Spree::CheckoutController do
|
|
context "After completing an order" do
|
|
let!(:order) { controller.current_order(true) }
|
|
|
|
it "creates a new empty order" do
|
|
controller.reset_order
|
|
expect(controller.session[:order_id]).not_to be_nil
|
|
end
|
|
|
|
it "clears the current order cache" do
|
|
controller.reset_order
|
|
expect(controller.current_order).not_to eq order
|
|
end
|
|
|
|
it "sets the new order's distributor to the same as the old order" do
|
|
distributor = create(:distributor_enterprise)
|
|
order.set_distributor!(distributor)
|
|
|
|
controller.reset_order
|
|
|
|
expect(controller.current_order.distributor).to eq distributor
|
|
end
|
|
|
|
it "sets the new order's token to the same as the old order, and preserve the access token in the session" do
|
|
controller.reset_order
|
|
|
|
expect(controller.current_order.token).to eq order.token
|
|
expect(session[:access_token]).to eq order.token
|
|
end
|
|
end
|
|
|
|
context "rendering edit from within spree for the current checkout state" do
|
|
let!(:order) { controller.current_order(true) }
|
|
let!(:line_item) { create(:line_item, order: order) }
|
|
let!(:user) { create(:user) }
|
|
|
|
it "redirects to the OFN checkout page" do
|
|
controller.stub(:skip_state_validation?) { true }
|
|
controller.stub(:spree_current_user) { user }
|
|
spree_get :edit
|
|
response.should redirect_to checkout_path
|
|
end
|
|
end
|
|
end
|