Skip to content

Commit

Permalink
Merge pull request #1905 from solidusio/remove-unnecessary-before-com…
Browse files Browse the repository at this point in the history
…plete-callback

Remove unnecessary shipping rates callback
  • Loading branch information
mamhoff authored Jun 21, 2017
2 parents 36d213d + 97a01b9 commit c293926
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
3 changes: 0 additions & 3 deletions core/app/models/spree/order/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def define_state_machine!
# calls matter so that we do not process payments
# until validations have passed
before_transition to: :complete, do: :validate_line_item_availability
if states[:delivery]
before_transition to: :complete, do: :ensure_available_shipping_rates
end
before_transition to: :complete, do: :ensure_promotions_eligible
before_transition to: :complete, do: :ensure_line_item_variants_are_not_deleted
before_transition to: :complete, do: :ensure_inventory_units
Expand Down
16 changes: 0 additions & 16 deletions core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,22 +589,6 @@ def assert_state_changed(order, from, to)
end
end

context 'a shipment has no shipping rates' do
let(:order) { create(:order_with_line_items, state: 'confirm') }
let(:shipment) { order.shipments.first }

before do
shipment.shipping_rates.destroy_all
end

it 'clears the shipments and fails the transition' do
expect(order.complete).to eq(false)
expect(order.errors[:base]).to include(Spree.t(:items_cannot_be_shipped))
expect(order.shipments.count).to eq(0)
expect(Spree::InventoryUnit.where(shipment_id: shipment.id).count).to eq(0)
end
end

context 'the order is already paid' do
let(:order) { create(:order_with_line_items) }

Expand Down
31 changes: 5 additions & 26 deletions frontend/spec/controllers/spree/checkout_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,39 +330,18 @@ def post_address
expect(response).to redirect_to(spree.checkout_state_path('address'))
end
end
end

context "fails to transition to complete from confirm" do
let(:order) do
FactoryGirl.create(:order_with_line_items).tap(&:next!)
end

before do
allow(controller).to receive_messages current_order: order
allow(controller).to receive_messages check_authorization: true
end

context "when the country is not a shippable country" do
before do
order.ship_address.tap do |address|
# A different country which is not included in the list of shippable countries
australia = create(:country, name: "Australia")
# update_columns to get around readonly restriction when testing
address.update_columns(country_id: australia.id, state_name: 'Victoria')
end
let(:foreign_address) { create(:address, country_iso_code: "CA") }

payment_method = FactoryGirl.create(:simple_credit_card_payment_method)
payment = FactoryGirl.create(:payment, payment_method: payment_method)
order.payments << payment
before do
order.update(shipping_address: foreign_address)
end

it "due to no available shipping rates for any of the shipments" do
expect(order.shipments.count).to eq(1)
order.shipments.first.shipping_rates.delete_all
order.update_attributes(state: 'confirm')
put :update, params: { state: order.state, order: {} }
put :update, params: { state: "address", order: {} }
expect(flash[:error]).to eq(Spree.t(:items_cannot_be_shipped))
expect(response).to redirect_to(spree.checkout_state_path('confirm'))
expect(response).to redirect_to(spree.checkout_state_path('address'))
end
end
end
Expand Down

0 comments on commit c293926

Please sign in to comment.