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.

330 CHAPTER 12 Sending email<br />

As usual, you see what you need to code right now to get your feature on the road to<br />

passing by running bin/cucumber features/waching.feature. You see that it’s actually<br />

this watchers list, indicated by Capybara telling you that it can’t find that element:<br />

Then I should see "user@ticketee.com" within "#watchers"<br />

Unable to find css "#watchers" (Capybara::ElementNotFound)<br />

To get this feature to continue, you’re going to need this element! You can add it to<br />

app/views/tickets/show.html.erb underneath the tag for <br />

by using the code from the following listing.<br />

Listing 12.8 app/views/tickets/show.html.erb<br />

<br />

Watchers<br />

<br />

<br />

<br />

<br />

<br />

<br />

You’ve created another div with the id attribute set to watchers, which is the element<br />

that your scenario looks for. In this div you iterate through all the watchers of the<br />

ticket and output a li tag for each of them, which will output a list of watchers when<br />

wrapped in a ul tag.<br />

When you have this element and you run your feature again with bin/cucumber<br />

features/watching_tickets.feature, you see that your feature gets one step closer<br />

to passing by locating user@ticketee.com in the #watchers element, but it now can’t<br />

find the Stop Watching This Ticket button:<br />

Then I should see "user@ticketee.com" within "#watchers"<br />

And I press "Stop watching this ticket"<br />

no button with value or id or text 'Stop watching this ticket'<br />

This button will toggle the watching status of the ticket of the current user, and the<br />

text will differ depending on if the user is or isn’t watching this ticket. In both cases,<br />

however, the button will go to the same action. To get this next scenario to pass, you<br />

add the button to the div#watchers element you just created by using a helper,<br />

changing the first few lines of the element to this:<br />

<br />

<br />

Watchers<br />

This toggle_watching_button helper will only appear in views for the Tickets-<br />

Controller, and so you should put the method definition in app/helpers/<br />

tickets_helper.rb inside the TicketsHelper module, using the code from the following<br />

listing to define the method.

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

Saved successfully!

Ooh no, something went wrong!