forked from e621ng/e621ng
[Dmails] Fix senders copy being created when validations fail
This commit is contained in:
parent
9e2c7b2b5b
commit
632b611c4c
@ -39,6 +39,7 @@ class Dmail < ApplicationRecord
|
||||
copy = Dmail.new(params)
|
||||
copy.owner_id = copy.to_id
|
||||
copy.save unless copy.to_id == copy.from_id
|
||||
raise ActiveRecord::Rollback if copy.errors.any?
|
||||
|
||||
# sender's copy
|
||||
copy = Dmail.new(params)
|
||||
|
@ -77,6 +77,18 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a senders copy when validations fail" do
|
||||
Danbooru.config.stubs(:disable_throttles?).returns(false)
|
||||
@user = create(:user, created_at: 2.weeks.ago)
|
||||
@recipient = create(:user)
|
||||
as(@user) do
|
||||
(Danbooru.config.dmail_minute_limit + 1).times do
|
||||
Dmail.create_split(attributes_for(:dmail, from_id: @user.id, to_id: @recipient.id))
|
||||
end
|
||||
end
|
||||
assert_equal(Danbooru.config.dmail_minute_limit * 2, Dmail.count)
|
||||
end
|
||||
|
||||
should "should parse user names" do
|
||||
dmail = build(:dmail, owner: @user)
|
||||
dmail.to_id = nil
|
||||
|
Loading…
Reference in New Issue
Block a user