Skip to content

Commit

Permalink
Emails displayed in same thread. (publiclab#8521)
Browse files Browse the repository at this point in the history
* Emails displayed in same thread.

* Emails displayed in same thread test fixes.

* Emails displaye in same thread - Fixed Like tests

* Emails displayed in same thread - Likes test fixes
  • Loading branch information
FrankieMFerreira authored and billymoroney1 committed Dec 28, 2021
1 parent 7ab914a commit 2f62065
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def notify(user, comment)
@user = user
@comment = comment
@footer = feature('email-footer')
mail(to: user.email, subject: "New comment on #{comment.parent.title}" \
" (##{comment.parent.id}) - #c#{comment.id} ")
mail(to: user.email, subject: "New comment on #{comment.node.title}" \
" (##{comment.node.id}) - #c#{comment.id} ")
end

def notify_note_author(user, comment)
Expand Down
13 changes: 9 additions & 4 deletions app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def notify_node_creation(node)
end

def notify_note_liked(node, user)
subject = "[PublicLab] #{user.username} liked your " +
(node.has_power_tag('question') ? 'question' : 'research note') +
" (##{node.id})"
subject = '[PublicLab] ' +
(node.has_power_tag('question') ? 'Question: ' : '') +
node.title +
" (##{node.id}) "
@user = user
@node = node
@tags = node.tags.collect(&:name).join(',')
Expand All @@ -37,6 +38,10 @@ def notify_note_liked(node, user)
end

def notify_tag_added(node, tag, tagging_user)
subject = '[PublicLab] ' +
(node.has_power_tag('question') ? 'Question: ' : '') +
node.title +
" (##{node.id}) "
@tag = tag
@node = node
@tags = node.tags.collect(&:name).join(',')
Expand All @@ -62,7 +67,7 @@ def notify_tag_added(node, tag, tagging_user)
mail(
to: "notifications@#{ActionMailer::Base.default_url_options[:host]}",
bcc: recipients,
subject: "#{node.title} (##{node.id})"
subject: subject
)
end

Expand Down
4 changes: 2 additions & 2 deletions test/functional/like_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def teardown; end
assert_equal cached_likes + 1, note.cached_likes
assert ActionMailer::Base.deliveries.size, 1
assert ActionMailer::Base.deliveries.collect(&:to).include?([note.author.email])
assert ActionMailer::Base.deliveries.collect(&:subject).include?("[PublicLab] #{current_user.username} liked your " + (note.has_power_tag('question') ? 'question' : 'research note') + " (##{note.id})")
assert ActionMailer::Base.deliveries.collect(&:subject).include?("[PublicLab] " + (note.has_power_tag('question') ? 'Question: ' : '') + "#{note.title} (##{note.id}) ")
end

test 'delete like' do
Expand Down Expand Up @@ -73,7 +73,7 @@ def teardown; end
note = Node.find note.id
cached_likes = note.cached_likes

current_user = User.find 2
current_user = User.find 2
current_user.ban #banned user

note = Node.find note.id
Expand Down
6 changes: 3 additions & 3 deletions test/unit/subscription_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SubscriptionMailerTest < ActionMailer::TestCase
email = ActionMailer::Base.deliveries.last
assert_equal ["notifications@#{request_host}"], email.from
assert_equal [node.author.email], email.to
assert_equal "[PublicLab] #{user.username} liked your research note (##{node.id})", email.subject
assert_equal '[PublicLab] ' + (node.has_power_tag('question') ? 'Question: ' : '') + "#{node.title} (##{node.id}) ", email.subject
assert email.body.include?("Public Lab contributor #{user.username} (https://#{request_host}/profile/#{user.username}) just liked your research note")
end

Expand All @@ -64,7 +64,7 @@ class SubscriptionMailerTest < ActionMailer::TestCase
email = ActionMailer::Base.deliveries.last
assert_equal ["notifications@#{request_host}"], email.from
assert_equal [node.author.email], email.to
assert_equal "[PublicLab] #{user.username} liked your question (##{node.id})", email.subject
assert_equal '[PublicLab] ' + (node.has_power_tag('question') ? 'Question: ' : '') + "#{node.title} (##{node.id}) ", email.subject
assert email.body.include?("Public Lab contributor #{user.username} (https://#{request_host}/profile/#{user.username}) just liked your question")
end

Expand All @@ -86,7 +86,7 @@ class SubscriptionMailerTest < ActionMailer::TestCase
assert_equal ["notifications@#{request_host}"], email.from
assert_equal ["notifications@#{request_host}"], email.to
assert email.bcc.include?(users_to_email.last.email)
assert_equal "#{node.title} (##{node.id})", email.subject
assert_equal '[PublicLab] ' + (node.has_power_tag('question') ? 'Question: ' : '') + "#{node.title} (##{node.id}) ", email.subject
assert email.body.include?("was tagged with")
end
end

0 comments on commit 2f62065

Please sign in to comment.