diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb
index af969f8470..24c45313b9 100644
--- a/app/controllers/tag_controller.rb
+++ b/app/controllers/tag_controller.rb
@@ -279,6 +279,13 @@ def create
uid: current_user.uid,
body: "@#{current_user.username} awards a #{barnstar_info_link} to #{node.drupal_user.name} for their awesome contribution!")
+ elsif tagname.split(':')[0] == "with"
+ user = User.find_by_username_case_insensitive(tagname.split(':')[1])
+ CommentMailer.notify_coauthor(user, node)
+ node.add_comment(subject: 'co-author',
+ uid: current_user.uid,
+ body: " @#{current_user.username} has marked #{tagname.split(':')[1]} as a co-author. ")
+
end
if saved
diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb
index ad29ec0cb2..7a3779b4c3 100644
--- a/app/mailers/comment_mailer.rb
+++ b/app/mailers/comment_mailer.rb
@@ -46,4 +46,12 @@ def notify_answer_author(user, comment)
@footer = feature('email-footer')
mail(to: user.email, subject: "New comment on your answer on '" + comment.parent.title + "'")
end
+
+ def notify_coauthor(user, note)
+ @user = user
+ @note = note
+ @author = note.author
+ @footer = feature('email-footer')
+ mail(to: user.email, subject: 'You were added as a co-author!').deliver
+ end
end
diff --git a/app/views/comment_mailer/notify_answer_author.html.erb b/app/views/comment_mailer/notify_answer_author.html.erb
index 67e44e29b6..a71671f869 100644
--- a/app/views/comment_mailer/notify_answer_author.html.erb
+++ b/app/views/comment_mailer/notify_answer_author.html.erb
@@ -2,7 +2,7 @@ Hi! There's been a new comment to your answer on '<%= @author.name %>' has added you as a co-author of '<%= @note.title %>'. Do NOT reply to this email; click this link to respond:
+
+
https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %>
+
+
+
+
+
+
Reply at: https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %>#comments
+
+
Report abuse to: moderators@<%= ActionMailer::Base.default_url_options[:host] %>
+
+ <%= @footer %>
+
+
diff --git a/app/views/comment_mailer/notify_note_author.html.erb b/app/views/comment_mailer/notify_note_author.html.erb
index b5665198ff..1d745db9b8 100644
--- a/app/views/comment_mailer/notify_note_author.html.erb
+++ b/app/views/comment_mailer/notify_note_author.html.erb
@@ -11,7 +11,7 @@ Do NOT reply to this email; click this link to respond:
https://<%= ActionMailer::Base.default_url_options[:host] %><%= @comment.node.path %>#c<%= @comment.cid %>
<% end %>
-<%= @comment.author.name %> wrote:
+<%= @comment.author.name %> wrote:
diff --git a/test/functional/tag_controller_test.rb b/test/functional/tag_controller_test.rb
index e7dbebbc2a..38b4c8fabc 100644
--- a/test/functional/tag_controller_test.rb
+++ b/test/functional/tag_controller_test.rb
@@ -305,6 +305,21 @@ def setup
end
end
+ test 'adds comment when creating coauthor' do
+ UserSession.create(users(:jeff))
+ user = users(:bob)
+ node = nodes(:one)
+
+ assert_difference 'Comment.count' do
+ tagname = "with:#{user.name}"
+ post :create,
+ name: tagname,
+ nid: node.id
+
+ assert_equal " [@#{node.author.name}](/profile/#{node.author.name}) has marked #{tagname.split(':')[1]} as a co-author. ", Comment.last.body
+ end
+ end
+
test 'should take node type as question if tag is a question tag' do
tag = tags(:question)
diff --git a/test/unit/comment_mailer_test.rb b/test/unit/comment_mailer_test.rb
index 1727c7a14e..5e70cdd23d 100644
--- a/test/unit/comment_mailer_test.rb
+++ b/test/unit/comment_mailer_test.rb
@@ -75,7 +75,7 @@ class CommentMailerTest < ActionMailer::TestCase
assert_equal "New comment on your answer on '" + comment.parent.title + "'", email.subject
assert email.body.include?("Hi! There's been a new comment to your answer on '#{comment.parent.title}'")
end
-
+
test 'notify barnstar' do
user = users(:bob)
note = nodes(:one)
@@ -90,4 +90,19 @@ class CommentMailerTest < ActionMailer::TestCase
assert_equal "You were awarded a Barnstar!", email.subject
assert email.body.include?("'#{user.name}' has awarded you a 'Barnstar' for your work in the research note '#{note.title}'")
end
-end
+
+ test 'notify coauthor' do
+ user = users(:bob)
+ note = nodes(:one)
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
+ CommentMailer.notify_coauthor(user, note)
+ end
+ assert !ActionMailer::Base.deliveries.empty?
+
+ email = ActionMailer::Base.deliveries.last
+ assert_equal ["do-not-reply@#{request_host}"], email.from
+ assert_equal [user.email], email.to
+ assert_equal "You were added as a co-author!", email.subject
+ assert email.body.include?("'#{note.author.name}' has added you as a co-author of '#{note.title}'")
+ end
+ end