Openfoodnetwork: [Spree Upgrade][FrontOffice] Fix restart checkout spec in checkout_controller (1 broken test)

Created on 13 Nov 2018  路  9Comments  路  Source: openfoodfoundation/openfoodnetwork

fix checkout controller restart spec.

First a shipment needs to be set in the order instead of the shipping_method_id, for example:
order.shipments << shipment_pending
instead of
order.update_attribute(:shipping_method_id, shipment_pending.shipping_method_id)

But afterwards all the assertions need to be verified or adapted.

16) CheckoutController#restart_checkout when the order is already in the 'cart' state does nothing
      Failure/Error: order.update_attribute(:shipping_method_id, shipment_pending.shipping_method_id)

      NoMethodError:
        undefined method `shipping_method_id' for #<Spree::Shipment:0x00555812914b68>
      # ./spec/controllers/checkout_controller_spec.rb:226:in `block (3 levels) in <top (required)>'

  17) CheckoutController#restart_checkout when the order is in a subsequent state resets the order state, and clears incomplete shipments and payments
      Failure/Error: order.update_attribute(:shipping_method_id, shipment_pending.shipping_method_id)

      NoMethodError:
        undefined method `shipping_method_id' for #<Spree::Shipment:0x007f80d03b1520>
      # ./spec/controllers/checkout_controller_spec.rb:226:in `block (3 levels) in <top (required)>'

All 9 comments

Related to #2683

I got a bit stuck on

https://github.com/openfoodfoundation/openfoodnetwork/blob/f593a700002cc899afeb5f8bc63a8f481ca1e7c5/spec/controllers/checkout_controller_spec.rb#L244-L258

IMO it depends too much on the actual state of the DB, payments, the order, etc. it's very hard to foresee them all. I suggest we extract the following

https://github.com/openfoodfoundation/openfoodnetwork/blob/f593a700002cc899afeb5f8bc63a8f481ca1e7c5/app/controllers/checkout_controller.rb#L161-L168

on a class and then, we test there in isolation. I'll be quicker.

yes, sounds good.
services/checkout_restart.rb ;-)

but maybe better in master first, right?

this issue is directly related to #3027

3130 has been merged but AFAIK this issue is still open.

3130 is not in 2-0-stable yet (#3199 was merged in 2-0 before #3130 was merged to master).

so we need to wait for the next merge of master to 2-0 (I'll do it this week).
and then see if this issue is still there.

btw, there's only one broken test related to this in 2-0-stable now: spec/controllers/checkout_controller_spec.rb:281
```
8) CheckoutController#restart_checkout when the order is in a subsequent state resets the order state, and clears incomplete shipments and payments
Failure/Error: expect(order.shipping_method_id).to_not be nil

   expected not #<NilClass:8> => nil
            got #<NilClass:8> => nil

   Compared using equal?, which compares object identity.
 # ./spec/controllers/checkout_controller_spec.rb:283:in `block (4 levels) in <top (required)>'

```

This was fixed by the merge #3228

Vamooss :muscle:

Was this page helpful?
0 / 5 - 0 ratings