aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/base.rb15
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb17
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb6
-rw-r--r--activerecord/test/cases/validations_test.rb8
4 files changed, 24 insertions, 22 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f4f07aa740..0cce1e0157 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -612,7 +612,7 @@ module ActiveRecord #:nodoc:
# Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
# > [#<Post:0x36bff9c @attributes={"first_name"=>"The Cheap Man Buys Twice"}>, ...]
def find_by_sql(sql)
- connection.select_all(sanitize_sql(sql), "#{name} Load").map { |record| instantiate(record) }
+ connection.select_all(sanitize_sql(sql), "#{name} Load").collect! { |record| instantiate(record) }
end
# Checks whether a record exists in the database that matches conditions given. These conditions
@@ -2572,14 +2572,11 @@ module ActiveRecord #:nodoc:
end
def convert_number_column_value(value)
- if value == false
- 0
- elsif value == true
- 1
- elsif value.is_a?(String) && value.blank?
- nil
- else
- value
+ case value
+ when FalseClass; 0
+ when TrueClass; 1
+ when ''; nil
+ else value
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
index 81a2e56b34..2afd6064ad 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -72,12 +72,21 @@ module ActiveRecord
private
def cache_sql(sql)
- if @query_cache.has_key?(sql)
- log_info(sql, "CACHE", 0.0)
- @query_cache[sql]
+ result =
+ if @query_cache.has_key?(sql)
+ log_info(sql, "CACHE", 0.0)
+ @query_cache[sql]
+ else
+ @query_cache[sql] = yield
+ end
+
+ if Array === result
+ result.collect { |row| row.dup }
else
- @query_cache[sql] = yield.freeze
+ result.duplicable? ? result.dup : result
end
+ rescue TypeError
+ result
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 08b2c79389..31d6c7942c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -138,11 +138,7 @@ module ActiveRecord
# convert something to a boolean
def value_to_boolean(value)
- if value.blank?
- nil
- else
- TRUE_VALUES.include?(value)
- end
+ TRUE_VALUES.include?(value)
end
# convert something to a BigDecimal
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index a40bda2533..4b2d28c80b 100644
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -1420,8 +1420,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
def test_validates_numericality_of_with_nil_allowed
Topic.validates_numericality_of :approved, :allow_nil => true
- invalid!(JUNK)
- valid!(NIL + BLANK + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
+ invalid!(BLANK + JUNK)
+ valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
end
def test_validates_numericality_of_with_integer_only
@@ -1434,8 +1434,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
def test_validates_numericality_of_with_integer_only_and_nil_allowed
Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
- invalid!(JUNK + FLOATS + BIGDECIMAL + INFINITY)
- valid!(NIL + BLANK + INTEGERS)
+ invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
+ valid!(NIL + INTEGERS)
end
def test_validates_numericality_with_greater_than