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.

326 CHAPTER 12 Sending email<br />

A<br />

B<br />

creating new ticket<br />

Ticketee<br />

Figure 12.4<br />

Alice creates a ticket.<br />

A Ticket<br />

0 comments<br />

Watchers<br />

Alice<br />

To automatically subscribe a user to a ticket of a new comment, use an after_create,<br />

just as you did in the Ticket model for only the author of that ticket. But first, you<br />

need to ensure that this works!<br />

You’ll add another scenario to the “Ticket notifications” feature, but first let’s consider<br />

the current flow. A couple of diagrams help explain this process.<br />

First, let’s look at figure 12.4. Here, alice@ticketee.com creates a ticket that will<br />

automatically subscribe her to be notified of any comments posted to it.<br />

Next, figure 12.5. Then bob@ticketee.com<br />

comes along and leaves a comment on the<br />

ticket, which should subscribe bob@ticke-<br />

tee.com to these ticket updates. This is the feature<br />

that you’ll code in a short while. After Bob<br />

has commented on the ticket, Alice receives a<br />

notification telling her just that. Now that Bob<br />

is subscribed to the ticket, he should receive<br />

comment notifications every time somebody<br />

else—such as Alice—comments on the ticket,<br />

as shown in figure 12.6.<br />

In this case, alice@ticketee.com shouldn’t<br />

receive a notification about a comment if she’s<br />

the one posting it! With the scenario<br />

explained, you can write it in Cucumber-form<br />

at the bottom of the “Ticket notifications” feature,<br />

as shown in the following listing:<br />

A<br />

B<br />

notified of B’s comment<br />

comments on ...<br />

Ticketee<br />

Figure 12.5 Bob<br />

comments on the ticket.<br />

A<br />

B<br />

comments on ...<br />

notified of<br />

A’s comment<br />

Figure 12.6<br />

Alice comments on<br />

the ticket, too.<br />

B is added to ...<br />

Ticketee<br />

A Ticket<br />

1 comment<br />

Watchers<br />

Alice<br />

Bob<br />

... the ticket<br />

A Ticket<br />

2 comments<br />

Watchers<br />

Alice<br />

Bob

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

Saved successfully!

Ooh no, something went wrong!