aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb16
-rw-r--r--activerecord/lib/active_record/associations/preloader/association.rb4
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb16
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb46
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb15
-rw-r--r--activerecord/lib/active_record/attribute_methods/write.rb33
-rw-r--r--activerecord/lib/active_record/base.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb11
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb18
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/transaction.rb14
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb7
-rw-r--r--activerecord/lib/active_record/connection_adapters/connection_specification.rb21
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb11
-rw-r--r--activerecord/lib/active_record/core.rb7
-rw-r--r--activerecord/lib/active_record/fixtures.rb8
-rw-r--r--activerecord/lib/active_record/inheritance.rb10
-rw-r--r--activerecord/lib/active_record/reflection.rb28
-rw-r--r--activerecord/lib/active_record/relation/delegation.rb1
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder/array_handler.rb2
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb35
-rw-r--r--activerecord/lib/active_record/sanitization.rb29
-rw-r--r--activerecord/lib/active_record/secure_token.rb49
-rw-r--r--activerecord/lib/active_record/transactions.rb29
-rw-r--r--activerecord/lib/active_record/type/boolean.rb13
26 files changed, 127 insertions, 302 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 7a050ca224..f1e784d771 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/string/filters'
-
module ActiveRecord
# = Active Record Has Many Through Association
module Associations
@@ -49,16 +47,7 @@ module ActiveRecord
end
save_through_record(record)
- if has_cached_counter? && !through_reflection_updates_counter_cache?
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Automatic updating of counter caches on through associations has been
- deprecated, and will be removed in Rails 5. Instead, please set the
- appropriate `counter_cache` options on the `has_many` and `belongs_to`
- for your associations to #{through_reflection.name}.
- MSG
- update_counter_in_database(1)
- end
record
end
@@ -211,11 +200,6 @@ module ActiveRecord
def invertible_for?(record)
false
end
-
- def through_reflection_updates_counter_cache?
- counter_name = cached_counter_attribute_name
- inverse_updates_counter_named?(counter_name, through_reflection)
- end
end
end
end
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb
index a6e1a24360..afcaa5d55a 100644
--- a/activerecord/lib/active_record/associations/preloader/association.rb
+++ b/activerecord/lib/active_record/associations/preloader/association.rb
@@ -104,11 +104,11 @@ module ActiveRecord
end
def association_key_type
- @klass.type_for_attribute(association_key_name.to_s).type
+ @klass.column_for_attribute(association_key_name).type
end
def owner_key_type
- @model.type_for_attribute(owner_key_name.to_s).type
+ @model.column_for_attribute(owner_key_name).type
end
def load_slices(slices)
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index b7edac791e..8f165fb1dc 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -192,7 +192,8 @@ module ActiveRecord
end
# Returns the column object for the named attribute.
- # Returns nil if the named attribute does not exist.
+ # Returns a +ActiveRecord::ConnectionAdapters::NullColumn+ if the
+ # named attribute does not exist.
#
# class Person < ActiveRecord::Base
# end
@@ -202,17 +203,12 @@ module ActiveRecord
# # => #<ActiveRecord::ConnectionAdapters::Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...>
#
# person.column_for_attribute(:nothing)
- # # => nil
+ # # => #<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...>
def column_for_attribute(name)
- column = columns_hash[name.to_s]
- if column.nil?
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- `#column_for_attribute` will return a null object for non-existent
- columns in Rails 5. Use `#has_attribute?` if you need to check for
- an attribute's existence.
- MSG
+ name = name.to_s
+ columns_hash.fetch(name) do
+ ConnectionAdapters::NullColumn.new(name)
end
- column
end
end
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index 20f0936e52..4b72fe7d7e 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/module/method_transplanting'
-
module ActiveRecord
module AttributeMethods
module Read
@@ -36,42 +34,24 @@ module ActiveRecord
extend ActiveSupport::Concern
module ClassMethods
- [:cache_attributes, :cached_attributes, :cache_attribute?].each do |method_name|
- define_method method_name do |*|
- cached_attributes_deprecation_warning(method_name)
- true
- end
- end
-
protected
- def cached_attributes_deprecation_warning(method_name)
- ActiveSupport::Deprecation.warn "Calling `#{method_name}` is no longer necessary. All attributes are cached."
- end
+ def define_method_attribute(name)
+ safe_name = name.unpack('h*').first
+ temp_method = "__temp__#{safe_name}"
- if Module.methods_transplantable?
- def define_method_attribute(name)
- method = ReaderMethodCache[name]
- generated_attribute_methods.module_eval { define_method name, method }
- end
- else
- def define_method_attribute(name)
- safe_name = name.unpack('h*').first
- temp_method = "__temp__#{safe_name}"
-
- ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
+ ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
- generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
- def #{temp_method}
- name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
- _read_attribute(name) { |n| missing_attribute(n, caller) }
- end
- STR
-
- generated_attribute_methods.module_eval do
- alias_method name, temp_method
- undef_method temp_method
+ generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
+ def #{temp_method}
+ name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
+ _read_attribute(name) { |n| missing_attribute(n, caller) }
end
+ STR
+
+ generated_attribute_methods.module_eval do
+ alias_method name, temp_method
+ undef_method temp_method
end
end
end
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index e5ec5ddca5..d0d8a968c5 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/string/filters'
-
module ActiveRecord
module AttributeMethods
module Serialization
@@ -51,19 +49,6 @@ module ActiveRecord
Type::Serialized.new(type, coder)
end
end
-
- def serialized_attributes
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- `serialized_attributes` is deprecated without replacement, and will
- be removed in Rails 5.0.
- MSG
-
- @serialized_attributes ||= Hash[
- columns.select { |t| t.cast_type.is_a?(Type::Serialized) }.map { |c|
- [c.name, c.cast_type.coder]
- }
- ]
- end
end
end
end
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb
index 16804f86bf..ab017c7b54 100644
--- a/activerecord/lib/active_record/attribute_methods/write.rb
+++ b/activerecord/lib/active_record/attribute_methods/write.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/module/method_transplanting'
-
module ActiveRecord
module AttributeMethods
module Write
@@ -25,27 +23,18 @@ module ActiveRecord
module ClassMethods
protected
- if Module.methods_transplantable?
- def define_method_attribute=(name)
- method = WriterMethodCache[name]
- generated_attribute_methods.module_eval {
- define_method "#{name}=", method
- }
- end
- else
- def define_method_attribute=(name)
- safe_name = name.unpack('h*').first
- ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
+ def define_method_attribute=(name)
+ safe_name = name.unpack('h*').first
+ ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
- generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
- def __temp__#{safe_name}=(value)
- name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
- write_attribute(name, value)
- end
- alias_method #{(name + '=').inspect}, :__temp__#{safe_name}=
- undef_method :__temp__#{safe_name}=
- STR
- end
+ generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
+ def __temp__#{safe_name}=(value)
+ name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
+ write_attribute(name, value)
+ end
+ alias_method #{(name + '=').inspect}, :__temp__#{safe_name}=
+ undef_method :__temp__#{safe_name}=
+ STR
end
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bb01231bca..100d3780f6 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -312,6 +312,7 @@ module ActiveRecord #:nodoc:
include Reflection
include Serialization
include Store
+ include SecureToken
end
ActiveSupport.run_load_hooks(:active_record, Base)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 6235745fb2..1371317e3c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -2,7 +2,6 @@ require 'thread'
require 'thread_safe'
require 'monitor'
require 'set'
-require 'active_support/core_ext/string/filters'
module ActiveRecord
# Raised when a connection could not be obtained within the connection
@@ -517,15 +516,7 @@ module ActiveRecord
def connection_pool_list
owner_to_pool.values.compact
end
-
- def connection_pools
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- In the next release, this will return the same as `#connection_pool_list`.
- (An array of pools, rather than a hash mapping specs to pools.)
- MSG
-
- Hash[connection_pool_list.map { |pool| [pool.spec, pool] }]
- end
+ alias :connection_pools :connection_pool_list
def establish_connection(owner, spec)
@class_to_pool.clear
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 68d8a2cd6a..7eaa89c9a7 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -56,18 +56,6 @@ module ActiveRecord
end
end
- module TimestampDefaultDeprecation # :nodoc:
- def emit_warning_if_null_unspecified(options)
- return if options.key?(:null)
-
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- `#timestamp` was called without specifying an option for `null`. In Rails 5,
- this behavior will change to `null: false`. You should manually specify
- `null: true` to prevent the behavior of your existing migrations from changing.
- MSG
- end
- end
-
class ReferenceDefinition # :nodoc:
def initialize(
name,
@@ -167,8 +155,6 @@ module ActiveRecord
# The table definitions
# The Columns are stored as a ColumnDefinition in the +columns+ attribute.
class TableDefinition
- include TimestampDefaultDeprecation
-
# An array of ColumnDefinition objects, representing the column changes
# that have been defined.
attr_accessor :indexes
@@ -375,7 +361,9 @@ module ActiveRecord
# t.timestamps null: false
def timestamps(*args)
options = args.extract_options!
- emit_warning_if_null_unspecified(options)
+
+ options[:null] = false if options[:null].nil?
+
column(:created_at, :datetime, options)
column(:updated_at, :datetime, options)
end
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 34d60493ea..0f44c332ae 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -851,14 +851,14 @@ module ActiveRecord
columns
end
- include TimestampDefaultDeprecation
# Adds timestamps (+created_at+ and +updated_at+) columns to +table_name+.
# Additional options (like <tt>null: false</tt>) are forwarded to #add_column.
#
# add_timestamps(:suppliers, null: false)
#
def add_timestamps(table_name, options = {})
- emit_warning_if_null_unspecified(options)
+ options[:null] = false if options[:null].nil?
+
add_column table_name, :created_at, :datetime, options
add_column table_name, :updated_at, :datetime, options
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
index fd666c8c39..f6ef3b0675 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb
@@ -69,12 +69,7 @@ module ActiveRecord
def rollback_records
ite = records.uniq
while record = ite.shift
- begin
- record.rolledback! full_rollback?
- rescue => e
- raise if ActiveRecord::Base.raise_in_transactional_callbacks
- record.logger.error(e) if record.respond_to?(:logger) && record.logger
- end
+ record.rolledback! full_rollback?
end
ensure
ite.each do |i|
@@ -89,12 +84,7 @@ module ActiveRecord
def commit_records
ite = records.uniq
while record = ite.shift
- begin
- record.committed!
- rescue => e
- raise if ActiveRecord::Base.raise_in_transactional_callbacks
- record.logger.error(e) if record.respond_to?(:logger) && record.logger
- end
+ record.committed!
end
ensure
ite.each do |i|
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index fa24d9b43f..c3a8bf5c74 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -25,7 +25,6 @@ module ActiveRecord
autoload :TableDefinition
autoload :Table
autoload :AlterTable
- autoload :TimestampDefaultDeprecation
end
autoload_at 'active_record/connection_adapters/abstract/connection_pool' do
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 65d8b1a8ab..e74de60a83 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -5,7 +5,6 @@ module ActiveRecord
module ConnectionAdapters
# An abstract definition of a column in a table.
class Column
- TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
module Format
@@ -77,6 +76,12 @@ module ActiveRecord
[self.class, name, default, cast_type, sql_type, null, default_function]
end
end
+
+ class NullColumn < Column
+ def initialize(name)
+ super name, nil, Type::Value.new
+ end
+ end
end
# :startdoc:
end
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
index e54e3199ff..08d46fca96 100644
--- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -1,5 +1,4 @@
require 'uri'
-require 'active_support/core_ext/string/filters'
module ActiveRecord
module ConnectionAdapters
@@ -210,30 +209,12 @@ module ActiveRecord
when Symbol
resolve_symbol_connection spec
when String
- resolve_string_connection spec
+ resolve_url_connection spec
when Hash
resolve_hash_connection spec
end
end
- def resolve_string_connection(spec)
- # Rails has historically accepted a string to mean either
- # an environment key or a URL spec, so we have deprecated
- # this ambiguous behaviour and in the future this function
- # can be removed in favor of resolve_url_connection.
- if configurations.key?(spec) || spec !~ /:/
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Passing a string to ActiveRecord::Base.establish_connection for a
- configuration lookup is deprecated, please pass a symbol
- (#{spec.to_sym.inspect}) instead.
- MSG
-
- resolve_symbol_connection(spec)
- else
- resolve_url_connection(spec)
- end
- end
-
# Takes the environment such as +:production+ or +:development+.
# This requires that the @configurations was initialized with a key that
# matches.
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb
index 961e6224c4..3adfb8b9d8 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rb
@@ -25,16 +25,7 @@ module ActiveRecord
to = type_cast_single extracted[:to]
if !infinity?(from) && extracted[:exclude_start]
- if from.respond_to?(:succ)
- from = from.succ
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Excluding the beginning of a Range is only partialy supported
- through `#succ`. This is not reliable and will be removed in
- the future.
- MSG
- else
- raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
- end
+ raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
end
::Range.new(from, to, extracted[:exclude_end])
end
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 38b2d632d2..5c7c0feeb7 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -87,13 +87,6 @@ module ActiveRecord
mattr_accessor :maintain_test_schema, instance_accessor: false
- def self.disable_implicit_join_references=(value)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Implicit join references were removed with Rails 4.1.
- Make sure to remove this configuration because it does nothing.
- MSG
- end
-
class_attribute :default_connection_handler, instance_writer: false
class_attribute :find_by_statement_cache
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 4732462b05..5f6a75ebef 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -633,7 +633,7 @@ module ActiveRecord
# interpolate the fixture label
row.each do |key, value|
- row[key] = value.gsub("$LABEL", label) if value.is_a?(String)
+ row[key] = value.gsub("$LABEL", label.to_s) if value.is_a?(String)
end
# generate a primary key if necessary
@@ -768,12 +768,6 @@ module ActiveRecord
end
- #--
- # Deprecate 'Fixtures' in favor of 'FixtureSet'.
- #++
- # :nodoc:
- Fixtures = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActiveRecord::Fixtures', 'ActiveRecord::FixtureSet')
-
class Fixture #:nodoc:
include Enumerable
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index b91e9ac137..fd1e22349b 100644
--- a/activerecord/lib/active_record/inheritance.rb
+++ b/activerecord/lib/active_record/inheritance.rb
@@ -79,16 +79,6 @@ module ActiveRecord
:true == (@finder_needs_type_condition ||= descends_from_active_record? ? :false : :true)
end
- def symbolized_base_class
- ActiveSupport::Deprecation.warn('`ActiveRecord::Base.symbolized_base_class` is deprecated and will be removed without replacement.')
- @symbolized_base_class ||= base_class.to_s.to_sym
- end
-
- def symbolized_sti_name
- ActiveSupport::Deprecation.warn('`ActiveRecord::Base.symbolized_sti_name` is deprecated and will be removed without replacement.')
- @symbolized_sti_name ||= sti_name.present? ? sti_name.to_sym : symbolized_base_class
- end
-
# Returns the class descending directly from ActiveRecord::Base, or
# an abstract class, if any, in the inheritance hierarchy.
#
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 7696ef13c7..dab5a502a5 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -153,15 +153,6 @@ module ActiveRecord
JoinKeys.new(foreign_key, active_record_primary_key)
end
- def source_macro
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- ActiveRecord::Base.source_macro is deprecated and will be removed
- without replacement.
- MSG
-
- macro
- end
-
def constraints
scope_chain.flatten
end
@@ -352,13 +343,10 @@ module ActiveRecord
return unless scope
if scope.arity > 0
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ raise ArgumentError, <<-MSG.squish
The association scope '#{name}' is instance dependent (the scope
- block takes an argument). Preloading happens before the individual
- instances are created. This means that there is no instance being
- passed to the association scope. This will most likely result in
- broken or incorrect behavior. Joining, Preloading and eager loading
- of these associations is deprecated and will be removed in the future.
+ block takes an argument). Preloading instance dependent scopes is
+ not supported.
MSG
end
end
@@ -763,16 +751,6 @@ module ActiveRecord
source_reflection.join_keys(association_klass)
end
- # The macro used by the source association
- def source_macro
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- ActiveRecord::Base.source_macro is deprecated and will be removed
- without replacement.
- MSG
-
- source_reflection.source_macro
- end
-
# A through association is nested if there would be more than one join table
def nested?
chain.length > 2
diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb
index 50f4d5c7ab..d4a8823cfe 100644
--- a/activerecord/lib/active_record/relation/delegation.rb
+++ b/activerecord/lib/active_record/relation/delegation.rb
@@ -1,6 +1,5 @@
require 'set'
require 'active_support/concern'
-require 'active_support/deprecation'
module ActiveRecord
module Delegation # :nodoc:
diff --git a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb
index 4b5f5773a0..95dbd6a77f 100644
--- a/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/string/filters'
-
module ActiveRecord
class PredicateBuilder
class ArrayHandler # :nodoc:
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index ef380abfe8..6892cc114c 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -62,15 +62,14 @@ module ActiveRecord
Relation::MULTI_VALUE_METHODS.each do |name|
class_eval <<-CODE, __FILE__, __LINE__ + 1
- def #{name}_values # def select_values
- @values[:#{name}] || [] # @values[:select] || []
- end # end
- #
- def #{name}_values=(values) # def select_values=(values)
- raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
- check_cached_relation
- @values[:#{name}] = values # @values[:select] = values
- end # end
+ def #{name}_values # def select_values
+ @values[:#{name}] || [] # @values[:select] || []
+ end # end
+ #
+ def #{name}_values=(values) # def select_values=(values)
+ assert_mutability! # assert_mutability!
+ @values[:#{name}] = values # @values[:select] = values
+ end # end
CODE
end
@@ -85,23 +84,12 @@ module ActiveRecord
Relation::SINGLE_VALUE_METHODS.each do |name|
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}_value=(value) # def readonly_value=(value)
- raise ImmutableRelation if @loaded # raise ImmutableRelation if @loaded
- check_cached_relation
+ assert_mutability! # assert_mutability!
@values[:#{name}] = value # @values[:readonly] = value
end # end
CODE
end
- def check_cached_relation # :nodoc:
- if defined?(@arel) && @arel
- @arel = nil
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- Modifying already cached Relation. The cache will be reset. Use a
- cloned Relation to prevent this warning.
- MSG
- end
- end
-
def create_with_value # :nodoc:
@values[:create_with] || {}
end
@@ -857,6 +845,11 @@ module ActiveRecord
private
+ def assert_mutability!
+ raise ImmutableRelation if @loaded
+ raise ImmutableRelation if defined?(@arel) && @arel
+ end
+
def build_arel
arel = Arel::SelectManager.new(table)
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb
index f5aa60a69a..768a72a947 100644
--- a/activerecord/lib/active_record/sanitization.rb
+++ b/activerecord/lib/active_record/sanitization.rb
@@ -72,35 +72,6 @@ module ActiveRecord
expanded_attrs
end
- # Sanitizes a hash of attribute/value pairs into SQL conditions for a WHERE clause.
- # { name: "foo'bar", group_id: 4 }
- # # => "name='foo''bar' and group_id= 4"
- # { status: nil, group_id: [1,2,3] }
- # # => "status IS NULL and group_id IN (1,2,3)"
- # { age: 13..18 }
- # # => "age BETWEEN 13 AND 18"
- # { 'other_records.id' => 7 }
- # # => "`other_records`.`id` = 7"
- # { other_records: { id: 7 } }
- # # => "`other_records`.`id` = 7"
- # And for value objects on a composed_of relationship:
- # { address: Address.new("123 abc st.", "chicago") }
- # # => "address_street='123 abc st.' and address_city='chicago'"
- def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
- table = Arel::Table.new(table_name).alias(default_table_name)
- predicate_builder = PredicateBuilder.new(TableMetadata.new(self, table))
- ActiveSupport::Deprecation.warn(<<-EOWARN)
-sanitize_sql_hash_for_conditions is deprecated, and will be removed in Rails 5.0
- EOWARN
- attrs = predicate_builder.resolve_column_aliases(attrs)
- attrs = expand_hash_conditions_for_aggregates(attrs)
-
- predicate_builder.build_from_hash(attrs).map { |b|
- connection.visitor.compile b
- }.join(' AND ')
- end
- alias_method :sanitize_sql_hash, :sanitize_sql_hash_for_conditions
-
# Sanitizes a hash of attribute/value pairs into SQL conditions for a SET clause.
# { status: nil, group_id: 1 }
# # => "status = NULL , group_id = 1"
diff --git a/activerecord/lib/active_record/secure_token.rb b/activerecord/lib/active_record/secure_token.rb
new file mode 100644
index 0000000000..23d4292cbb
--- /dev/null
+++ b/activerecord/lib/active_record/secure_token.rb
@@ -0,0 +1,49 @@
+module ActiveRecord
+ module SecureToken
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ # Example using has_secure_token
+ #
+ # # Schema: User(toke:string, auth_token:string)
+ # class User < ActiveRecord::Base
+ # has_secure_token
+ # has_secure_token :auth_token
+ # end
+ #
+ # user = User.new
+ # user.save
+ # user.token # => "44539a6a59835a4ee9d7b112"
+ # user.auth_token # => "e2426a93718d1817a43abbaa"
+ # user.regenerate_token # => true
+ # user.regenerate_auth_token # => true
+ #
+ # SecureRandom is used to generate the 24-character unique token, so collisions are highly unlikely.
+ # We'll check to see if the generated token has been used already using #exists?, and retry up to 10
+ # times to find another unused token. After that a RuntimeError is raised if the problem persists.
+ #
+ # Note that it's still possible to generate a race condition in the database in the same way that
+ # validates_presence_of can. You're encouraged to add a unique index in the database to deal with
+ # this even more unlikely scenario.
+ def has_secure_token(attribute = :token)
+ # Load securerandom only when has_secure_key is used.
+ require 'securerandom'
+ define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token(attribute) }
+ before_create { self.send("#{attribute}=", self.class.generate_unique_secure_token(attribute)) }
+ end
+
+ def generate_unique_secure_token(attribute)
+ 10.times do |i|
+ SecureRandom.hex(12).tap do |token|
+ if exists?(attribute => token)
+ raise "Couldn't generate a unique token in 10 attempts!" if i == 9
+ else
+ return token
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index 97648ec898..9cef50029b 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -4,23 +4,10 @@ module ActiveRecord
extend ActiveSupport::Concern
#:nodoc:
ACTIONS = [:create, :destroy, :update]
- #:nodoc:
- CALLBACK_WARN_MESSAGE = "Currently, Active Record suppresses errors raised " \
- "within `after_rollback`/`after_commit` callbacks and only print them to " \
- "the logs. In the next version, these errors will no longer be suppressed. " \
- "Instead, the errors will propagate normally just like in other Active " \
- "Record callbacks.\n" \
- "\n" \
- "You can opt into the new behavior and remove this warning by setting:\n" \
- "\n" \
- " config.active_record.raise_in_transactional_callbacks = true\n\n"
included do
define_callbacks :commit, :rollback,
scope: [:kind, :name]
-
- mattr_accessor :raise_in_transactional_callbacks, instance_writer: false
- self.raise_in_transactional_callbacks = false
end
# = Active Record Transactions
@@ -236,9 +223,6 @@ module ActiveRecord
def after_commit(*args, &block)
set_options_for_callbacks!(args)
set_callback(:commit, :after, *args, &block)
- unless ActiveRecord::Base.raise_in_transactional_callbacks
- ActiveSupport::Deprecation.warn(CALLBACK_WARN_MESSAGE)
- end
end
# This callback is called after a create, update, or destroy are rolled back.
@@ -247,9 +231,16 @@ module ActiveRecord
def after_rollback(*args, &block)
set_options_for_callbacks!(args)
set_callback(:rollback, :after, *args, &block)
- unless ActiveRecord::Base.raise_in_transactional_callbacks
- ActiveSupport::Deprecation.warn(CALLBACK_WARN_MESSAGE)
- end
+ end
+
+ def raise_in_transactional_callbacks
+ ActiveSupport::Deprecation.warn('ActiveRecord::Base.raise_in_transactional_callbacks is deprecated and will be removed without replacement.')
+ true
+ end
+
+ def raise_in_transactional_callbacks=(value)
+ ActiveSupport::Deprecation.warn('ActiveRecord::Base.raise_in_transactional_callbacks= is deprecated, has no effect and will be removed without replacement.')
+ value
end
private
diff --git a/activerecord/lib/active_record/type/boolean.rb b/activerecord/lib/active_record/type/boolean.rb
index 978d16d524..f6a75512fd 100644
--- a/activerecord/lib/active_record/type/boolean.rb
+++ b/activerecord/lib/active_record/type/boolean.rb
@@ -10,19 +10,8 @@ module ActiveRecord
def cast_value(value)
if value == ''
nil
- elsif ConnectionAdapters::Column::TRUE_VALUES.include?(value)
- true
else
- if !ConnectionAdapters::Column::FALSE_VALUES.include?(value)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- You attempted to assign a value which is not explicitly `true` or `false`
- to a boolean column. Currently this value casts to `false`. This will
- change to match Ruby's semantics, and will cast to `true` in Rails 5.
- If you would like to maintain the current behavior, you should
- explicitly handle the values you would like cast to `false`.
- MSG
- end
- false
+ !ConnectionAdapters::Column::FALSE_VALUES.include?(value)
end
end
end