adds tests as per #460
Merge branch 'ql-refactor' of github.com:rethinkdb/rethinkdb into ql-refactor