diff --git a/app/models/comment.rb b/app/models/comment.rb index 34cf5d3..6667f00 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -91,7 +91,7 @@ class Comment < ActiveRecord::Base after_create :schedule_notification def schedule_notification - Delayed::Job.enqueue CommentHandler.new(self.id) + Delayed::Job.enqueue CommentHandler.new(self.id, :verify_and_notify) end delegate :environment, :to => :profile @@ -214,15 +214,23 @@ class Comment < ActiveRecord::Base def spam! self.spam = true self.save! - plugins.dispatch(:comment_marked_as_spam, self) + Delayed::Job.enqueue(CommentHandler.new(self.id, :marked_as_spam)) self end def ham! self.spam = false self.save! - plugins.dispatch(:comment_marked_as_ham, self) + Delayed::Job.enqueue(CommentHandler.new(self.id, :marked_as_ham)) self end + def marked_as_spam + plugins.dispatch(:comment_marked_as_spam, self) + end + + def marked_as_ham + plugins.dispatch(:comment_marked_as_ham, self) + end + end diff --git a/app/models/comment_handler.rb b/app/models/comment_handler.rb index 130bc50..dcb2ff3 100644 --- a/app/models/comment_handler.rb +++ b/app/models/comment_handler.rb @@ -1,8 +1,8 @@ -class CommentHandler < Struct.new(:comment_id) +class CommentHandler < Struct.new(:comment_id, :method) def perform comment = Comment.find(comment_id) - comment.verify_and_notify + comment.send(method) rescue ActiveRecord::RecordNotFound # just ignore non-existing comments end diff --git a/test/unit/comment_handler_test.rb b/test/unit/comment_handler_test.rb index d6f7b9b..242c1f0 100644 --- a/test/unit/comment_handler_test.rb +++ b/test/unit/comment_handler_test.rb @@ -12,11 +12,11 @@ class CommentHandlerTest < ActiveSupport::TestCase handler.perform end - should 'call Comment#notify_by_mail' do - handler = CommentHandler.new(-1) + should 'call Comment#whatever_method' do + handler = CommentHandler.new(-1, :whatever_method) comment = Comment.new Comment.stubs(:find).with(-1).returns(comment) - comment.expects(:verify_and_notify) + comment.expects(:whatever_method) handler.perform end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index ac68b1d..4a46c4c 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -517,6 +517,7 @@ class CommentTest < ActiveSupport::TestCase c = create_comment c.spam! + process_delayed_job_queue assert_equal c, SpamNotification.marked_as_spam end @@ -527,6 +528,7 @@ class CommentTest < ActiveSupport::TestCase c = create_comment c.ham! + process_delayed_job_queue assert_equal c, SpamNotification.marked_as_ham end -- libgit2 0.21.2