spree/spree — pull request #3131 by sohara (2013-05-31 03:55:25+00:00)
Title: Add nil object check for StockLocation#fill_status

The StockLocation#fill_status assumes that there each StockLocation has a StockItem for every Variant. However, in our app, after db migration to Spree 2, we have stock locations that have no stock items. I am uncertain if this is due to a missing (not yet written) migration, or whether the assumption is unreliable.

This [after create method](https://github.com/spree/spree/blob/master/core/app/models/spree/variant.rb#L174) seems to imply that in fact there should be a stock_item in each stock_location for each variant and there is a corresponding after_create method in StockLocation.

I wonder if it will be difficult to track all legacy and newly created variants, as well as newly created StockLocations, to ensure that the assumption holds.

If we don't want to depend on that we could use this nil object check. Otherwise we should revisit the spree 2 migrations and see what is missing.

cc @cmar