27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Subscribing to updates<br />

Listing 12.5 features/ticket_notifications.feature<br />

Scenario: Comment authors are automatically subscribed to a ticket<br />

When I follow "TextMate 2"<br />

And I follow "Release date"<br />

And I fill in "Text" with "Is it out yet?"<br />

And I press "Create Comment"<br />

Then I should see "Comment has been created."<br />

When I follow "Sign out"<br />

Given a clear email queue<br />

Given I am signed in as "alice@ticketee.com"<br />

When I follow "TextMate 2"<br />

And I follow "Release date"<br />

And I fill in "Text" with "Not yet!"<br />

And I press "Create Comment"<br />

Then I should see "Comment has been created."<br />

Then "bob@ticketee.com" should receive an email<br />

Then "alice@ticketee.com" should have no emails<br />

In this scenario, you’re already logged in as bob@ticketee.com (courtesy of the<br />

Background). With Bob, you create a comment on the “Release date” ticket, check<br />

that alice@ticketee.com receives an email, and then sign out. Then you clear the<br />

email queue to ensure that alice@ticketee.com receives no emails after this point. You<br />

sign in as alice@ticketee.com and create a comment, which should trigger an email to<br />

be sent to bob@ticketee.com, but not to alice@ticketee.com. When you run this scenario<br />

using bin/cucumber features/ticket_notifications.feature:36, you see<br />

that Bob never receives an email:<br />

expected: 1,<br />

got: 0 (using ==) (RSpec::Expectations::ExpectationNotMetError)<br />

...<br />

features/ticket_notifications.feature:54<br />

This is failing on the step that checks if bob@ticketee.com has an email. You can<br />

therefore determine that bob@ticketee.com isn’t subscribed to receive comment<br />

update notifications as he should have been when he posted a comment. You need to<br />

add any commenter to the watchers list when they post a comment so that they’re<br />

notified of ticket updates.<br />

12.2.2 Automatically adding a user to a watchlist<br />

To keep users up to date with tickets, you’ll automatically add them to the watchers<br />

list for that ticket when they post a comment. You currently do this when people create<br />

a new ticket, and so you can apply the same logic to adding them to the list when<br />

they create a comment.<br />

You can define another after_create callback in the Comment model by using this<br />

line:<br />

after_create :creator_watches_ticket<br />

327

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!