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 />

You implement the on and off functionality simultaneously by writing a new feature<br />

in a new file at features/watching_tickets.feature. Let’s start with the code from the<br />

following listing.<br />

Listing 12.6 features/watching_tickets.feature<br />

Feature: Watching tickets<br />

In order to keep up to date with tickets<br />

As a user<br />

I want to choose to subscribe to their updates<br />

Background:<br />

Given there are the following users:<br />

| email | password |<br />

| user@ticketee.com | password |<br />

Given there is a project called "TextMate 2"<br />

And "user@ticketee.com" can view the "TextMate 2" project<br />

And "user@ticketee.com" has created a ticket for this project:<br />

| title | description |<br />

| Release date | TBA very shortly. |<br />

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

Given I am on the homepage<br />

In this example, you create a single user, a project, and a ticket. Because this user created<br />

the ticket, they’re automatically subscribed to watching this ticket and therefore<br />

they should see the Stop Watching This Ticket button on the ticket page. You test this<br />

by writing the scenario from the following listing underneath your Background.<br />

Listing 12.7 features/watching_tickets.feature<br />

Scenario: Ticket watch toggling<br />

When I follow "TextMate 2"<br />

And I follow "Release date"<br />

Then I should see "user@ticketee.com" within "#watchers"<br />

And I press "Stop watching this ticket"<br />

Then I should see "You are no longer watching this ticket"<br />

And I should not see "user@ticketee.com" within "#watchers"<br />

To begin to watch a ticket again, all the user has to do is click the Watch This Ticket<br />

button, which you can also test by adding the following code to this scenario:<br />

When I press "Watch this ticket"<br />

Then I should see "You are now watching this ticket"<br />

And I should see "user@ticketee.com" within "#watchers"<br />

See? That’s how you test the watching/not watching<br />

function simultaneously! You don’t need to post a comment<br />

and test that a user is truly watching this ticket; you<br />

can instead check to see if a user’s name appears in a list<br />

of all the watchers on the right side of the ticket page,<br />

which will look like figure 12.8.<br />

329<br />

Figure 12.8 Who’s watching

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

Saved successfully!

Ooh no, something went wrong!