dmails: don't save copies of outgoing dmails sent by DanbooruBot.
There's not much sense in saving copies of everything DanbooruBot sends in DanbooruBot's inbox. They probably won't be checked so it just bloats the dmails table.
This commit is contained in:
@@ -61,7 +61,10 @@ class Dmail < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def create_automated(params)
|
||||
create_split(from: Danbooru.config.system_user, **params)
|
||||
dmail = Dmail.new(from: Danbooru.config.system_user, **params)
|
||||
dmail.owner = dmail.to
|
||||
dmail.save
|
||||
dmail
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -147,5 +147,26 @@ class DmailTest < ActiveSupport::TestCase
|
||||
recipient.reload
|
||||
assert(!recipient.has_mail?)
|
||||
end
|
||||
|
||||
context "that is automated" do
|
||||
setup do
|
||||
@bot = FactoryGirl.create(:user)
|
||||
Danbooru.config.stubs(:system_user).returns(@bot)
|
||||
end
|
||||
|
||||
should "only create a copy for the recipient" do
|
||||
Dmail.create_automated(to: @user, title: "test", body: "test")
|
||||
|
||||
assert @user.dmails.exists?(from: @bot, title: "test", body: "test")
|
||||
assert !@bot.dmails.exists?(from: @bot, title: "test", body: "test")
|
||||
end
|
||||
|
||||
should "fail gracefully if recipient doesn't exist" do
|
||||
assert_nothing_raised do
|
||||
dmail = Dmail.create_automated(to_name: "this_name_does_not_exist", title: "test", body: "test")
|
||||
assert_equal(["can't be blank"], dmail.errors[:to_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,12 +31,11 @@ class UserTest < ActiveSupport::TestCase
|
||||
bot = FactoryGirl.create(:user)
|
||||
Danbooru.config.stubs(:system_user).returns(bot)
|
||||
|
||||
assert_difference("Dmail.count", 2) do
|
||||
assert_difference("Dmail.count", 1) 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user