mentions: process mentions added in an edit (fix #2736)
This commit is contained in:
@@ -8,7 +8,8 @@ module Mentionable
|
||||
def mentionable(options = {})
|
||||
@mentionable_options = options
|
||||
|
||||
after_create :queue_mention_messages
|
||||
message_field = mentionable_option(:message_field)
|
||||
after_save :queue_mention_messages, if: :"#{message_field}_changed?"
|
||||
end
|
||||
|
||||
def mentionable_option(key)
|
||||
@@ -17,8 +18,11 @@ module Mentionable
|
||||
end
|
||||
|
||||
def queue_mention_messages
|
||||
text = read_attribute(self.class.mentionable_option(:message_field))
|
||||
names = DText.parse_mentions(text)
|
||||
message_field = self.class.mentionable_option(:message_field)
|
||||
text = send(message_field)
|
||||
text_was = send("#{message_field}_was")
|
||||
|
||||
names = DText.parse_mentions(text) - DText.parse_mentions(text_was)
|
||||
|
||||
names.uniq.each do |name|
|
||||
body = self.instance_exec(name, &self.class.mentionable_option(:body))
|
||||
|
||||
@@ -20,6 +20,21 @@ class CommentTest < ActiveSupport::TestCase
|
||||
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
|
||||
end
|
||||
|
||||
context "added in an edit" do
|
||||
should "dmail the added user" do
|
||||
@user1 = FactoryGirl.create(:user)
|
||||
@user2 = FactoryGirl.create(:user)
|
||||
@comment = FactoryGirl.create(:comment, :post_id => @post.id, :body => "@#{@user1.name}")
|
||||
|
||||
assert_no_difference("@user1.dmails.count") do
|
||||
assert_difference("@user2.dmails.count") do
|
||||
@comment.body = "@#{@user1.name} @#{@user2.name}"
|
||||
@comment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "in a quote block" do
|
||||
setup do
|
||||
@user2 = FactoryGirl.create(:user, :created_at => 2.weeks.ago)
|
||||
|
||||
Reference in New Issue
Block a user