bcardarella/client_side_validations — Issue #292: case sensitive and scope active validation fails with mysql database
Author: jmaniv
Created: 2012-03-07 16:09:45+00:00
State: open

My Environment:
```Rails 3.0.9, Ruby 1.9.2p290, Rubygem 1.8.8, mysql2 (0.2.7) and client_side_validations (3.1.0).
Database is MySQL.```

User model
```validates :name, :code, :presence => {:message => "Value needed"},
:uniqueness => {:case_sensitive => false, :scope => :active }```

Problem 1: uniqueness failed due to boolean value passed as string. :scope => :active creates the sql query as
```Select 1 from users where name = 'Yyy' and active = 'true' ```.
Above query fails to execute in MySQL database but gem assuming record not found and then allow to submit.
```Error was : truncated incorrect DOUBLE value: 'true'```
Below query will work fine
```Select 1 from users where name = 'Yyy' and active = true```
may be it is seems like string value 'true' instead of boolean value true

Problem 2: case sensitive fails
I Inspected rails and gem query for both case sensitive true and false state for your reference
a) :case_sensitive => false
GEM generate query as:
```SELECT 1 FROM users WHERE name LIKE 'Yyy'```
RAILS generate query as:
```SELECT 1 FROM users WHERE LOWER(name) = LOWER('Yyy')```

b) :case_sensitive => true
GEM generate query as:
```SELECT 1 FROM users WHERE name = 'YyY'```
RAILS generate query as:
```SELECT 1 FROM users WHERE name = BINARY 'YyY'```