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.

244 CHAPTER 10 Tracking state<br />

used, then you’d have no record of that state ever existing. It’s best if, once states are<br />

created and used on a ticket, they can’t be deleted. 1<br />

To track the states, you’ll let users leave a comment. With a comment, users will be<br />

able to leave a text message about the ticket and may also elect to change the state of<br />

the ticket to something else by selecting it from a drop-down box. But not all users will<br />

be able to leave a comment and change the state. You’ll protect both creating a comment<br />

and changing the state.<br />

By the time you’re done with all of this, the users of your application will have the<br />

ability to add comments to your tickets. Some users, due to permission restriction, will<br />

be able to change the state of a ticket through the comment interface.<br />

You’ll begin with creating that interface for a user to create a comment and then<br />

build on top of that the ability for the user to change the state of a ticket while adding<br />

a comment. Let’s get into it.<br />

10.1 Leaving a comment<br />

Let’s get started by adding the ability to leave<br />

a comment. When you’re done you will have<br />

a simple form that looks like figure 10.1.<br />

To get started with this you’ll write a<br />

Cucumber feature that goes through the<br />

process of creating a comment. When you’re<br />

done with this feature, you will have a comment<br />

form at the bottom of the show action<br />

for the TicketsController which you’ll<br />

then use as a base for adding your state dropdown<br />

box later on. Put this feature in a new<br />

file at features/creating_comments.feature,<br />

and make it look like the following listing.<br />

Listing 10.1 features/creating_comments.feature<br />

Feature: Creating comments<br />

In order to update a ticket's progress<br />

As a user<br />

I want to leave comments<br />

Figure 10.1 The comment form<br />

Background:<br />

Given there are the following users:<br />

| email | password |<br />

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

And I am signed in as them<br />

And there is a project called "Ticketee"<br />

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

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

1 Alternatively, these states could be moved into an “archive” state of their own so they couldn’t be assigned to<br />

new tickets but still would be visible on older tickets.

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

Saved successfully!

Ooh no, something went wrong!