Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix pending and published comment notifications

  • Loading branch information...
commit e5583f9933e942c30950262caf8e2d5df254d594 1 parent d0683b4
Bruno Bornsztein authored
3  app/controllers/comments_controller.rb
View
@@ -100,9 +100,8 @@ def create
commentable_type = get_commentable_type(params[:commentable_type])
@commentable = commentable_type.singularize.constantize.find(params[:commentable_id])
- @comment = Comment.new(params[:comment])
+ @comment = @commentable.comments.new(params[:comment])
- @comment.commentable = @commentable
@comment.recipient = @commentable.owner
@comment.user_id = current_user.id if current_user
@comment.author_ip = request.remote_ip #save the ip address for everyone, just because
5 app/models/comment.rb
View
@@ -13,7 +13,8 @@ class Comment < ActiveRecord::Base
validates_length_of :comment, :maximum => 2000
before_save :whitelist_attributes
- after_save :send_notifications
+ after_create :send_notifications
+ after_save :send_notifications, :if => Proc.new{|record| record.role_change.eql?(['pending', 'published']) }
validates_presence_of :user, :unless => Proc.new{|record| configatron.allow_anonymous_commenting }
validates_presence_of :author_email, :unless => Proc.new{|record| record.user } #require email unless logged in
@@ -94,7 +95,7 @@ def notify_previous_anonymous_commenters
def send_notifications
return if commentable.respond_to?(:send_comment_notifications?) && !commentable.send_comment_notifications?
- return unless self.role_changed? && !self.role.eql?('pending')
+ return if pending?
UserNotifier.comment_notice(self).deliver if should_notify_recipient?
self.notify_previous_commenters
self.notify_previous_anonymous_commenters if configatron.allow_anonymous_commenting
4 test/unit/comment_test.rb
View
@@ -127,6 +127,7 @@ def test_spam_comment_notification_handling
configatron.stubs(:akismet_key).returns('1234')
comment = post.comments.new(:comment => 'foo', :user => users(:aaron), :recipient => users(:quentin))
+
#no notifications for pending comments
assert_no_difference ActionMailer::Base.deliveries, :length do
comment.save!
@@ -137,11 +138,10 @@ def test_spam_comment_notification_handling
assert_difference ActionMailer::Base.deliveries, :length, 1 do
comment.save!
end
-
-
end
def test_should_create_user_comment_with_notification
+ Comment.any_instance.stubs(:spam?).returns(false)
user = users(:aaron)
assert_difference ActionMailer::Base.deliveries, :length, 2 do
user.comments.create!(:comment => 'foo', :user => users(:dwr), :recipient => users(:aaron))
Please sign in to comment.
Something went wrong with that request. Please try again.