]> cat aescling's git repositories - mastodon.git/commitdiff
Fix autoplay issue with spoiler tag (#8540)
authorRenato "Lond" Cerqueira <renato@lond.com.br>
Fri, 31 Aug 2018 13:16:59 +0000 (15:16 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 31 Aug 2018 13:16:59 +0000 (15:16 +0200)
Add tests to avoid similar issues in the future

app/lib/formatter.rb
app/views/stream_entries/_detailed_status.html.haml
app/views/stream_entries/_simple_status.html.haml
spec/lib/formatter_spec.rb

index 0b4690394caf292b7689784eb31229af4d93c00c..8b694536c24886c4ab4e890ef88181fdfff1c9a0 100644 (file)
@@ -61,7 +61,7 @@ class Formatter
     Sanitize.fragment(html, config)
   end
 
-  def format_spoiler(status)
+  def format_spoiler(status, **options)
     html = encode(status.spoiler_text)
     html = encode_custom_emojis(html, status.emojis, options[:autoplay])
     html.html_safe # rubocop:disable Rails/OutputSafety
index 6251cdd1a52a0a0bd826d362520685580ccd56cf..bf5f614a116ca1d79c442b93ec65c4efed45de64 100644 (file)
@@ -17,7 +17,7 @@
   .status__content.emojify<
     - if status.spoiler_text?
       %p{ style: 'margin-bottom: 0' }<
-        %span.p-summary> #{Formatter.instance.format_spoiler(status)}&nbsp;
+        %span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}&nbsp;
         %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
     .e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
index 1d596d4e0a7f243928a3dff920a6bdf2e69fb5a7..e147596f6979f6880ea81154068674b0417d6c06 100644 (file)
@@ -20,7 +20,7 @@
   .status__content.emojify<
     - if status.spoiler_text?
       %p{ style: 'margin-bottom: 0' }<
-        %span.p-summary> #{Formatter.instance.format_spoiler(status)}&nbsp;
+        %span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}&nbsp;
         %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more')
     .e-content{ lang: status.language, style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
index d60d24bf68a134368f7efcfcd062b196afe73b18..0c2248cae593f96018e348081a09e1905d45b4d4 100644 (file)
@@ -170,6 +170,29 @@ RSpec.describe Formatter do
     end
   end
 
+
+  describe '#format_spoiler' do
+    subject { Formatter.instance.format_spoiler(status) }
+
+    context 'given a post containing plain text' do
+      let(:status)  { Fabricate(:status, text: 'text', spoiler_text: 'Secret!', uri: nil) }
+
+      it 'Returns the spoiler text' do
+        is_expected.to eq 'Secret!'
+      end
+    end
+
+    context 'given a post with an emoji shortcode at the start' do
+      let!(:emoji) { Fabricate(:custom_emoji) }
+      let(:status)  { Fabricate(:status, text: 'text', spoiler_text: ':coolcat: Secret!', uri: nil) }
+      let(:text) { ':coolcat: Beep boop' }
+
+      it 'converts the shortcode to an image tag' do
+        is_expected.to match(/<img draggable="false" class="emojione" alt=":coolcat:"/)
+      end
+    end
+  end
+
   describe '#format' do
     subject { Formatter.instance.format(status) }