Add tests, minor refactor for Rails 3 functionality