mbleigh/acts-as-taggable-on — pull request #496 by leklund (2014-03-19 15:55:43+00:00)
Title: Use group rather than distinct or .uniq when using tagged_with(any:true). Fixes PostgreSQL errors

__Summary:__ ```SELECT DISTINCT foo.* FROM foo``` breaks in PostgreSQL when foo has a column with json datatype. acts-as-taggable-on uses distinct to get unique results when using any: true. However, this pull request: https://github.com/mbleigh/acts-as-taggable-on/pull/461, introduced a bug so that every call to Model.tagged_with('foo') would use the ```.uniq``` method which adds a ```SELECT DISTINCT``` the the query. #461 was attempting to fix #357 but moving the explicit distinct to a ```.uniq``` only fixed certain collisions with other gems.

The 'distinct' bug in action: https://gist.github.com/leklund/9643920

The error raised is ```PG::UndefinedFunction: ERROR: could not identify an equality operator for type json``` because the distinct is unnecessarily comparing every column on the table using the equality operator.

__What does this pull request add?__

* changes the ```.uniq``` for any to use a group by the primary key of the table. This avoids the wildcard distinct.
* test to expose the bug introduce by #461 that calls 'distinct' on every query generated from ```tagged_with```
* tests for postgresql specific tables with json columns
* fixes an intermittently failing test in postgresql (one of the exclude tests was expecting a certain order back from the database and wasn't always getting that order).