refactored for supporting ActiveSupport 3+ and refactored testing