forked from e621ng/e621ng
[Tests] Fix forum post/topic tests
This commit is contained in:
parent
16b28b5666
commit
a023c2806e
@ -34,6 +34,11 @@ User.find_or_create_by!(name: Danbooru.config.system_user) do |user|
|
||||
user.level = User::Levels::ADMIN
|
||||
end
|
||||
|
||||
ForumCategory.find_or_create_by!(id: Danbooru.config.alias_implication_forum_category) do |category|
|
||||
category.name = "Tag Alias and Implication Suggestions"
|
||||
category.can_view = 0
|
||||
end
|
||||
|
||||
unless Rails.env.test?
|
||||
CurrentUser.user = admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
@ -132,33 +132,29 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_difference("ForumPost.count", 1) do
|
||||
post_auth forum_posts_path, @user, params: {:forum_post => {:body => "xaxaxa", :topic_id => @forum_topic.id}}
|
||||
end
|
||||
|
||||
forum_post = ForumPost.last
|
||||
assert_redirected_to(forum_topic_path(@forum_topic))
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
should "destroy the posts" do
|
||||
delete_auth forum_post_path(@forum_post), @mod
|
||||
assert_redirected_to(forum_post_path(@forum_post))
|
||||
@forum_post.reload
|
||||
assert_equal(true, @forum_post.is_deleted?)
|
||||
get_auth forum_post_path(@forum_post), @mod
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
context "unhide action" do
|
||||
setup do
|
||||
as(@mod) do
|
||||
@forum_post.update(is_deleted: true)
|
||||
@forum_post.hide!
|
||||
end
|
||||
end
|
||||
|
||||
should "restore the post" do
|
||||
post_auth undelete_forum_post_path(@forum_post), @mod
|
||||
post_auth unhide_forum_post_path(@forum_post), @mod
|
||||
assert_redirected_to(forum_post_path(@forum_post))
|
||||
@forum_post.reload
|
||||
assert_equal(false, @forum_post.is_deleted?)
|
||||
assert_equal(false, @forum_post.is_hidden?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "not allow users to see the topic" do
|
||||
get_auth forum_topic_path(@forum_topic), @user
|
||||
assert_redirected_to forum_topics_path
|
||||
assert_response :forbidden
|
||||
end
|
||||
|
||||
should "not bump the forum for users without access" do
|
||||
@ -151,7 +151,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "create a new forum topic and post" do
|
||||
assert_difference(["ForumPost.count", "ForumTopic.count"], 1) do
|
||||
post_auth forum_topics_path, @user, params: {:forum_topic => {:title => "bababa", :original_post_attributes => {:body => "xaxaxa"}}}
|
||||
post_auth forum_topics_path, @user, params: {:forum_topic => {:title => "bababa", :category_id => Danbooru.config.alias_implication_forum_category, :original_post_attributes => {:body => "xaxaxa"}}}
|
||||
end
|
||||
|
||||
forum_topic = ForumTopic.last
|
||||
@ -168,24 +168,22 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "destroy the topic and any associated posts" do
|
||||
delete_auth forum_topic_path(@forum_topic), @mod
|
||||
assert_redirected_to(forum_topic_path(@forum_topic))
|
||||
@forum_topic.reload
|
||||
assert(@forum_topic.is_deleted?)
|
||||
assert_response :no_content
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
context "unhide action" do
|
||||
setup do
|
||||
as(@mod) do
|
||||
@forum_topic.update(is_deleted: true)
|
||||
@forum_topic.hide!
|
||||
end
|
||||
end
|
||||
|
||||
should "restore the topic" do
|
||||
post_auth undelete_forum_topic_path(@forum_topic), @mod
|
||||
post_auth unhide_forum_topic_path(@forum_topic), @mod
|
||||
assert_redirected_to(forum_topic_path(@forum_topic))
|
||||
@forum_topic.reload
|
||||
assert(!@forum_topic.is_deleted?)
|
||||
assert(!@forum_topic.is_hidden?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,54 +25,6 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "that mentions a user" do
|
||||
context "in a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not create a dmail" do
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] blah [quote]@#{@user2.name}[/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 0) do
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote][quote]@#{@user2.name}[/quote][/quote]")
|
||||
end
|
||||
|
||||
assert_difference("Dmail.count", 1) do
|
||||
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "[quote]@#{@user2.name}[/quote] @#{@user2.name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "outside a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryBot.create(:user)
|
||||
@post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
|
||||
end
|
||||
|
||||
should "create a dmail" do
|
||||
assert_difference("Dmail.count", 1) do
|
||||
@post.save
|
||||
end
|
||||
|
||||
dmail = Dmail.last
|
||||
assert_equal(<<-EOS.strip_heredoc, dmail.body)
|
||||
@#{CurrentUser.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
|
||||
|
||||
[quote]
|
||||
Hey @#{@user2.name} check this out!
|
||||
[/quote]
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "that belongs to a topic with several pages of posts" do
|
||||
setup do
|
||||
Danbooru.config.stubs(:posts_per_page).returns(3)
|
||||
@ -89,11 +41,11 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
CurrentUser.user = FactoryBot.create(:moderator_user)
|
||||
end
|
||||
|
||||
|
||||
should "update the topic's updated_at timestamp" do
|
||||
@topic.reload
|
||||
assert_equal(@posts[-1].updated_at.to_i, @topic.updated_at.to_i)
|
||||
@posts[-1].delete!
|
||||
@posts[-1].hide!
|
||||
@topic.reload
|
||||
assert_equal(@posts[-2].updated_at.to_i, @topic.updated_at.to_i)
|
||||
end
|
||||
@ -106,7 +58,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
assert_equal(3, @posts[6].forum_topic_page)
|
||||
end
|
||||
|
||||
should "update the topic's updated_at when deleted" do
|
||||
should "update the topic's updated_at when destroyed" do
|
||||
@posts.last.destroy
|
||||
@topic.reload
|
||||
assert_equal(@posts[8].updated_at.to_s, @topic.updated_at.to_s)
|
||||
@ -142,26 +94,6 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
assert_not_equal(@original_topic_updated_at.to_s, @topic.updated_at.to_s)
|
||||
end
|
||||
|
||||
should "update the topic when updated only for the original post" do
|
||||
posts = []
|
||||
3.times do
|
||||
posts << FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
|
||||
end
|
||||
|
||||
# updating the original post
|
||||
Timecop.travel(1.second.from_now) do
|
||||
posts.first.update(:body => "xxx")
|
||||
end
|
||||
@topic.reload
|
||||
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)
|
||||
|
||||
# updating a non-original post
|
||||
Timecop.travel(2.seconds.from_now) do
|
||||
posts.last.update(:body => "xxx")
|
||||
end
|
||||
assert_equal(posts.first.updated_at.to_s, @topic.updated_at.to_s)
|
||||
end
|
||||
|
||||
should "be searchable by body content" do
|
||||
post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
|
||||
assert_equal(1, ForumPost.search(body_matches: "xxx").count)
|
||||
|
@ -138,8 +138,8 @@ class ForumTopicTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be searchable by category id" do
|
||||
assert_equal(1, ForumTopic.search(:category_id => 0).count)
|
||||
assert_equal(0, ForumTopic.search(:category_id => 1).count)
|
||||
assert_equal(0, ForumTopic.search(:category_id => 0).count)
|
||||
assert_equal(1, ForumTopic.search(:category_id => Danbooru.config.alias_implication_forum_category).count)
|
||||
end
|
||||
|
||||
should "initialize its creator" do
|
||||
|
@ -2,13 +2,11 @@ require 'test_helper'
|
||||
|
||||
class TagAliasTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
Sidekiq::Testing::inline!
|
||||
|
||||
category = ForumCategory.create(id: Danbooru.config.alias_implication_forum_category, name: 'Tag Requests')
|
||||
Sidekiq::Testing.inline!
|
||||
end
|
||||
|
||||
teardown do
|
||||
Sidekiq::Testing::fake!
|
||||
Sidekiq::Testing.fake!
|
||||
end
|
||||
|
||||
context "A tag alias" do
|
||||
|
@ -3,13 +3,11 @@ require 'test_helper'
|
||||
class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
setup do
|
||||
Sidekiq::Testing::inline!
|
||||
|
||||
category = ForumCategory.create(id: Danbooru.config.alias_implication_forum_category, name: 'Tag Requests')
|
||||
Sidekiq::Testing.inline!
|
||||
end
|
||||
|
||||
teardown do
|
||||
Sidekiq::Testing::fake!
|
||||
Sidekiq::Testing.fake!
|
||||
end
|
||||
|
||||
context "A tag implication" do
|
||||
|
Loading…
Reference in New Issue
Block a user