Fix Adapters::ActiveRecord::Context for Rails 5

This should fix Rails 5 not passing the spec ActiveRecord::ContextSpec
"join sources can be rejoined to execute a valid query".

TODO:

- Refactor out separate files for Rails 5.

- Find a fix so the preceding test "returns dependent arel join nodes
for all searches run against the context" passes also.
This commit is contained in:
Jon Atack 2015-12-22 00:40:11 +01:00
parent ebf3877173
commit 2a3759317a
1 changed files with 12 additions and 7 deletions

View File

@ -94,13 +94,18 @@ module Ransack
# JoinDependency to track table aliases.
#
def join_sources
base =
if ::ActiveRecord::VERSION::MAJOR >= 5
Arel::SelectManager.new(@object.table)
else
Arel::SelectManager.new(@object.engine, @object.table)
end
joins = @join_dependency.join_constraints(@object.joins_values)
base, joins =
if ::ActiveRecord::VERSION::MAJOR >= 5
[
Arel::SelectManager.new(@object.table),
@join_dependency.join_constraints(@object.joins_values, @join_type)
]
else
[
Arel::SelectManager.new(@object.engine, @object.table),
@join_dependency.join_constraints(@object.joins_values)
]
end
joins.each do |aliased_join|
base.from(aliased_join)
end