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.

132 CHAPTER 6 Authentication and basic authorization<br />

Listing 6.10 features/viewing_tickets.feature<br />

Given there is a project called "TextMate 2"<br />

And that project has a ticket:<br />

| title | description |<br />

| Make it shiny! | Gradients! Starbursts! Oh my! |<br />

No user is assigned to this ticket for the second step, and that’s why user is nil. You<br />

should rewrite this feature to make it create a ticket and link it to a specific user.<br />

6.5.3 Fixing the Viewing Tickets feature<br />

The first step is to create a user you can link to, so change the first lines of the<br />

Background to this:<br />

Given there are the following users:<br />

| email | password |<br />

| user@ticketee.com | password |<br />

And there is a project called "TextMate 2"<br />

And that project has a ticket:<br />

| title | description |<br />

| Make it shiny! | Gradients! Starbursts! Oh my! |<br />

Next, change the third step a little so it creates a ticket with a user:<br />

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

| title | description |<br />

| Make it shiny! | Gradients! Starbursts! Oh my! |<br />

Also be sure to change the other ticket-creation lines further down:<br />

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

| title | description |<br />

| Standards compliance | Isn’t a joke. |<br />

When you run bin/cucumber features/viewing_tickets.feature, you get the new<br />

version of this step definition:<br />

Given /^"([^\"]*)" has created a ticket for this project:$/ do |arg1, table|<br />

# table is a Cucumber::Ast::Table<br />

pending # express the regexp above with the code you wish you had<br />

end<br />

Copy the first line of this step definition, open features/step_definitions/<br />

ticket_steps.rb, and replace the first line in the file with this new line. Then replace<br />

arg1 with email, making the entire step definition<br />

Given /^"([^\"]*)" has created a ticket for this project:$/ do |email, table|<br />

table.hashes.each do |attributes|<br />

@project.tickets.create!(attributes)<br />

end<br />

end<br />

Next, link this new ticket to the user who has the email you pass in. Change the step<br />

definition as follows:<br />

Given /^"([^\"]*)" has created a ticket for this project:$/ do |email, table|<br />

table.hashes.each do |attributes|

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

Saved successfully!

Ooh no, something went wrong!