diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 4e861d5d1..ea2a29114 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -31,9 +31,9 @@ class Dmail < ApplicationRecord creator_ip_addr.to_s end - def spam?(sender = CurrentUser.user) + def spam? return false if Danbooru.config.rakismet_key.blank? - return false if sender.is_gold? + return false if from.is_gold? super() end end @@ -58,7 +58,6 @@ class Dmail < ApplicationRecord def initialize_attributes self.from_id ||= CurrentUser.id self.creator_ip_addr ||= CurrentUser.ip_addr - self.is_spam = spam?(CurrentUser.user) end end @@ -73,6 +72,7 @@ class Dmail < ApplicationRecord # recipient's copy copy = Dmail.new(params) copy.owner_id = copy.to_id + copy.is_spam = copy.spam? copy.save unless copy.to_id == copy.from_id # sender's copy diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index 0d4427cce..a2ab36fc2 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -23,8 +23,8 @@ class DmailTest < ActiveSupport::TestCase should "not validate" do assert_difference("Dmail.count", 2)do - dmail = Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki") - assert(dmail.is_spam?) + Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki") + assert(@recipient.dmails.last.is_spam?) end end end