Implement forum topic voting and tag change pruning (#3580)
This commit is contained in:
36
test/controllers/forum_post_votes_controller_test.rb
Normal file
36
test/controllers/forum_post_votes_controller_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ForumPostVotesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The forum post votes controller" do
|
||||
setup do
|
||||
@user = create(:user)
|
||||
|
||||
as_user do
|
||||
@forum_topic = create(:forum_topic)
|
||||
@forum_post = create(:forum_post, topic: @forum_topic)
|
||||
end
|
||||
end
|
||||
|
||||
should "allow voting" do
|
||||
assert_difference("ForumPostVote.count") do
|
||||
post_auth forum_post_votes_path(forum_post_id: @forum_post.id), @user, params: {forum_post_vote: {score: 1}, format: "js"}
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "when deleting" do
|
||||
setup do
|
||||
as_user do
|
||||
@forum_post_vote = @forum_post.votes.create(score: 1)
|
||||
end
|
||||
end
|
||||
|
||||
should "allow removal" do
|
||||
assert_difference("ForumPostVote.count", -1) do
|
||||
delete_auth forum_post_votes_path(forum_post_id: @forum_post.id), @user, params: {format: "js"}
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
11
test/fixtures/forum_post_votes.yml
vendored
Normal file
11
test/fixtures/forum_post_votes.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
forum_post_id: 1
|
||||
creator_id: 1
|
||||
score: 1
|
||||
|
||||
two:
|
||||
forum_post_id: 1
|
||||
creator_id: 1
|
||||
score: 1
|
||||
7
test/models/forum_post_vote_test.rb
Normal file
7
test/models/forum_post_vote_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ForumPostVoteTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
66
test/unit/tag_change_request_pruner_test.rb
Normal file
66
test/unit/tag_change_request_pruner_test.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TagChangeRequestPrunerTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
CurrentUser.user = FactoryBot.create(:admin_user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@forum_topic = create(:forum_topic)
|
||||
@tag_alias = create(:tag_alias, forum_topic: @forum_topic)
|
||||
@tag_implication = create(:tag_implication, antecedent_name: "ccc", consequent_name: "ddd", forum_topic: @forum_topic)
|
||||
@bulk_update_request = create(:bulk_update_request, script: "alias eee -> fff", forum_topic: @forum_topic)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
subject { TagChangeRequestPruner.new }
|
||||
|
||||
context '#warn_old' do
|
||||
setup do
|
||||
[TagAlias, TagImplication, BulkUpdateRequest].each do |model|
|
||||
model.update_all(status: "pending", created_at: (TagRelationship::EXPIRY_WARNING + 1).days.ago)
|
||||
end
|
||||
end
|
||||
|
||||
should "update the forum topic for an alias" do
|
||||
ForumUpdater.any_instance.expects(:update)
|
||||
subject.warn_old(TagAlias)
|
||||
end
|
||||
|
||||
should "update the forum topic for an implication" do
|
||||
ForumUpdater.any_instance.expects(:update)
|
||||
subject.warn_old(TagImplication)
|
||||
end
|
||||
|
||||
should "update the forum topic for a bulk update request" do
|
||||
ForumUpdater.any_instance.expects(:update)
|
||||
subject.warn_old(BulkUpdateRequest)
|
||||
end
|
||||
end
|
||||
|
||||
context '#reject_expired' do
|
||||
setup do
|
||||
[TagAlias, TagImplication, BulkUpdateRequest].each do |model|
|
||||
model.update_all(status: "pending", created_at: (TagRelationship::EXPIRY + 1).days.ago)
|
||||
end
|
||||
end
|
||||
|
||||
should "reject the alias" do
|
||||
TagAlias.any_instance.expects(:reject!)
|
||||
subject.reject_expired(TagAlias)
|
||||
end
|
||||
|
||||
should "reject the implication" do
|
||||
TagImplication.any_instance.expects(:reject!)
|
||||
subject.reject_expired(TagImplication)
|
||||
end
|
||||
|
||||
should "reject the bulk update request" do
|
||||
BulkUpdateRequest.any_instance.expects(:reject!)
|
||||
subject.reject_expired(BulkUpdateRequest)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user