Skip to content

Commit

Permalink
Make rake:create work for test env
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed May 5, 2023
1 parent e5b5ade commit cdf0a11
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'active_storage/engine'

require_relative '../lib/lumen'
require_relative '../lib/database_utils'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down Expand Up @@ -109,5 +110,9 @@ class Application < Rails::Application
config.active_record.yaml_column_permitted_classes = [Symbol]

config.logger = Lumen::LOGGER

config.to_prepare do
ActiveRecord::Base.singleton_class.include(DatabaseUtils)
end
end
end
2 changes: 1 addition & 1 deletion config/initializers/translations.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Rails.application.config.to_prepare do
# Preload all the exisiting translations
Translation.load_all if ActiveRecord::Base.connection.table_exists? 'translations'
Translation.load_all if ActiveRecord::Base.database_exists? && ActiveRecord::Base.connection.table_exists?('translations')
end
10 changes: 10 additions & 0 deletions lib/database_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DatabaseUtils
def database_exists?
begin
connection
rescue ActiveRecord::NoDatabaseError
return false
end
true
end
end
2 changes: 2 additions & 0 deletions spec/support/elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
path_data: "/tmp/elasticsearch_test#{ENV['TEST_ENV_NUMBER']}"
}
if ENV['TEST_ES_CLUSTER_COMMAND'].present?
# TEST_CLUSTER_COMMAND is read by the elasticsearch-rails gem
ENV['TEST_CLUSTER_COMMAND'] = ENV['TEST_ES_CLUSTER_COMMAND']
es_options[:command] = ENV['TEST_ES_CLUSTER_COMMAND']
end

Expand Down

0 comments on commit cdf0a11

Please sign in to comment.