From 39bc67ec152279676995795cd0e377e477333918 Mon Sep 17 00:00:00 2001 From: Arit Amana <32520970+msarit@users.noreply.github.com> Date: Wed, 9 Mar 2022 18:26:02 -0500 Subject: [PATCH] Test Solution for Forem-link Embed issues on Canary2 (#16843) * solution * fixing specs * complete specs * nudge Travis * resolve database issues * nudge Travis * Check that the settings table exists before loading the class This maybe fixes an issue in test-console-check accessing a missing table `users` (because we're requiring settings during the initializer, and we're initializing the app during a schema load on a newly created db). * refactor check * privatize and rename * add self * reposition private class method * Prevent accidentally deploying to DEV * Skip tests to try deploying to benhalpern * Allow PR to deploy to benhalpern * Allow other branches to deploy * Oops * Revert changes to travis.yml Co-authored-by: Dan Uber Co-authored-by: Andy Z <17884966+Zhao-Andy@users.noreply.github.com> --- app/lib/url.rb | 8 +++++++- spec/lib/url_spec.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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")