Skip to content

Commit

Permalink
only redirect to the customer details page if we are missing a billing
Browse files Browse the repository at this point in the history
address [Fixes solidusio#3182]
  • Loading branch information
kylecrum authored and GeekOnCoffee committed Jun 12, 2013
1 parent 154ca74 commit b504cc7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
8 changes: 1 addition & 7 deletions backend/app/controllers/spree/admin/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,8 @@ def load_data
@previous_cards = @order.credit_cards.with_payment_profile
end

# At this point admin should have passed through Customer Details step
# where order.next is called which leaves the order in payment step
#
# Orders in complete step also allows to access this controller
#
# Otherwise redirect user to that step
def can_transition_to_payment
unless @order.payment? || @order.complete?
unless @order.billing_address.present?
flash[:notice] = Spree.t(:fill_in_customer_info)
redirect_to edit_admin_order_customer_url(@order)
end
Expand Down
38 changes: 26 additions & 12 deletions backend/spec/controllers/spree/admin/payments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,42 @@ module Admin

let(:order) { create(:order) }

before do
Spree::Order.stub find_by_number!: order
order.stub(:payment_required? => true)
end
context "order has billing address" do

context "order has no payments" do
context "passed through customer details step" do
before { order.stub(state: "payment") }
before do
order.bill_address = create(:address)
order.save!
end

context "order does not have payments" do
it "redirect to new payments page" do
spree_get :index, { amount: 100 }
spree_get :index, { amount: 100, order_id: order.number }
response.should redirect_to(spree.new_admin_order_payment_path(order))
end
end

context "try to skip customer details step" do
it "redirect to customer details step" do
spree_get :index, { amount: 100 }
response.should redirect_to(spree.edit_admin_order_customer_path(order))
context "order has payments" do

before do
order.payments << create(:payment, amount: order.total, order: order, state: 'completed')
end

it "shows the payments page" do
spree_get :index, { amount: 100, order_id: order.number }
expect(response.code).to eq "200"
end
end

end

context "order does not have a billing address" do

it "should redirect to the customer details page" do
spree_get :index, { amount: 100, order_id: order.number }
expect(response).to redirect_to(spree.edit_admin_order_customer_path(order))
end
end

end
end
end

0 comments on commit b504cc7

Please sign in to comment.