Skip to content

Commit

Permalink
chore: adds fix for failing tests on Rails 6
Browse files Browse the repository at this point in the history
  • Loading branch information
chloelbn committed Jan 20, 2021
1 parent 0d053a4 commit c135028
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/algoliasearch/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
15 changes: 12 additions & 3 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit c135028

Please sign in to comment.