Shopify/active_shipping — pull request #166 by jstorimer (2014-07-06 01:12:31+00:00)
Title: raise earlier if the maximum number of packages is exceeded

Related to #160.

@csfrancis @csaunders @costford

I saw that we're still getting the occasional OOM when fetching shipping rates ([errbit](https://github.com/Shopify/shopify/issues/22805)).

The backtrace pointed to what was line 20 in `ShipmentPacker.pack`. This line expands the `items` array to include one element to match the quantity of each item. In this case someone put a quantity of 1b in their order, so when we tried to create an Array of 1b item Hashes, (b)OOM.

I took the same exception that @csfrancis added in #160 and moved it up before line 20.

I didn't add any new tests because I couldn't think of a way to test this behaviour specifically, besides putting in some insane value that makes the test OOM should this line be removed. Not exactly easy to debug. The test coverage from #160 is still there so I'm thinking it's fine as is.