dmails: add tests for automated dmails.

This commit is contained in:
evazion
2017-02-23 22:06:12 -06:00
parent b1af644f67
commit 6704e71377
2 changed files with 35 additions and 2 deletions

View File

@@ -64,6 +64,33 @@ class PostDisapprovalTest < ActiveSupport::TestCase
end
end
end
context "when sending dmails" do
setup do
@uploaders = FactoryGirl.create_list(:user, 2)
@disapprovers = FactoryGirl.create_list(:mod_user, 2)
# 2 uploaders, with 2 uploads each, and 2 disapprovals on each upload.
@uploaders.each do |uploader|
FactoryGirl.create_list(:post, 2, uploader: uploader).each do |post|
FactoryGirl.create(:post_disapproval, post: post, user: @disapprovers[0])
FactoryGirl.create(:post_disapproval, post: post, user: @disapprovers[1])
end
end
end
should "dmail the uploaders" do
bot = FactoryGirl.create(:user)
Danbooru.config.stubs(:system_user).returns(bot)
assert_difference(["@uploaders[0].dmails.count", "@uploaders[1].dmails.count"], 1) do
PostDisapproval.dmail_messages!
end
assert(@uploaders[0].dmails.exists?(from: bot, to: @uploaders[0]))
assert(@uploaders[1].dmails.exists?(from: bot, to: @uploaders[1]))
end
end
end
end
end

View File

@@ -13,7 +13,7 @@ class UserTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "promoting a user" do
setup do
CurrentUser.user = FactoryGirl.create(:moderator_user)
@@ -27,10 +27,16 @@ class UserTest < ActiveSupport::TestCase
assert_equal("You have been promoted to a Gold level account from Member.", @user.feedback.last.body)
end
should "create a dmail" do
should "send an automated dmail to the user" do
bot = FactoryGirl.create(:user)
Danbooru.config.stubs(:system_user).returns(bot)
assert_difference("Dmail.count", 2) do
@user.promote_to!(User::Levels::GOLD)
end
assert(@user.dmails.exists?(from: bot, to: @user, title: "You have been promoted"))
assert(bot.dmails.exists?(from: bot, to: @user, title: "You have been promoted"))
end
end