From 23750b4733e1d8e7ef334d70998258d1d2e2c6c8 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Wed, 31 Oct 2012 00:33:51 -0200 Subject: Simplify value logic by always typecasting --- activerecord/lib/active_record/validations/uniqueness.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index dc07645732..5700350cf9 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -67,22 +67,16 @@ module ActiveRecord end column = klass.columns_hash[attribute.to_s] - - if !value.nil? && column.text? && column.limit - value = value.to_s[0, column.limit] - else - value = klass.connection.type_cast(value, column) - end + value = klass.connection.type_cast(value, column) + value = value.to_s[0, column.limit] if value && column.limit && column.text? if !options[:case_sensitive] && value && column.text? # will use SQL LOWER function before comparison, unless it detects a case insensitive collation - relation = klass.connection.case_insensitive_comparison(table, attribute, column, value) + klass.connection.case_insensitive_comparison(table, attribute, column, value) else - value = klass.connection.case_sensitive_modifier(value) unless value.nil? - relation = table[attribute].eq(value) + value = klass.connection.case_sensitive_modifier(value) unless value.nil? + table[attribute].eq(value) end - - relation end end -- cgit v1.2.3