Commit 1b41eda76883b1b908b656d464245e60c1f5af69

Authored by Antonio Terceiro
1 parent 9d33b5cb

ActionItem870: enhancing the feature

app/models/comment.rb
... ... @@ -27,6 +27,10 @@ class Comment < ActiveRecord::Base
27 27 end
28 28 end
29 29  
  30 + def author_email
  31 + author ? author.email : email
  32 + end
  33 +
30 34 def url
31 35 article.url.merge(:anchor => anchor)
32 36 end
... ... @@ -57,8 +61,9 @@ class Comment < ActiveRecord::Base
57 61 recipients profile.email
58 62 from "#{profile.environment.name} <#{profile.environment.contact_email}>"
59 63 subject _("%s - New comment in '%s'") % [profile.environment.name, comment.article.title]
60   - body :name => (comment.author.nil? ? comment.name : comment.author.name),
61   - :email => (comment.author.nil? ? comment.email : comment.author.email),
  64 + headers['Reply-To'] = comment.author_email
  65 + body :name => comment.author_name,
  66 + :email => comment.author_email,
62 67 :title => comment.title,
63 68 :body => comment.body,
64 69 :article_url => comment.url,
... ...
test/unit/comment_notifier_test.rb
... ... @@ -37,6 +37,14 @@ class CommentNotifierTest &lt; Test::Unit::TestCase
37 37 assert_match /user_comment_test/, sent.body
38 38 end
39 39  
  40 + should "add a Reply-To header set to the commenter e-mail" do
  41 + p = create_user('user_comment_test', :email => 'my@email.com').person
  42 + a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true)
  43 + a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!')
  44 + sent = ActionMailer::Base.deliveries.first
  45 + assert_equal ['my@email.com'], sent.reply_to
  46 + end
  47 +
40 48 should 'display unauthenticated author name and email in delivered mail' do
41 49 p = create_user('user_comment_test').person
42 50 a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true)
... ...
test/unit/comment_test.rb
... ... @@ -78,6 +78,15 @@ class CommentTest &lt; Test::Unit::TestCase
78 78 assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name
79 79 end
80 80  
  81 + should "provide author e-mail for athenticated authors" do
  82 + owner = create_user('testuser').person
  83 + assert_equal owner.email, Comment.new(:author => owner).author_email
  84 + end
  85 +
  86 + should "provide author e-mail for unauthenticated author" do
  87 + assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_email
  88 + end
  89 +
81 90 should 'provide url to comment' do
82 91 art = Article.new
83 92 art.expects(:url).returns({ :controller => 'lala', :action => 'something' })
... ...