Refactor tests and remove duplicated ones

This commit is contained in:
Pau Perez
2017-07-18 12:12:46 +02:00
committed by Rob Harrington
parent a18bf4b666
commit 1ef4bf5da0
3 changed files with 16 additions and 37 deletions

View File

@@ -84,6 +84,12 @@ describe CheckoutController do
order.should_receive(:ship_address=)
controller.send(:clear_ship_address)
end
it "sets the new order's token to the same as the old order" do
order = controller.current_order(true)
spree_post :update, order: {}
expect(controller.current_order.token).to eq order.token
end
end
context "via xhr" do

View File

@@ -4,46 +4,19 @@ require 'support/request/authentication_workflow'
describe Spree::CheckoutController do
context "After completing an order" do
let!(:order) { controller.current_order(true) }
context 'rendering edit from within spree for the current checkout state' do
let(:order) { controller.current_order(true) }
let(:user) { create(:user) }
it "creates a new empty order" do
controller.reset_order
expect(controller.session[:order_id]).not_to be_nil
before do
create(:line_item, order: order)
allow(controller).to receive(:skip_state_validation?) { true }
allow(controller).to receive(:spree_current_user) { user }
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
expect(spree_get(:edit)).to redirect_to checkout_path
end
end
end

View File

@@ -41,7 +41,7 @@ describe ResetOrderService do
expect(controller.instance_variable_get(:@current_order)).to be_nil
end
it 'sets the distributor of the order' do
it 'sets the new order\'s distributor to the same as the old order' do
reset_order_service.call
expect(new_order)