From c1350289819e7e9bdeed63296af241b47b21826b Mon Sep 17 00:00:00 2001 From: Chloe Liban Date: Tue, 19 Jan 2021 17:43:49 +0100 Subject: [PATCH] chore: adds fix for failing tests on Rails 6 --- lib/algoliasearch/utilities.rb | 2 +- spec/integration_spec.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/algoliasearch/utilities.rb b/lib/algoliasearch/utilities.rb index 46401ade..5cbc329f 100644 --- a/lib/algoliasearch/utilities.rb +++ b/lib/algoliasearch/utilities.rb @@ -2,7 +2,7 @@ module AlgoliaSearch module Utilities class << self def get_model_classes - if defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled? + if Rails.application && defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled? Zeitwerk::Loader.eager_load_all elsif Rails.application Rails.application.eager_load! diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index f8a09a9d..a9004a9d 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,9 +1,10 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) OLD_RAILS = Gem.loaded_specs['rails'].version < Gem::Version.new('4.0') +NEW_RAILS = Gem.loaded_specs['rails'].version >= Gem::Version.new('6.0') require 'active_record' -unless OLD_RAILS +unless OLD_RAILS || NEW_RAILS require 'active_job/test_helper' ActiveJob::Base.queue_adapter = :test end @@ -705,7 +706,11 @@ class SerializedObject < ActiveRecord::Base result = NestedItem.raw_search('') result['nbHits'].should == 1 - @i2.update_attributes :hidden => false + if @i2.respond_to? :update_attributes + @i2.update_attributes :hidden => false + else + @i2.update :hidden => false + end result = NestedItem.raw_search('') result['nbHits'].should == 2 @@ -1323,7 +1328,11 @@ class ReplicaThenSlave expect(results['hits'].size).to eq(1) # update the book and make it non-public anymore (not premium, not released) - book.update_attributes :released => false + if book.respond_to? :update_attributes + book.update_attributes :released => false + else + book.update :released => false + end # should be removed from the index results = index.search('Public book')