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 />

Now that you can add and remove tags, what is there left to do? Find them! By implementing<br />

a way to find tickets with a given tag, you make it easier for users to see only<br />

the tickets they want to see. As an added bonus, you’ll also implement a way for the<br />

users to find tickets for a given state, perhaps even at the same time as finding a tag.<br />

When you’re done with this next feature, you’ll add some more functionality that<br />

will let users go to tickets for a tag by clicking the tag name inside the ticket show<br />

page.<br />

11.5 Finding tags<br />

At the beginning of this chapter, we planned on covering searching for tickets using a<br />

query such as tag:iteration_1 state: open. This magical method would return all<br />

the tickets in association with the iteration_1 tag that were marked as open. This<br />

helps users scope down the list of tickets that appear on a project page to be able to<br />

better focus on them.<br />

There’s a gem developed specifically for this purpose called Searcher 4 that you can<br />

use. This provides you with a search method on specific classes, which accepts a query<br />

like the one mentioned and returns the records that match it.<br />

11.5.1 Testing search<br />

As usual, you should (and will) test that searching for tickets with a given tag works,<br />

which you can do by writing a new feature called features/searching.feature and filling<br />

it with the content from the following listing.<br />

Listing 11.4 features/searching.feature<br />

Feature: Searching<br />

In order to find specific tickets<br />

As a user<br />

I want to enter a search query and get results<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 />

| Tag! | Hey! You're it! | iteration_1 |<br />

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

| title | description | tags |<br />

| Tagged! | Hey! I'm it now! | iteration_2 |<br />

Given I am on the homepage<br />

4 This gem is good for a lo-fi solution but shouldn’t be used in a high search-volume environment. For that,<br />

look into full text search support for your favorite database system.<br />

303

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

Saved successfully!

Ooh no, something went wrong!