From 1b41eda76883b1b908b656d464245e60c1f5af69 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 12 Dec 2008 20:07:53 -0300 Subject: [PATCH] ActionItem870: enhancing the feature --- app/models/comment.rb | 9 +++++++-- test/unit/comment_notifier_test.rb | 8 ++++++++ test/unit/comment_test.rb | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 339cb31..0a53176 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -27,6 +27,10 @@ class Comment < ActiveRecord::Base end end + def author_email + author ? author.email : email + end + def url article.url.merge(:anchor => anchor) end @@ -57,8 +61,9 @@ class Comment < ActiveRecord::Base recipients profile.email from "#{profile.environment.name} <#{profile.environment.contact_email}>" subject _("%s - New comment in '%s'") % [profile.environment.name, comment.article.title] - body :name => (comment.author.nil? ? comment.name : comment.author.name), - :email => (comment.author.nil? ? comment.email : comment.author.email), + headers['Reply-To'] = comment.author_email + body :name => comment.author_name, + :email => comment.author_email, :title => comment.title, :body => comment.body, :article_url => comment.url, diff --git a/test/unit/comment_notifier_test.rb b/test/unit/comment_notifier_test.rb index 4eac274..4ab77c3 100644 --- a/test/unit/comment_notifier_test.rb +++ b/test/unit/comment_notifier_test.rb @@ -37,6 +37,14 @@ class CommentNotifierTest < Test::Unit::TestCase assert_match /user_comment_test/, sent.body end + should "add a Reply-To header set to the commenter e-mail" do + p = create_user('user_comment_test', :email => 'my@email.com').person + a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) + a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') + sent = ActionMailer::Base.deliveries.first + assert_equal ['my@email.com'], sent.reply_to + end + should 'display unauthenticated author name and email in delivered mail' do p = create_user('user_comment_test').person a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 241d059..c817dc0 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -78,6 +78,15 @@ class CommentTest < Test::Unit::TestCase assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name end + should "provide author e-mail for athenticated authors" do + owner = create_user('testuser').person + assert_equal owner.email, Comment.new(:author => owner).author_email + end + + should "provide author e-mail for unauthenticated author" do + assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_email + end + should 'provide url to comment' do art = Article.new art.expects(:url).returns({ :controller => 'lala', :action => 'something' }) -- libgit2 0.21.2