diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 3fbd8356a..1de1adf7f 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -44,9 +44,9 @@ def evaluate(search, opts = {}) else case Ransack.options[:postgres_fields_sort_option] when :nulls_first - scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS FIRST" : "#{scope_or_sort.to_sql} NULLS LAST" + scope_or_sort = Arel.sql(scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS FIRST" : "#{scope_or_sort.to_sql} NULLS LAST") when :nulls_last - scope_or_sort = scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS LAST" : "#{scope_or_sort.to_sql} NULLS FIRST" + scope_or_sort = Arel.sql(scope_or_sort.direction == :asc ? "#{scope_or_sort.to_sql} NULLS LAST" : "#{scope_or_sort.to_sql} NULLS FIRST") end relation = relation.order(scope_or_sort) diff --git a/spec/ransack/adapters/active_record/base_spec.rb b/spec/ransack/adapters/active_record/base_spec.rb index 851819640..aa07388b3 100644 --- a/spec/ransack/adapters/active_record/base_spec.rb +++ b/spec/ransack/adapters/active_record/base_spec.rb @@ -585,6 +585,13 @@ def self.simple_escaping? ) end + it 'shouldn\'t trigger a deprecation warning when fields_sort_options is set' do + Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first } + search = Person.ransack(sorts: ['name_case_insensitive desc']) + expect { search.result.first }.to_not output.to_stderr + Ransack.configure { |c| c.postgres_fields_sort_option = nil } + end + context 'case insensitive sorting' do it 'allows sort by desc' do search = Person.ransack(sorts: ['name_case_insensitive desc'])