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.

292 CHAPTER 11 Tagging<br />

11.2 Adding more tags<br />

The tags for a ticket can change<br />

throughout the ticket’s life; new tags<br />

can be added and old ones can be<br />

deleted. Let’s look at how you can add<br />

more tags to a ticket after it’s been created<br />

through the comments form.<br />

Underneath the comment form on a<br />

ticket’s page, add the same Tags field<br />

that you previously used to add tags to<br />

your ticket on the new ticket page. One<br />

thing you have to keep in mind here is<br />

that if someone enters a tag that’s<br />

already been entered, you don’t want it<br />

to show up.<br />

You’ve got two scenarios to implement<br />

then: the first is a vanilla addition<br />

of tags to a ticket through a comment,<br />

and the second is a scenario ensuring<br />

Figure 11.3 Comment form with tags<br />

that duplicate tags do not appear. Let’s implement this function one scenario at a<br />

time. When you’re done, you’ll end up with the pretty picture shown in figure 11.3.<br />

11.2.1 Adding tags through a comment<br />

To test that users can add tags when they’re creating a comment, you add a new scenario<br />

to the features/creating_comments.feature feature that looks like this listing:<br />

Listing 11.2 features/creating_comments.feature<br />

Scenario: Adding a tag to a ticket<br />

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

Then I should not see "bug" within "#ticket #tags"<br />

And I fill in "Text" with "Adding the bug tag"<br />

And I fill in "Tags" with "bug"<br />

And I press "Create Comment"<br />

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

Then I should see "bug" within "#ticket #tags"<br />

First, you make sure you don’t see this tag within #ticket #tags, to ensure you don’t<br />

have a false positive. Next, you fill in the text for the comment so it’s valid, add the<br />

word “bug” to the Tags field, and click the Create Comment button. Finally, you<br />

ensure that the comment has been created and that the bug tag you entered into the<br />

comment form now appears in #ticket #tags.<br />

When you run this scenario using bin/cucumber features/creating_comments<br />

.feature:47, it will fail because there is no Tags field on the ticket’s page yet:

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

Saved successfully!

Ooh no, something went wrong!