From 308cfc2376272d3fd08cdd7a0398221e875d4426 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Tue, 15 May 2018 11:20:16 -0700 Subject: [PATCH] reduce constraints for when to show forum post vote links (#3691) --- app/models/forum_post.rb | 3 +-- app/views/forum_post_votes/_list.html.erb | 2 +- app/views/forum_post_votes/_vote.html.erb | 2 +- test/functional/forum_posts_controller_test.rb | 9 ++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index b5c1d2a60..41b2731ef 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -139,8 +139,7 @@ class ForumPost < ApplicationRecord end def votable? - # shortcut to eliminate posts that are probably not tag change requests - body =~ /->/ && (bulk_update_request.present? || tag_alias.present? || tag_implication.present?) && created_at >= TagRelationship::EXPIRY.days.ago + body.to_s.match?(/->/) end def voted?(user, score) diff --git a/app/views/forum_post_votes/_list.html.erb b/app/views/forum_post_votes/_list.html.erb index e8475be13..1da894209 100644 --- a/app/views/forum_post_votes/_list.html.erb +++ b/app/views/forum_post_votes/_list.html.erb @@ -11,6 +11,6 @@ <%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %> <% end %> -<% if forum_post.tag_change_request.is_pending? && !votes.by(CurrentUser.user.id).exists? %> +<% if forum_post.tag_change_request && forum_post.tag_change_request.is_pending? && !votes.by(CurrentUser.user.id).exists? %> <%= render "forum_post_votes/add_vote", vote: votes.by(CurrentUser.user.id).first, forum_post: forum_post %> <% end %> diff --git a/app/views/forum_post_votes/_vote.html.erb b/app/views/forum_post_votes/_vote.html.erb index 30f6cb8ce..f5b9d9d23 100644 --- a/app/views/forum_post_votes/_vote.html.erb +++ b/app/views/forum_post_votes/_vote.html.erb @@ -4,7 +4,7 @@ %>
  • - <% if forum_post.tag_change_request.is_pending? && vote.creator_id == CurrentUser.id %> + <% if forum_post.tag_change_request && forum_post.tag_change_request.is_pending? && vote.creator_id == CurrentUser.id %> <%= link_to content_tag(:i, nil, class: "far #{vote.fa_class}"), forum_post_votes_path(forum_post_id: forum_post.id, format: "js"), remote: true, method: :delete %> <%= link_to_user vote.creator %> <% else %> diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index 24fb20421..92de5e52f 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -15,10 +15,9 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest context "with votes" do setup do as_user do - as(@user) do - @tag_alias = create(:tag_alias, forum_post: @forum_post, status: "pending") - @vote = create(:forum_post_vote, forum_post: @forum_post, score: 1) - end + @tag_alias = create(:tag_alias, forum_post: @forum_post, status: "pending") + @vote = create(:forum_post_vote, forum_post: @forum_post, score: 1) + @forum_post.reload end end @@ -41,7 +40,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest end should "hide the vote links" do - assert_select "a[title='Vote up']" + assert_select "a[title='Vote up']", false end should "still render existing votes" do