From 2e00d4d0246013bc8a215eb7f90d86f483b81ce4 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 31 Aug 2022 01:42:55 +0100 Subject: [PATCH] DEV: Fix flaky twitter onebox behavior (#18141) The order in which Onebox engines are loaded is not guaranteed. Occasionally during tests, the twitter engine would be loaded before the instagram engine, and cause the Instagram Onebox spec to fail due to the lack of `Onebox.options.twitter_client`. This commit makes the load order of Onebox engines consistent, and fixes the issue in the twitter_status_onebox. --- lib/onebox/engine.rb | 2 +- lib/onebox/engine/twitter_status_onebox.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb index 5d64fa41f6d..9d7c6c2cfa5 100644 --- a/lib/onebox/engine.rb +++ b/lib/onebox/engine.rb @@ -9,7 +9,7 @@ module Onebox def self.engines constants.select do |constant| constant.to_s =~ /Onebox$/ - end.map(&method(:const_get)) + end.sort.map(&method(:const_get)) end def self.all_iframe_origins diff --git a/lib/onebox/engine/twitter_status_onebox.rb b/lib/onebox/engine/twitter_status_onebox.rb index 29f22427ac8..bdb94b5ebb1 100644 --- a/lib/onebox/engine/twitter_status_onebox.rb +++ b/lib/onebox/engine/twitter_status_onebox.rb @@ -11,7 +11,8 @@ module Onebox always_https def self.===(other) - !Onebox.options.twitter_client.twitter_credentials_missing? && super + client = Onebox.options.twitter_client + client && !client.twitter_credentials_missing? && super end def http_params