Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary shipping rates callback #1905

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -323,39 +323,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