aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-11 14:53:17 -0700
committerwycats <wycats@gmail.com>2010-04-11 14:53:17 -0700
commit803df08d896b82ae3e86c9c1e3c2ea4b6826ef70 (patch)
treeb813371e844a9a05ba33beb6582335d3617f66ee /activerecord
parent76e0a9eb5b5ad17d51dad5e4e8c5ea1ed504ea88 (diff)
parent1f80b8b04f9783ea7a5f39bd7ce27248bc57a851 (diff)
downloadrails-803df08d896b82ae3e86c9c1e3c2ea4b6826ef70.tar.gz
rails-803df08d896b82ae3e86c9c1e3c2ea4b6826ef70.tar.bz2
rails-803df08d896b82ae3e86c9c1e3c2ea4b6826ef70.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb7
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb3
-rw-r--r--activerecord/lib/active_record/associations/association_proxy.rb4
-rw-r--r--activerecord/lib/active_record/callbacks.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb3
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb6
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb45
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb9
-rw-r--r--activerecord/lib/active_record/serializers/xml_serializer.rb3
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb4
-rw-r--r--activerecord/test/cases/datatype_test_postgresql.rb2
12 files changed, 52 insertions, 41 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 20a8754b7c..d94cc03938 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1,5 +1,6 @@
-require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/enumerable'
+require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'
module ActiveRecord
@@ -1707,9 +1708,9 @@ module ActiveRecord
silence_warnings do
self.parent.const_set(extension_module_name, Module.new(&block_extension))
end
- Array(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
+ Array.wrap(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
else
- Array(extensions)
+ Array.wrap(extensions)
end
end
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index b808f8c306..6a4cef0d50 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -1,4 +1,5 @@
require 'set'
+require 'active_support/core_ext/array/wrap'
module ActiveRecord
module Associations
@@ -98,7 +99,7 @@ module ActiveRecord
if @target.is_a?(Array)
@target.to_ary
else
- Array(@target)
+ Array.wrap(@target)
end
end
alias_method :to_a, :to_ary
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb
index 4fb1df3ab9..b9d0fe3abe 100644
--- a/activerecord/lib/active_record/associations/association_proxy.rb
+++ b/activerecord/lib/active_record/associations/association_proxy.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module Associations
# This is the root class of all association proxies:
@@ -55,7 +57,7 @@ module ActiveRecord
@owner, @reflection = owner, reflection
@updated = false
reflection.check_validity!
- Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
+ Array.wrap(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
reset
end
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index add5d99ca6..98c14e6eb0 100644
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
# Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
# before or after an alteration of the object state. This can be used to make sure that associated and
@@ -250,7 +252,7 @@ module ActiveRecord
def before_validation(*args, &block)
options = args.last
if options.is_a?(Hash) && options[:on]
- options[:if] = Array(options[:if])
+ options[:if] = Array.wrap(options[:if])
options[:if] << "@_on_validate == :#{options[:on]}"
end
set_callback(:validation, :before, *args, &block)
@@ -259,7 +261,7 @@ module ActiveRecord
def after_validation(*args, &block)
options = args.extract_options!
options[:prepend] = true
- options[:if] = Array(options[:if])
+ options[:if] = Array.wrap(options[:if])
options[:if] << "!halted && value != false"
options[:if] << "@_on_validate == :#{options[:on]}" if options[:on]
set_callback(:validation, :after, *(args << options), &block)
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 e5d100b51b..3c560903f7 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -32,7 +32,6 @@ module ActiveRecord
# Enable the query cache within the block.
def cache
old, @query_cache_enabled = @query_cache_enabled, true
- @query_cache ||= {}
yield
ensure
clear_query_cache
@@ -54,7 +53,7 @@ module ActiveRecord
# the same SQL query and repeatedly return the same result each time, silently
# undermining the randomness you were expecting.
def clear_query_cache
- @query_cache.clear if @query_cache
+ @query_cache.clear
end
def select_all_with_query_cache(*args)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 6d4ab501fa..e8cba1bd41 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
@@ -267,7 +269,7 @@ module ActiveRecord
# generates
# CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
def add_index(table_name, column_name, options = {})
- column_names = Array(column_name)
+ column_names = Array.wrap(column_name)
index_name = index_name(table_name, :column => column_names)
if Hash === options # legacy support, since this param was a string
@@ -297,7 +299,7 @@ module ActiveRecord
def index_name(table_name, options) #:nodoc:
if Hash === options # legacy support
if options[:column]
- "index_#{table_name}_on_#{Array(options[:column]) * '_and_'}"
+ "index_#{table_name}_on_#{Array.wrap(options[:column]) * '_and_'}"
elsif options[:name]
options[:name]
else
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 6ffffc8654..578297029b 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -41,6 +41,7 @@ module ActiveRecord
@connection, @logger = connection, logger
@runtime = 0
@query_cache_enabled = false
+ @query_cache = {}
end
# Returns the human-readable name of the adapter. Use mixed case - one
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 68ee88bba4..7169c8f3f0 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -54,6 +54,12 @@ module ActiveRecord
super(name, self.class.extract_value_from_default(default), sql_type, null)
end
+ # :stopdoc:
+ class << self
+ attr_accessor :money_precision
+ end
+ # :startdoc:
+
private
def extract_limit(sql_type)
case sql_type
@@ -71,9 +77,11 @@ module ActiveRecord
# Extracts the precision from PostgreSQL-specific data types.
def extract_precision(sql_type)
- # Actual code is defined dynamically in PostgreSQLAdapter.connect
- # depending on the server specifics
- super
+ if sql_type == 'money'
+ self.class.money_precision
+ else
+ super
+ end
end
# Maps PostgreSQL-specific data types to logical Rails types.
@@ -83,18 +91,18 @@ module ActiveRecord
when /^(?:real|double precision)$/
:float
# Monetary types
- when /^money$/
+ when 'money'
:decimal
# Character types
when /^(?:character varying|bpchar)(?:\(\d+\))?$/
:string
# Binary data types
- when /^bytea$/
+ when 'bytea'
:binary
# Date/time types
when /^timestamp with(?:out)? time zone$/
:datetime
- when /^interval$/
+ when 'interval'
:string
# Geometric types
when /^(?:point|line|lseg|box|"?path"?|polygon|circle)$/
@@ -106,16 +114,16 @@ module ActiveRecord
when /^bit(?: varying)?(?:\(\d+\))?$/
:string
# XML type
- when /^xml$/
+ when 'xml'
:xml
# Arrays
when /^\D+\[\]$/
:string
# Object identifier types
- when /^oid$/
+ when 'oid'
:integer
# UUID type
- when /^uuid$/
+ when 'uuid'
:string
# Small and big integer types
when /^(?:small|big)int$/
@@ -383,9 +391,9 @@ module ActiveRecord
def quote(value, column = nil) #:nodoc:
if value.kind_of?(String) && column && column.type == :binary
"#{quoted_string_prefix}'#{escape_bytea(value)}'"
- elsif value.kind_of?(String) && column && column.sql_type =~ /^xml$/
+ elsif value.kind_of?(String) && column && column.sql_type == 'xml'
"xml E'#{quote_string(value)}'"
- elsif value.kind_of?(Numeric) && column && column.sql_type =~ /^money$/
+ elsif value.kind_of?(Numeric) && column && column.sql_type == 'money'
# Not truly string input, so doesn't require (or allow) escape string syntax.
"'#{value.to_s}'"
elsif value.kind_of?(String) && column && column.sql_type =~ /^bit/
@@ -925,7 +933,7 @@ module ActiveRecord
# Construct a clean list of column names from the ORDER BY clause, removing
# any ASC/DESC modifiers
order_columns = order_by.split(',').collect { |s| s.split.first }
- order_columns.delete_if &:blank?
+ order_columns.delete_if(&:blank?)
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
# Return a DISTINCT ON() clause that's distinct on the columns we want but includes
@@ -989,17 +997,8 @@ module ActiveRecord
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
# should know about this but can't detect it there, so deal with it here.
- money_precision = (postgresql_version >= 80300) ? 19 : 10
- PostgreSQLColumn.module_eval(<<-end_eval)
- def extract_precision(sql_type) # def extract_precision(sql_type)
- if sql_type =~ /^money$/ # if sql_type =~ /^money$/
- #{money_precision} # 19
- else # else
- super # super
- end # end
- end # end
- end_eval
-
+ PostgreSQLColumn.money_precision =
+ (postgresql_version >= 80300) ? 19 : 10
configure_connection
end
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index b5e8b7570a..09332418d5 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
module ActiveRecord
@@ -9,7 +10,7 @@ module ActiveRecord
attr_accessor :"#{query_method}_values"
next if [:where, :having].include?(query_method)
- class_eval <<-CEVAL
+ class_eval <<-CEVAL, __FILE__
def #{query_method}(*args, &block)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
@@ -21,12 +22,12 @@ module ActiveRecord
end
[:where, :having].each do |query_method|
- class_eval <<-CEVAL
+ class_eval <<-CEVAL, __FILE__
def #{query_method}(*args, &block)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = build_where(*args)
- new_relation.#{query_method}_values += [*value] if value.present?
+ new_relation.#{query_method}_values += Array.wrap(value) if value.present?
new_relation
end
CEVAL
@@ -35,7 +36,7 @@ module ActiveRecord
ActiveRecord::Relation::SINGLE_VALUE_METHODS.each do |query_method|
attr_accessor :"#{query_method}_value"
- class_eval <<-CEVAL
+ class_eval <<-CEVAL, __FILE__
def #{query_method}(value = true, &block)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index b19920741e..2e85959b1e 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/conversions'
module ActiveRecord #:nodoc:
@@ -186,7 +187,7 @@ module ActiveRecord #:nodoc:
end
def serializable_method_attributes
- Array(options[:methods]).inject([]) do |method_attributes, name|
+ Array.wrap(options[:methods]).inject([]) do |method_attributes, name|
method_attributes << MethodAttribute.new(name.to_s, @serializable) if @serializable.respond_to?(name.to_s)
method_attributes
end
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 4806fa0ecc..6283bdd0d6 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator
@@ -19,7 +21,7 @@ module ActiveRecord
relation = table.where(sql, *params)
- Array(options[:scope]).each do |scope_item|
+ Array.wrap(options[:scope]).each do |scope_item|
scope_value = record.send(scope_item)
relation = relation.where(scope_item => scope_value)
end
diff --git a/activerecord/test/cases/datatype_test_postgresql.rb b/activerecord/test/cases/datatype_test_postgresql.rb
index 9454b6e059..3c2d9fb7bd 100644
--- a/activerecord/test/cases/datatype_test_postgresql.rb
+++ b/activerecord/test/cases/datatype_test_postgresql.rb
@@ -97,7 +97,7 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
def test_money_values
assert_equal 567.89, @first_money.wealth
- assert_equal -567.89, @second_money.wealth
+ assert_equal(-567.89, @second_money.wealth)
end
def test_number_values