Skip to content

Commit

Permalink
Replace update_checkout_path with checkout_path
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmendoza committed Oct 12, 2022
1 parent e1d0e72 commit bc23b2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
5 changes: 1 addition & 4 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@
resource :checkout_session, only: :new
resource :checkout_guest_session, only: :create
resource :checkout, only: :edit
# non-restful checkout stuff
patch '/checkout/update/:state', to: 'checkouts#update', as: :update_checkout
resource :checkout, only: [:edit, :update]
get '/orders/:id/token/:token' => 'orders#show', as: :token_order
Expand Down
2 changes: 1 addition & 1 deletion templates/app/views/checkouts/_checkout_step.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_for order, url: update_checkout_path(order.state), html: { id: "checkout_form_#{order.state}" } do |form| %>
<%= form_for order, url: checkout_path(state: order.state), html: { id: "checkout_form_#{order.state}" } do |form| %>
<% if order.state == "address" || !order.email? %>
<div class="text-input">
<%= form.label :email, 'Customer E-Mail:' %>
Expand Down
50 changes: 25 additions & 25 deletions templates/spec/requests/checkouts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@

it 'checks if the user is authorized for :edit' do
expect do
patch update_checkout_path(state: 'address', order: { bill_address_attributes: address_params })
patch checkout_path(state: 'address', order: { bill_address_attributes: address_params })
end.to change { order.reload.state }.from('cart').to('delivery')
end

context "save successful" do
def post_address
patch update_checkout_path(state: "address",
patch checkout_path(state: "address",
order: {
bill_address_attributes: address_params,
use_billing: true
Expand All @@ -75,7 +75,7 @@ def post_address
let!(:order) { create(:order_with_line_items, state: 'cart') }

it "assigns order" do
patch update_checkout_path(state: 'address', order: { bill_address_attributes: address_params })
patch checkout_path(state: 'address', order: { bill_address_attributes: address_params })
expect(assigns[:order]).not_to be_nil
end

Expand All @@ -93,7 +93,7 @@ def post_address
let(:order) { create(:order_with_line_items) }

def post_persist_address
patch update_checkout_path(state: "address",
patch checkout_path(state: "address",
order: {
bill_address_attributes: address_params,
use_billing: true
Expand Down Expand Up @@ -121,7 +121,7 @@ def post_persist_address
let(:order_bill_address_attributes) { order.reload.bill_address.attributes.except("created_at", "updated_at").compact }

it "tries to associate user addresses to order" do
patch update_checkout_path(state: 'address', order: { email: 'test@email.com' })
patch checkout_path(state: 'address', order: { email: 'test@email.com' })

expect(order_ship_address_attributes).to eq user_ship_address_attributes
expect(order_bill_address_attributes).to eq user_bill_address_attributes
Expand All @@ -130,7 +130,7 @@ def post_persist_address

context "when a billing and shipping address" do
subject do
patch update_checkout_path(
patch checkout_path(
state: 'address',
order: {
bill_address_attributes: order.bill_address.attributes.except("created_at", "updated_at").compact,
Expand Down Expand Up @@ -190,7 +190,7 @@ def post_persist_address
end

it 'sets the payment amount' do
patch update_checkout_path(params)
patch checkout_path(params)
order.reload
expect(order.state).to eq('new_step')
expect(order.payments.size).to eq(1)
Expand Down Expand Up @@ -218,7 +218,7 @@ def post_persist_address

context 'when a permitted payment method' do
it 'sets the payment amount' do
patch update_checkout_path(params)
patch checkout_path(params)
order.reload
expect(order.state).to eq('confirm')
expect(order.payments.size).to eq(1)
Expand All @@ -231,7 +231,7 @@ def post_persist_address

it 'sets the payment amount' do
expect do
patch update_checkout_path(params)
patch checkout_path(params)
end.to raise_error(ActiveRecord::RecordNotFound)

expect(order.state).to eq('payment')
Expand All @@ -258,7 +258,7 @@ def post_persist_address

it 'does not change the address' do
expect do
patch update_checkout_path(state: 'payment', params: params)
patch checkout_path(state: 'payment', params: params)
end.not_to(change { order.reload.ship_address.zipcode })
end
end
Expand All @@ -278,17 +278,17 @@ def post_persist_address

# This inadvertently is a regression test for https://github.com/spree/spree/issues/2694
it "redirects to the order view" do
patch update_checkout_path(state: "confirm")
patch checkout_path(state: "confirm")
expect(response).to redirect_to order_path(order)
end

it "populates the flash message" do
patch update_checkout_path(state: "confirm")
patch checkout_path(state: "confirm")
expect(flash.notice).to eq(I18n.t('spree.order_processed_successfully'))
end

it "removes completed order from current_order" do
patch update_checkout_path(state: "confirm")
patch checkout_path(state: "confirm")
expect(assigns(:current_order)).to be_nil
expect(assigns(:order)).to eql order
end
Expand All @@ -297,13 +297,13 @@ def post_persist_address

context "save unsuccessful" do
it "does not assign order" do
patch update_checkout_path(state: "address", order: { bill_address_attributes: address_params })
patch checkout_path(state: "address", order: { bill_address_attributes: address_params })
expect(assigns[:order]).not_to be_nil
end

it "renders the edit template" do
order.line_items.destroy_all
patch update_checkout_path(state: "address", order: { bill_address_attributes: address_params })
patch checkout_path(state: "address", order: { bill_address_attributes: address_params })
expect(response).to redirect_to(edit_cart_path)
end
end
Expand All @@ -313,7 +313,7 @@ def post_persist_address
let(:order) { create(:order_with_line_items, guest_token: nil, user_id: nil) }

it "redirects to the edit_cart_path" do
patch update_checkout_path(state: "confirm")
patch checkout_path(state: "confirm")
expect(response).to redirect_to edit_cart_path
end
end
Expand All @@ -326,7 +326,7 @@ def post_persist_address
before do
allow(Spree::OrderUpdater).to receive(:new).and_return(updater_instance)
allow(updater_instance).to receive(:update_payment_state).and_raise(Spree::Core::GatewayError.new('Invalid something or other.'))
patch update_checkout_path(state: order.state, order: { bill_address_attributes: address_params })
patch checkout_path(state: order.state, order: { bill_address_attributes: address_params })
end

it "renders the edit template and display exception message" do
Expand All @@ -346,7 +346,7 @@ def post_persist_address
end

it "due to the order having errors" do
patch update_checkout_path(state: order.state, order: { bill_address_attributes: address_params })
patch checkout_path(state: order.state, order: { bill_address_attributes: address_params })
expect(flash[:error]).to eq("Valid shipping address required")
expect(response).to redirect_to(edit_checkout_path(state: 'address'))
end
Expand All @@ -360,7 +360,7 @@ def post_persist_address
end

it "redirects due to no available shipping rates for any of the shipments" do
patch update_checkout_path(state: "address", order: { bill_address_attributes: address_params })
patch checkout_path(state: "address", order: { bill_address_attributes: address_params })
expect(request.flash.to_h['error']).to eq(I18n.t('spree.items_cannot_be_shipped'))
expect(response).to redirect_to(edit_checkout_path(state: 'address'))
end
Expand All @@ -374,7 +374,7 @@ def post_persist_address
before { payment_source.destroy! }

it "fails to transition from payment to complete" do
patch update_checkout_path(state: order.state, order: {})
patch checkout_path(state: order.state, order: {})
expect(flash[:error]).to eq(I18n.t('spree.payment_processing_failed'))
end
end
Expand All @@ -391,7 +391,7 @@ def post_persist_address
end

it "redirects the customer to the cart page with an error message" do
patch update_checkout_path(state: "address", order: { bill_address_attributes: address_params })
patch checkout_path(state: "address", order: { bill_address_attributes: address_params })
expect(flash[:error]).to eq(I18n.t('spree.insufficient_stock_for_order'))
expect(response).to redirect_to(edit_cart_path)
end
Expand All @@ -409,7 +409,7 @@ def post_persist_address
end

it "redirects the customer to the address checkout page with an error message" do
patch update_checkout_path(state: "address", order: { bill_address_attributes: address_params })
patch checkout_path(state: "address", order: { bill_address_attributes: address_params })
error = I18n.t('spree.inventory_error_flash_for_insufficient_shipment_quantity', unavailable_items: order.products.first.name)
expect(flash[:error]).to eq(error)
expect(response).to redirect_to(edit_checkout_path(state: :address))
Expand All @@ -430,7 +430,7 @@ def post_persist_address
before do
order
Spree::StockItem.update_all(count_on_hand: 0, backorderable: false)
patch update_checkout_path(state: "payment")
patch checkout_path(state: "payment")
end

it "redirects to cart" do
Expand Down Expand Up @@ -464,7 +464,7 @@ def post_persist_address

it "doesn't remove unshippable items before payment" do
expect do
patch update_checkout_path(state: "payment")
patch checkout_path(state: "payment")
end.to_not(change { order.line_items })
end
end
Expand All @@ -479,7 +479,7 @@ def post_persist_address

it "removes unshippable items before payment" do
expect do
patch update_checkout_path(state: "payment", order: { email: "johndoe@example.com" })
patch checkout_path(state: "payment", order: { email: "johndoe@example.com" })
end.to change { order.line_items.reload.to_a.size }.from(1).to(0)
end
end
Expand Down

0 comments on commit bc23b2d

Please sign in to comment.