Refactor machine controller

This patchset adds tests for and refactors (mostly removes duplicates) MachinesController.

In 3e8659f, tests are added, making sure that we don't break its API.

The only change in functionality is in 60d9460 - before, ```session[:domain]``` was set only for the ```list```, ```index``` and ```show``` actions. However, this appears to be a bug - if user / client would hit any other action first, then, due to the missing domain, the node name would not be correctly set and the corresponding node object might not be found. So this patch makes sure that the ```session[:domain]``` is set for every action (if it hasn't been set yet).

I also noticed two more possible issues (but I'm not sure if they indeed pose a real problem, so feel free to discuss):

1. The response code is 200 even if e.g. ```machine.reboot``` fails, making it hard to detect that something went wrong.
2. 404 responses are plain text, not JSON as the 200s. This might possibly cause client to fail if it decides to parse the response (e.g. to get an error text).