From e329764276cd75d464da661640e6b3da5387f19a Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 10 Oct 2018 23:48:45 -0500 Subject: [PATCH] Fix #3952: Adding animated_gif tag to a ugoira post breaks the player. --- app/models/post.rb | 16 ++++++++++++++++ test/unit/post_test.rb | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index f7193b4c0..54fdc3f27 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -201,6 +201,14 @@ class Post < ApplicationRecord file_ext =~ /jpg|jpeg|gif|png/i end + def is_png? + file_ext =~ /png/i + end + + def is_gif? + file_ext =~ /gif/i + end + def is_flash? file_ext =~ /swf/i end @@ -765,6 +773,14 @@ class Post < ApplicationRecord tags << "ugoira" end + if !is_gif? + tags -= ["animated_gif"] + end + + if !is_png? + tags -= ["animated_png"] + end + return tags end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 0cb7e9a6a..7883a36c3 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1140,6 +1140,16 @@ class PostTest < ActiveSupport::TestCase end end + context "tagged with animated_gif or animated_png" do + should "remove the tag if not a gif or png" do + @post.update(tag_string: "tagme animated_gif") + assert_equal("tagme", @post.tag_string) + + @post.update(tag_string: "tagme animated_png") + assert_equal("tagme", @post.tag_string) + end + end + should "have an array representation of its tags" do post = FactoryBot.create(:post) post.reload