diff --git a/app/lib/url.rb b/app/lib/url.rb index dee76b00e..39ac4b654 100644 --- a/app/lib/url.rb +++ b/app/lib/url.rb @@ -4,8 +4,14 @@ module URL ApplicationConfig["APP_PROTOCOL"] end + def self.database_available? + ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?("site_configs") + end + + private_class_method :database_available? + def self.domain - if Rails.application&.initialized? && Settings::General.respond_to?(:app_domain) + if database_available? Settings::General.app_domain else ApplicationConfig["APP_DOMAIN"] diff --git a/spec/lib/url_spec.rb b/spec/lib/url_spec.rb index 5dcd3630e..1fe6a8c4f 100644 --- a/spec/lib/url_spec.rb +++ b/spec/lib/url_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" RSpec.describe URL, type: :lib do before do + allow(ApplicationConfig).to receive(:[]).and_call_original allow(ApplicationConfig).to receive(:[]).with("APP_PROTOCOL").and_return("https://") allow(ApplicationConfig).to receive(:[]).with("APP_DOMAIN").and_return("test.forem.cloud") allow(Settings::General).to receive(:app_domain).and_return("dev.to")