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.

304 CHAPTER 11 Tagging<br />

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

Scenario: Finding by tag<br />

When I fill in "Search" with "tag:iteration_1"<br />

And I press "Search"<br />

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

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

In the Background for this feature, you create two tickets and give them two separate<br />

tags: iteration_1 and iteration_2. When you look for tickets tagged with<br />

iteration_1, you shouldn’t see tickets that don’t have this tag, such as the one that is<br />

only tagged iteration_2.<br />

Run this feature using bin/cucumber features/searching.feature, and it’ll complain<br />

because there’s no Search field on the page:<br />

When I fill in "Search" with "tag:iteration_1"<br />

cannot fill in ... 'Search'<br />

In your feature, the last thing you do before attempting to fill in this Search field is go<br />

to the project page for Ticketee. This means that the Search field should be on that<br />

page so that your feature and, more important, your users, can fill it out. You add the<br />

field above the ul element for the tickets list, inside app/views/projects/<br />

show.html.erb:<br />

:get do %><br />

<br />

<br />

<br />

<br />

You’ve only used form_tag once, back in chapter 8. This method generates a form<br />

that’s not tied to any particular object, but still gives you the same style of form wrapper<br />

that form_for does. Inside the form_tag, you use the label_tag and text_field<br />

_tag helpers to define a label and input field for the search terms, and use<br />

submit_tag for a submit button for this form.<br />

The search_project_tickets_path method is undefined at the moment, which<br />

you see when you run bundle exec cucumber features/searching.feature:<br />

undefined local variable or method `search_project_tickets_path' ...<br />

Notice the pluralized tickets in this method. To define non-standard RESTful<br />

actions, you’ve previously used the member method inside of config/routes.rb. This has<br />

worked fine because you’ve always acted on a single resource. This time, however, you<br />

want to act on a collection of a resource. This means that you use the collection<br />

method in config/routes.rb instead. To define this method, change these lines in<br />

config/routes.rb<br />

resources :projects do<br />

resources :tickets<br />

end

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

Saved successfully!

Ooh no, something went wrong!