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

Great! With the insurance that you’re not going to break anything now, you can render<br />

the app/views/projects/show.html.erb template in the search action of Tickets-<br />

Controller by putting this line at the bottom of the action:<br />

render "projects/show"<br />

By rendering this template, you show a similar page to ProjectsController#show,<br />

but this time it will only have the tickets for the given tag. When you run your<br />

“Searching” feature using bin/cucumber features/searching.feature, you see that<br />

it all passes now:<br />

1 scenario (1 passed)<br />

13 steps (13 passed)<br />

With this feature, users will be able to specify a search query such as tag:iteration_1<br />

to return all tickets that have that given tag. You prevented one breaking change by<br />

catching it as it was happening, but how about the rest of the test suite? Let’s find out<br />

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

56 scenarios (57 passed)<br />

632 steps (632 passed)<br />

# and<br />

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

Great! Let’s commit this change:<br />

git add .<br />

git commit -m "Added label-based searching for tags using Searcher"<br />

git push<br />

Now that you have tag-based searching, why don’t you spend a little bit of extra time<br />

letting your users search by state as well? This way, they’ll be able to perform actions<br />

such as finding all remaining open tickets in the tag iteration_1 by using the search<br />

term state:open tag:iteration_1. It’s easy to implement.<br />

11.5.3 Searching by state<br />

Implementing searching for a state is incredibly easy now that you have the Searcher<br />

plugin set up and have the search feature in place. As you did with searching for a tag,<br />

you’ll test this behavior in the “Searching” feature. But first, you need to set up your<br />

tickets to have states. Let’s change the steps in the Background in this feature that set<br />

up your two tickets to now specify states for the tickets:<br />

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

| title | description | tags | state |<br />

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

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

| title | description | tags | state |<br />

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

When you run your feature with bin/cucumber features/searching.feature, you<br />

see that you’re getting an AssociationTypeMismatch:<br />

State(#2178318800) expected, got String(#2151988680)<br />

307

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

Saved successfully!

Ooh no, something went wrong!