hide forum votes if the request is not pending
This commit is contained in:
@@ -45,6 +45,9 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: Test splitting
|
name: Test splitting
|
||||||
command: |
|
command: |
|
||||||
|
ping -c 5 public-api.secure.pixiv.net
|
||||||
|
ping -c 5 oauth.secure.pixiv.net
|
||||||
|
ping -c 5 www.pixiv.net
|
||||||
circleci tests glob test/**/*_test.rb | circleci tests split | xargs -I{} docker-compose -f config/docker/compose.yml exec -T web bash -l -c 'cd /app ; bin/rails test {}'
|
circleci tests glob test/**/*_test.rb | circleci tests split | xargs -I{} docker-compose -f config/docker/compose.yml exec -T web bash -l -c 'cd /app ; bin/rails test {}'
|
||||||
docker cp docker_web_1:/app/test/reports /tmp
|
docker cp docker_web_1:/app/test/reports /tmp
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ class PixivApiClient
|
|||||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||||
end
|
end
|
||||||
rescue Net::OpenTimeout
|
rescue Net::OpenTimeout
|
||||||
print "R"
|
print "R" if Rails.env.test?
|
||||||
sleep(5)
|
sleep(5)
|
||||||
retry
|
retry
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
@@ -191,7 +191,7 @@ class PixivApiClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
rescue Net::OpenTimeout
|
rescue Net::OpenTimeout
|
||||||
print "R"
|
print "R" if Rails.env.test?
|
||||||
sleep(5)
|
sleep(5)
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -134,6 +134,10 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_change_request
|
||||||
|
bulk_update_request || tag_alias || tag_implication
|
||||||
|
end
|
||||||
|
|
||||||
def votable?
|
def votable?
|
||||||
# shortcut to eliminate posts that are probably not tag change requests
|
# 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 =~ /->/ && (bulk_update_request.present? || tag_alias.present? || tag_implication.present?) && created_at >= TagRelationship::EXPIRY.days.ago
|
||||||
|
|||||||
@@ -11,6 +11,6 @@
|
|||||||
<%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %>
|
<%= render "forum_post_votes/vote", vote: vote, forum_post: forum_post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if !votes.by(CurrentUser.user.id).exists? %>
|
<% if 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 %>
|
<%= render "forum_post_votes/add_vote", vote: votes.by(CurrentUser.user.id).first, forum_post: forum_post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
%>
|
%>
|
||||||
|
|
||||||
<li class="vote-score-<%= vote.vote_type %>">
|
<li class="vote-score-<%= vote.vote_type %>">
|
||||||
<% if vote.creator_id == CurrentUser.id %>
|
<% if 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 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 %>
|
<%= link_to_user vote.creator %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
3
test/factories/forum_post_vote.rb
Normal file
3
test/factories/forum_post_vote.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FactoryBot.define do
|
||||||
|
factory(:forum_post_vote)
|
||||||
|
end
|
||||||
@@ -8,7 +8,45 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
@mod = create(:moderator_user)
|
@mod = create(:moderator_user)
|
||||||
as_user do
|
as_user do
|
||||||
@forum_topic = create(:forum_topic, :title => "my forum topic")
|
@forum_topic = create(:forum_topic, :title => "my forum topic")
|
||||||
@forum_post = create(:forum_post, :topic_id => @forum_topic.id, :body => "xxx")
|
@forum_post = create(:forum_post, :topic_id => @forum_topic.id, :body => "alias xxx -> yyy")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render the vote links" do
|
||||||
|
get_auth forum_topic_path(@forum_topic), @mod
|
||||||
|
assert_select "a[title='Vote up']"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render existing votes" do
|
||||||
|
get_auth forum_topic_path(@forum_topic), @mod
|
||||||
|
assert_select "li.vote-score-up"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "after the alias is rejected" do
|
||||||
|
setup do
|
||||||
|
as(@mod) do
|
||||||
|
@tag_alias.reject!
|
||||||
|
end
|
||||||
|
get_auth forum_topic_path(@forum_topic), @mod
|
||||||
|
end
|
||||||
|
|
||||||
|
should "hide the vote links" do
|
||||||
|
assert_select "a[title='Vote up']"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "still render existing votes" do
|
||||||
|
assert_select "li.vote-score-up"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user