mysociety/planningalerts-app — pull request #85 by stevenday (2014-10-27 17:30:47+00:00)
Title: Refactor search controller to use a model as backing

This refactors the search controller to use an ActiveModel object to back the
search form and handle form validation and transformation of the inputs into
an appropriate search. This simplifies the controller, allowing it to focus on
display concerns only. It also allows us to introduce an object which can be
overwritten/inherited on a theme basis, as searching is likely to be quite
different in different themes.

Note: the thing I'm not totally happy with is that you *have* to call valid?
on the search object in order to make it call mapit to populate the lat/lng.
I consulted a few rails devs and the consensus was that this was the lesser of
two evils (the other option being doing it in `initialize`) but it still sucks
a bit.

As part of this I also snuck in a few other improvements:
- lots more tests of the search processing logic
- use of commonlib's MapIt library functions instead of calling it directly
- simplification of the controller display logic
- improving how the Hants capybara features use VCR to make refactoring easier
- better error messages when the postcode/address is not valid

There are a couple of minor changes to the search views because we now get a
search object to play with that has useful methods like `is_location_search?`
and `valid?/invalid?`. I've ticketed a bigger one in #82 but since this
already took me way longer than I expected I decided to not include that in
this PR.

Closes #81