Skip to content

Commit

Permalink
Merge pull request #29619 from kamipo/deprecate_delegating_to_arel_in…
Browse files Browse the repository at this point in the history
…_relation

Deprecate delegating to `arel` in `Relation`
  • Loading branch information
kaspth committed Jun 29, 2017
2 parents 4448873 + d9fca84 commit a317af9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
* Deprecate delegating to `arel` in `Relation`.

*Ryuta Kamizono*

* Fix eager loading to respect `store_full_sti_class` setting.

*Ryuta Kamizono*
Expand Down
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation/delegation.rb
Expand Up @@ -89,6 +89,8 @@ def method_missing(method, *args, &block)
self.class.delegate_to_scoped_klass(method)
scoping { @klass.public_send(method, *args, &block) }
elsif arel.respond_to?(method)
ActiveSupport::Deprecation.warn \
"Delegating #{method} to arel is deprecated and will be removed in Rails 6.0."
self.class.delegate method, to: :arel
arel.public_send(method, *args, &block)
else
Expand Down
15 changes: 15 additions & 0 deletions activerecord/test/cases/relation/delegation_test.rb
Expand Up @@ -21,8 +21,22 @@ module DelegationWhitelistTests
end
end

module DeprecatedArelDelegationTests
AREL_METHODS = [
:with, :orders, :froms, :project, :projections, :taken, :constraints, :exists, :locked, :where_sql,
:ast, :source, :join_sources, :to_dot, :bind_values, :create_insert, :create_true, :create_false
]

def test_deprecate_arel_delegation
AREL_METHODS.each do |method|
assert_deprecated { target.public_send(method) }
end
end
end

class DelegationAssociationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
include DeprecatedArelDelegationTests

fixtures :posts

Expand All @@ -33,6 +47,7 @@ def target

class DelegationRelationTest < ActiveRecord::TestCase
include DelegationWhitelistTests
include DeprecatedArelDelegationTests

fixtures :comments

Expand Down

0 comments on commit a317af9

Please sign in to comment.