alphagov/whitehall — pull request #256 by h-lame (2013-02-21 10:20:35+00:00)
Title: Extract image size checking to an lib class and disable it in tests

We noticed that our tests eat a lot of memory, and on a resource constrained VM this can mean we get failures because of running out of memory. The major cause of the errors in this case seemed to be from the validation on image_data, person, classification_featuring_image_data, edition_organisation_image_data, and edition_world_location_image_data that checks what size the image is.

To try and solve this we extract the bulk of the code from those validations to ImageSizeChecker.new.size_is? in lib, and then use any_instance stubbing to make it always return true. We unstub this for those few tests that actually want to exercise the method for real.

In unscientific testing on my machine this reduced the unit test duration from 261s to 232s.