validate_uniqueness_of does not quote scoped values when
constructing the SQL query, so if the scoped column happens to be
text, you get a PGError. (PostgreSQL 8.2 server did not
complain)
class Group < ActiveRecord::Base
# name, section, and subsection are all text columns
validates_uniqueness_of :name, :scope => [:section, :subsection]
end
class GroupTest < ActiveSupport::TestCase
# blows up with PGError
should validate_uniqueness_of(:name).scoped_to([:section, :subsection])
end
Here is the specific error from the database:
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: character varying = integer
LINE 1: ..."groups"."name" = E'09-01' AND "groups".section = 1 AND "g...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I have written a patch against ActiveRecord::Validations (see
attached). I would gladly write tests too, but I'm running on
Gentoo, which does not know about libxml2-dev or libxslt1-dev, and
"gem install bundler" is timing out right now, too. So I don't have
a formal test setup (but my patch works in the above case).