Spec for GroupsController and some refactoring

[Skip ci]