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.

298 CHAPTER 11 Tagging<br />

ment from the page and make an asynchronous behind-the-scenes request to the<br />

action.<br />

11.4.1 Testing tag deletion<br />

To click this link using Cucumber, you give the link around the X an id so you can easily<br />

locate it in your feature, which you’ll now write. Let’s create a new file at features/<br />

deleting_tags.feature and put in it the code from the following listing.<br />

Listing 11.3 features/deleting_tags.feature<br />

Feature: Deleting tags<br />

In order to remove old tags<br />

As a user<br />

I want to click a button and make them go away<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" can tag the "Ticketee" project<br />

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

| title | description | tags |<br />

| A tag | Tagging a ticket! | this-tag-must-die |<br />

Given I am on the homepage<br />

When I follow "Ticketee" within "#projects"<br />

And I follow "A tag"<br />

@javascript<br />

Scenario: Deleting a tag<br />

When I follow "delete-this-tag-must-die"<br />

Then I should not see "this-tag-must-die"<br />

In this scenario, it’s important to note that you’re passing through the tags field as a<br />

field in the “created a ticket” step, just like the other fields. The tags field isn’t in the<br />

tickets table. You’ll get to that in a second.<br />

In this feature, you create a new user and sign in as them. Then you create a new<br />

project called Ticketee and give the user the ability to view and tag the project. You<br />

create a ticket by the user and tag it with a tag called this_tag_must_die. Finally, you<br />

navigate to the page of the ticket you’ve created.<br />

In the scenario, you follow the delete-this-tag-must-die link, which will be the<br />

id on the link to delete this tag. When this link has been followed, you shouldn’t see<br />

this_tag_must_die, meaning that the action to remove the tag from the ticket has<br />

worked its magic.<br />

When you run this feature using bin/features/deleting_tags.feature, you get<br />

this error:<br />

undefined method `each' for "this_tag_must_die":String (NoMethodError)<br />

./features/step_definitions/ticket_steps.rb:10 ...

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

Saved successfully!

Ooh no, something went wrong!