UX: Strip class when link is not oneboxed due to site setting limits.

UX: Strip class when link is not oneboxed due to site setting limits.

From 56034c733a597f73f5c79b067292d3f4b12d3938 Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Thu, 29 Nov 2018 14:33:01 +0800
Subject: [PATCH] UX: Strip class when link is not oneboxed due to site setting
 limits.


diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 8e8199c..ace1815 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -447,7 +447,12 @@ class CookedPostProcessor
       skip_onebox = limit <= 0 && !map[url]
 
       if skip_onebox
-        remove_inline_onebox_loading_class(element) unless is_onebox
+        if is_onebox
+          element.remove_class('onebox')
+        else
+          remove_inline_onebox_loading_class(element)
+        end
+
         next
       end
 
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index 83d6714..7990b39 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -35,6 +35,10 @@ describe CookedPostProcessor do
         "https://#{url_hostname}/t/mini-inline-onebox-support-rfc/66400"
       end
 
+      let(:not_oneboxed_url) do
+        "https://#{url_hostname}/t/random-url"
+      end
+
       let(:title) { 'some title' }
 
       let(:post) do
@@ -42,7 +46,7 @@ describe CookedPostProcessor do
         #{url}
         This is a #{url} with path
 
-        https://#{url_hostname}/t/random-url
+        #{not_oneboxed_url}
 
         This is a https://#{url_hostname}/t/another-random-url test
         This is a #{url} with path
@@ -101,11 +105,17 @@ describe CookedPostProcessor do
           without: {
             class: described_class::INLINE_ONEBOX_LOADING_CSS_CLASS
           },
-          text: "https://#{url_hostname}/t/another-random-url",
+          text: not_oneboxed_url,
           count: 1
         )
 
-        expect(cpp.html).to have_tag('a.onebox', count: 1)
+        expect(cpp.html).to have_tag('a',
+          without: {
+            class: 'onebox'
+          },
+          text: not_oneboxed_url,
+          count: 1
+        )
       end
     end

GitHub

1 Like