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.

Finding tags<br />

You only had to add states to the tickets that were being created and tell Searcher to<br />

search by states, and now this feature passes.<br />

That’s it for the searching feature! In it, you’ve added the ability for users to find<br />

tickets by a given tag and/or state. It should be mentioned that these queries can be<br />

chained, so a user may enter a query such as tag:iteration_1 state:Open and it will<br />

find all tickets with the iteration_1 tag and the Open state.<br />

As per usual, commit your changes because you’re done with this feature. But also<br />

per usual, check to make sure that everything is A-OK by running rake cucumber :ok<br />

spec:<br />

58 scenarios (58 passed)<br />

645 steps (645 passed)<br />

# and<br />

39 examples, 0 failures, 19 pending<br />

Brilliant, let’s commit:<br />

git add .<br />

git commit -m "Users may now search for tickets by state or tag"<br />

git push<br />

With searching in place and the ability to add and remove tags, you’re almost done<br />

with this set of features. The final feature involves changing the tag name rendered in<br />

app/views/tags/_tag.html.erb so that when a user clicks it they are shown all tickets for<br />

that tag.<br />

11.5.4 Search, but without the search<br />

You are now going to change your tag partial to link to the search page for that tag.<br />

To test this functionality, you can add another scenario to the bottom of features/<br />

searching.feature to test that when a user clicks a ticket’s tag, they are only shown tickets<br />

for that tag. The new scenario looks pretty much identical to this:<br />

Scenario: Clicking a tag goes to search results<br />

When I follow "Tag!"<br />

And I follow "iteration_1"<br />

Then I should see "Tag!"<br />

And I should not see "Tagged!"<br />

When you run this last scenario using bin/cucumber features/searching.feature<br />

:33, you’re told that it cannot find the iteration_1 link on the page:<br />

no link with title, id or text 'iteration_1' found<br />

This scenario is successfully navigating to a ticket and then attempting to click a link<br />

with the name of the tag, only to not find the tag’s name. Therefore, it’s up to you to<br />

add this functionality to your app. Where you display the names of tags in your application,<br />

you need to change them into links that go to pages displaying all tickets for<br />

that particular tag. Let’s open app/views/tags/_tag.html.erb and change this simple little<br />

line<br />

<br />

309

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

Saved successfully!

Ooh no, something went wrong!