Adds a test and validations for circular structures.

Acts_as_tree does not check for circular structures in the models it is invoked on. With this fix, infinite tree fetching no more.