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.

174 CHAPTER 8 More authorization<br />

This is the same problem as before: the user doesn’t have permission to access that<br />

project. To fix this problem, alter the Background, put the permission step underneath<br />

the user-creation step, and sign in as that user, like this:<br />

Given there are the following users:<br />

| email | password |<br />

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

And "user@ticketee.com" can view the "Internet Explorer" project<br />

And I am signed in as them<br />

This Background also contains code that ensures users are asked to sign in if they click<br />

the New Ticket link when they’re not signed in. Because you’ll log in as a user before<br />

you get to this point, you can remove the last few lines from this Background:<br />

Then I should see "You need to sign in or sign up before continuing."<br />

When I fill in "Email" with "user@ticketee.com"<br />

And I fill in "Password" with "password"<br />

And I press "Sign in"<br />

Then I should see "New Ticket"<br />

When you run this feature again, all the scenarios pass:<br />

3 scenarios (3 passed)<br />

35 steps (35 passed)<br />

One down, three to go. The next failing feature is the Deleting Tickets feature.<br />

It fails for the same reason as the previous one: the user doesn’t have access to the<br />

project to delete a ticket. Let’s fix this now by putting the following line underneath<br />

where your project is created:<br />

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

And "user@ticketee.com" can view the "TextMate 2" project<br />

That’s a little too easy! When you run bin/cucumber features/deleting_tickets<br />

.feature, this feature now passes:<br />

1 scenario (1 passed)<br />

11 steps (11 passed)<br />

Next up is the Editing Tickets feature, which contains not one but two broken scenarios.<br />

The two scenarios in this feature, similar to the Editing Projects scenario, are broken<br />

because the feature can’t find a link:<br />

And I follow "Make it shiny!"<br />

no link with title, id or text 'Make it shiny!' found<br />

➥(Capybara::ElementNotFound)<br />

Again, the error occurs because the user doesn’t have permission to access this particular<br />

project. You must specify that this user has access to this project in the<br />

Background, just as you did for the Creating Tickets and Editing Tickets features. Add<br />

this line directly under the line that creates the project in the Background:<br />

And "user@ticketee.com" can view the "TextMate 2" project

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

Saved successfully!

Ooh no, something went wrong!