From d4b17824311dac370552cf0c727435d97066a331 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Fri, 27 Apr 2018 16:18:18 -0700 Subject: [PATCH] allow more forum posts to be voted on (fixes #3677) --- app/models/forum_post.rb | 7 +++++++ app/views/forum_posts/_forum_post.html.erb | 2 +- test/unit/forum_post_test.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index c533ac821..c18f5a912 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -6,6 +6,8 @@ class ForumPost < ApplicationRecord belongs_to_updater belongs_to :topic, :class_name => "ForumTopic" has_many :votes, class_name: "ForumPostVote" + has_one :tag_relationship + has_one :bulk_update_request before_validation :initialize_is_deleted, :on => :create after_create :update_topic_updated_at_on_create after_update :update_topic_updated_at_on_update_for_original_posts @@ -129,6 +131,11 @@ class ForumPost < ApplicationRecord end end + def votable? + # shortcut to eliminate posts that are probably not tag change requests + body.match(/->/) && (bulk_update_request.present? || tag_relationship.present?) && created_at >= TagRelationship::EXPIRY.days.ago + end + def voted?(user, score) votes.where(creator_id: user.id, score: score).exists? end diff --git a/app/views/forum_posts/_forum_post.html.erb b/app/views/forum_posts/_forum_post.html.erb index 82779124f..4e461b7d1 100644 --- a/app/views/forum_posts/_forum_post.html.erb +++ b/app/views/forum_posts/_forum_post.html.erb @@ -44,7 +44,7 @@ <% else %>
  • <%= link_to "Permalink", forum_post_path(forum_post) %>
  • <% end %> - <% if forum_post.is_original_post?(original_forum_post_id) %> + <% if forum_post.votable? %> diff --git a/test/unit/forum_post_test.rb b/test/unit/forum_post_test.rb index b565c30c8..501680866 100644 --- a/test/unit/forum_post_test.rb +++ b/test/unit/forum_post_test.rb @@ -14,6 +14,17 @@ class ForumPostTest < ActiveSupport::TestCase CurrentUser.ip_addr = nil end + context "#votable?" do + setup do + @post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "[[aaa]] -> [[bbb]]") + @tag_alias = FactoryBot.create(:tag_alias, forum_post: @post) + end + + should "be true for a post associated with a tag alias" do + assert(@post.votable?) + end + end + context "that mentions a user" do context "in a quote block" do setup do