Skip to content

Commit

Permalink
Merge pull request #1129 from tuff-ghost/issue_3431
Browse files Browse the repository at this point in the history
3431: Chapter titles in batch subscription notification emails
  • Loading branch information
sarken committed May 2, 2014
2 parents 30a5dc2 + 4332ef9 commit 1acc684
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
20 changes: 4 additions & 16 deletions app/models/subscription.rb
Expand Up @@ -29,22 +29,10 @@ def name

def subject_text(creation)
authors = creation.pseuds.map{ |p| p.byline }.to_sentence
"#{authors} posted #{creation_name(creation)}"
end

def creation_name(creation)
if creation.is_a?(Chapter)
"#{chapter_name(creation)} of #{creation.work.title}"
elsif subscribable_type == 'User'
creation.title
elsif subscribable_type == 'Series'
"#{creation.title} in #{self.name} series"
end
end

def chapter_name(creation)
title = creation.chapter_title
title.match(/^Chapter /) ? title : "Chapter #{title}"
chapter_text = creation.is_a?(Chapter) ? "#{creation.chapter_header} of " : ""
work_title = creation.is_a?(Chapter) ? creation.work.title : creation.title
text = "#{authors} posted #{chapter_text}#{work_title}"
text += subscribable_type == "Series" ? " in the #{self.name} series" : ""
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/mailer.html.erb
Expand Up @@ -100,7 +100,7 @@
</p>

<p>
The Archive of Our Own is a fan-run and fan-supported archive that relies on <a href="<%= donate_url %>" style="color:#ffffff; text-decoration:underline">your support</a>.
The Archive of Our Own is a fan-run and fan-supported archive that relies on <a href="<%= donate_url %>" style="color:#ffffff; text-decoration:underline">your donations</a>.
</p>

<% if content_for?(:sent_at) %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/mailer.text.erb
Expand Up @@ -13,8 +13,7 @@ Archive of Our Own
<% end %>
If you've received this message in error, please contact Support at <%= root_url %>support.

The Archive of Our Own is a fan-run and fan-supported archive that relies on your support.
Donate at <%= donate_url %>.
The Archive of Our Own is a fan-run and fan-supported archive that relies on your donations: <%= donate_url %>.
<% if content_for?(:sent_at) %>

Sent at: <%= yield(:sent_at) %>.
Expand Down
Expand Up @@ -11,12 +11,13 @@
<%= this_work.backdate ? "backdated" : "new" %> work:
<% else %>
new chapter of <i><b><%= work_link %></b></i> (<%= this_work.word_count %> words):
<% chapter_title = (creation.chapter_header + (creation.title.blank? ? "" : ": #{creation.title}")).html_safe %>
<% end %>

<p>
<i>
<%= style_bold(creation.is_a?(Work) ? work_link :
style_link(@subscription.chapter_name(creation), work_chapter_url(this_work, creation))) %>
style_link(chapter_title, work_chapter_url(this_work, creation))) %>
</i> (<%= creation.word_count%> words)

<% unless @seen[this_work.id] %>
Expand Down
Expand Up @@ -3,9 +3,10 @@
<% @seen_summary = {} %>
<% @creations.each_with_index do |creation, index| %>
<% this_work = creation.respond_to?(:work) ? creation.work : creation %>
<%= this_work.pseuds.map{|p| p.byline}.to_sentence.html_safe %> posted a <% if creation.is_a?(Work) then %><%= this_work.backdate ? "backdated" : "new" %> work:<% else %>new chapter of <%= this_work.title %> (<%= this_work.word_count %> words):<% end %> <%= creation.is_a?(Work) ? work_url(this_work) : work_chapter_url(this_work, creation) %>
<%= creation.is_a?(Work) ? this_work.title.html_safe : @subscription.chapter_name(creation) %> (<%= creation.word_count%> words)<% unless @seen[this_work.id] %>
<%= this_work.pseuds.map{|p| p.byline}.to_sentence.html_safe %> posted a <% if creation.is_a?(Work) then %><%= this_work.backdate ? "backdated" : "new" %> work:<% else %>new chapter of <%= this_work.title %> (<%= this_work.word_count %> words):<% chapter_title = (creation.chapter_header + (creation.title.blank? ? "" : ": #{creation.title}")).html_safe %><% end %>
<%= creation.is_a?(Work) ? work_url(this_work) : work_chapter_url(this_work, creation) %>
<%= creation.is_a?(Work) ? this_work.title.html_safe : chapter_title %> (<%= creation.word_count%> words)<% unless @seen[this_work.id] %>
by <%= this_work.pseuds.map{|p| text_pseud(p)}.to_sentence.html_safe %><% end %>
<% if !creation.summary.blank? && creation.is_a?(Chapter) %>
Expand Down
36 changes: 26 additions & 10 deletions features/other/subscriptions.feature
Expand Up @@ -11,7 +11,7 @@
And all emails have been delivered

Scenario: subscribe to an author

When "second_user" subscribes to author "first_user"
And I am logged in as "first_user"
And I post the work "Awesome Story"
Expand All @@ -36,9 +36,9 @@
And the email should contain "first_user"
And the email should contain "posted"
And the email should contain "Chapter 2"

Scenario: unsubscribe from an author

When I am logged in as "second_user"
And I go to first_user's user page
And I press "Subscribe"
Expand All @@ -62,7 +62,7 @@
And I should be on my subscriptions page

Scenario: subscribe button on profile page

When I am logged in as "second_user"
And I go to first_user's profile page
And I press "Subscribe"
Expand All @@ -71,7 +71,7 @@
Then I should see "successfully unsubscribed"

Scenario: subscribe to individual work

When "second_user" subscribes to work "Awesome Story"
And a draft chapter is added to "Awesome Story"
Then 0 emails should be delivered
Expand All @@ -83,7 +83,23 @@
And the email should contain "posted"
And the email should contain "Chapter 2"

Scenario: subscribe to an individual work with an the & and < and > entitites in the title
Scenario: receive notification of a titled chapter

When "second_user" subscribes to work "Cake Story"
And I am logged in as "wip_author"
And I view the work "Cake Story"
And I follow "Add Chapter"
And I fill in "Chapter title" with "ICE CREAM CAKE"
And I fill in "content" with "meltiiiinnngg"
And I press "Post Without Preview"
And subscription notifications are sent
Then 1 email should be delivered to "second_user@foo.com"
And the email should contain "wip_author"
And the email should contain "posted"
And the email should not contain "Chapter ICE CREAM CAKE"
And the email should contain "Chapter 2: ICE CREAM CAKE"

Scenario: subscribe to an individual work with an the & and < and > characters in the title

Given I have loaded the fixtures
And the following activated users exist
Expand All @@ -105,9 +121,9 @@
And I go to my subscriptions page
And I press "Unsubscribe from I am <strong>er Than Yesterday & Other Lies"
Then I should see "You have successfully unsubscribed from I am <strong>er Than Yesterday & Other Lies"

Scenario: subscribe to series

When "second_user" subscribes to series "Awesome Series"
And I am logged in as "series_author"
And I set up the draft "Second Work"
Expand All @@ -121,7 +137,7 @@
And the email should contain "new work"

Scenario: batched subscription notifications

When "second_user" subscribes to author "first_user"
And I am logged in as "first_user"
And I post the work "The First Awesome Story"
Expand All @@ -137,4 +153,4 @@
And the email should contain "Another"
And the email should contain "A Third"
And the email should contain "A FOURTH"

0 comments on commit 1acc684

Please sign in to comment.