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.

Put this line:<br />

Deleting a tag<br />

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

With your all-powerful step defined in features/step_definitions/permission_steps.rb,<br />

you don’t have to define a definition for this step to work. When you re-run this scenario<br />

using bin/cucumber features/creating_comments.feature:48, it will pass:<br />

1 scenario (1 passed)<br />

16 steps (16 passed)<br />

One scenario down, one to go! The next one is the features/creating_tickets.feature:51<br />

scenario. At the top of the feature, you can put the same line you used in the “Creating<br />

comments” feature, right under the view permission. Don’t forget to rename the<br />

project:<br />

And "user@ticketee.com" can tag the "Internet Explorer" project<br />

This scenario too will pass:<br />

1 scenario (1 passed)<br />

16 steps (16 passed)<br />

Great! Only certain users can now tag tickets. Let’s make sure that everything is still<br />

running at 100% by running rake cucumber:ok spec. You should see this:<br />

55 scenarios (55 passed)<br />

608 steps (608 passed)<br />

# and<br />

38 examples, 0 failures, 18 pending<br />

In this section, you have restricted the ability to add tags to a ticket—whether through<br />

the new ticket or comment forms—to only users who have the permission to tag.<br />

You’ve done this to restrict the flow of tags. Generally speaking, the people with the<br />

ability to tag should know only to create useful tags, so that the usefulness of the tags is<br />

not diluted. In the next section, you’ll use this same permission to determine what<br />

users are able to remove a tag from a ticket.<br />

11.4 Deleting a tag<br />

Removing a tag from a ticket is a helpful feature, because a tag may become irrelevant<br />

over time. Say that you’ve tagged a ticket as v0.1 for your project, but the feature isn’t<br />

yet complete and needs to be moved to v0.2. Without this feature, there will be no way<br />

to delete the old tag. Then what? Was this ticket for v0.1 or v0.2? Who knows? With the<br />

ability to delete a tag, you have some assurance that people<br />

will clean up tags if they’re able to.<br />

To let users delete a tag, add an X to the left of each<br />

of your tags, as shown in figure 11.4.<br />

When this X is clicked, the tag will disappear through<br />

the magic of JavaScript. Rather than making a whole<br />

request out to the action for deleting a tag and then<br />

redirecting back to the ticket page, remove the tag’s ele- Figure 11.4 X marks the spot<br />

297

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

Saved successfully!

Ooh no, something went wrong!