From 4ef2fe24168eb53b22d08ca51fd1ac3c9e8552da Mon Sep 17 00:00:00 2001 From: ellnix Date: Wed, 2 Apr 2025 13:11:37 +0200 Subject: [PATCH 1/4] Stop modifying LOAD_PATH in specs rspec automatically adds `spec/` to the load path, and adding `lib/` to the load path does not serve a purpose from what I can see. --- spec/spec_helper.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1f92dc5..0385b73 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,9 +22,6 @@ require 'faker' require 'threads' -$LOAD_PATH.unshift(File.dirname(__FILE__)) -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) - require 'meilisearch-rails' require 'rspec' require 'rails/all' From b1b645746db639ddf4d1122ebb65e82735f4bc6d Mon Sep 17 00:00:00 2001 From: ellnix Date: Wed, 2 Apr 2025 13:13:50 +0200 Subject: [PATCH 2/4] Remove OLD_RAILS and NEW_RAILS constants Also removes legacy ActiveJob test setup. This should be safe since we do not support Rails versions older than 6 anyway. --- spec/spec_helper.rb | 3 --- spec/support/active_record_schema.rb | 6 ------ 2 files changed, 9 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0385b73..61ba67f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,9 +36,6 @@ # Required for serializing objects similar to production environments GlobalID.app = 'meilisearch-test' -OLD_RAILS = Gem.loaded_specs['rails'].version < Gem::Version.new('4.0') -NEW_RAILS = Gem.loaded_specs['rails'].version >= Gem::Version.new('6.0') - Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |file| require file } RSpec.configure do |c| diff --git a/spec/support/active_record_schema.rb b/spec/support/active_record_schema.rb index 832e021..f5fe6a3 100644 --- a/spec/support/active_record_schema.rb +++ b/spec/support/active_record_schema.rb @@ -17,12 +17,6 @@ FileUtils.rm('data.sqlite3') if File.exist?('data.sqlite3') -unless OLD_RAILS || NEW_RAILS - require 'active_job/test_helper' - - ActiveJob::Base.queue_adapter = :test -end - def ar_schema @ar_schema ||= ActiveRecord::Schema.new end From 6f0035e3b02997d90d754b55be78dbdebb4d5c3f Mon Sep 17 00:00:00 2001 From: ellnix Date: Wed, 2 Apr 2025 13:14:43 +0200 Subject: [PATCH 3/4] Use rm_f instead of combining rm with File.exist? There's a theoretical possibility of a race condition: https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/ruby-best-practices/atomic-file-operations/ I don't really expect it to happen, but this way is simpler in any case. --- spec/support/active_record_schema.rb | 2 +- spec/support/sequel_db.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/active_record_schema.rb b/spec/support/active_record_schema.rb index f5fe6a3..5150c38 100644 --- a/spec/support/active_record_schema.rb +++ b/spec/support/active_record_schema.rb @@ -15,7 +15,7 @@ ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks) -FileUtils.rm('data.sqlite3') if File.exist?('data.sqlite3') +FileUtils.rm_f('data.sqlite3') def ar_schema @ar_schema ||= ActiveRecord::Schema.new diff --git a/spec/support/sequel_db.rb b/spec/support/sequel_db.rb index 48ad397..cc6bbe2 100644 --- a/spec/support/sequel_db.rb +++ b/spec/support/sequel_db.rb @@ -7,4 +7,4 @@ def sequel_db end) end -FileUtils.rm('sequel_data.sqlite3') if File.exist?('sequel_data.sqlite3') +FileUtils.rm_f('sequel_data.sqlite3') From 4f33e1b1178a9ee1a9a94729b6c2c307b824b129 Mon Sep 17 00:00:00 2001 From: ellnix Date: Wed, 2 Apr 2025 13:54:38 +0200 Subject: [PATCH 4/4] Add sqlite3-shm and sqlite3-wal files to gitignore Temporary files that can be left behind if the tests don't exit gracefully. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9ea23d8..53c3158 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,9 @@ Gemfile.lock # Ignore db files *.sqlite3 +# Ignore temprary db files +*.sqlite3-shm +*.sqlite3-wal # Ignore editor files .idea