27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

252 CHAPTER 10 Tracking state<br />

With the code in place not only to create comments but also to display them, your<br />

feature should pass when you run it with bin/cucumber features/creating<br />

_comments.feature:<br />

2 scenario (2 passed)<br />

23 steps (23 passed)<br />

Good to see. You’ve now got the base for users to be able to change the state of a<br />

ticket. Before proceeding further, you should make sure that everything is working as<br />

it should by running rake cucumber:ok spec, and you should also commit your<br />

changes. When you run the tests, you’ll see this output:<br />

48 scenarios (48 passed)<br />

492 steps (492 passed)<br />

# and<br />

32 examples, 0 failures, 15 pending<br />

Good stuff! Let’s commit and push this:<br />

git add .<br />

git commit -m "Users can now leave comments on tickets"<br />

git push<br />

With this form added to the ticket’s page, users are now able to leave comments on<br />

tickets. This feature of your application is useful because it provides a way for users of<br />

a project to have a discussion about a ticket and keep track of it. Next up, we’ll look at<br />

adding another way to provide additional context to this ticket by adding states.<br />

10.2 Changing a ticket’s state<br />

States provide a helpful way of standardizing the way that a ticket’s<br />

progress is tracked. By glancing at the state of a ticket, a user will be<br />

able to determine if that ticket needs more work or if it’s complete,<br />

as shown in figure 10.4.<br />

To change a ticket’s state, you’ll add a drop-down box on the<br />

comment form where a user can select a state from a list of states.<br />

These states will be stored in another table called states, and they’ll be accessed<br />

through the State model.<br />

Eventually, you’ll let some users of the application have the ability to add states for<br />

the select box and make one of them the default. For now, you’ll focus on creating the<br />

drop-down box so that states can be selected.<br />

As usual, you’ll cover creating a comment that changes a ticket’s state by writing<br />

another scenario. The scenario you’ll now write goes at the bottom of features/<br />

creating_comments.feature and is shown in the following listing.<br />

Listing 10.9 features/creating_comments.feature<br />

Scenario: Changing a ticket's state<br />

When I follow "Change a ticket's state"<br />

When I fill in "Text" with "This is a real issue"<br />

Figure 10.4<br />

A ticket’s state

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

Saved successfully!

Ooh no, something went wrong!