27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

178 CHAPTER 8 More authorization<br />

Removing these scenarios removes two of the failing scenarios, but two more are still<br />

failing:<br />

Failing Scenarios:<br />

cucumber features/hidden_links.feature:21<br />

cucumber features/hidden_links.feature:31<br />

These two scenarios fail because user@ticketee.com doesn’t have access to the Text-<br />

Mate 2 project. To give it access, you can put the permission step underneath the<br />

project-creation step in the Background, like this:<br />

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

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

When you run this feature again using bin/cucumber features/hidden_links<br />

.feature, it passes:<br />

7 scenarios (7 passed)<br />

39 steps (39 passed)<br />

You fixed the scenarios in the Hidden Links feature, but the Signing Up feature still<br />

fails. These two features aren’t closely related, so it’s best to make a commit but not<br />

push it to GitHub now so you have all related changes in one commit and other<br />

changes in separate commits. For this commit, the ProjectsController’s index<br />

action is restricted to displaying projects only the user can see, so the commit commands<br />

are as follows:<br />

git add .<br />

git commit -m "Don’t show projects that a<br />

user doesn't have permission to see"<br />

Now let’s see why the Signing Up feature is acting up. When you run it using bin<br />

/cucumber features/signing_up.feature, the final step fails:<br />

Then I should see "You have signed up successfully"<br />

expected #has_content?("You have signed up successfully.")<br />

to return true, got false<br />

When users sign up to your application, they’re shown the “You have signed up successfully”<br />

message, as the feature says they should, and they’re also redirected to the<br />

root of your application. The problem lies with this final step: people are redirected to<br />

the root of the application, the ProjectsController’s index action, which is now<br />

locked down to require that users be authenticated before they can view this action.<br />

This is problematic, but it’s fixable.<br />

8.3.4 Fixing Signing Up<br />

The Signing Up feature is broken, and the problem lies solely with the latest changes<br />

you made to the ProjectsController. When users sign up, they’re sent to the<br />

root_path in the application, which resolves to the index action in the Projects-<br />

Controller. This controller has the authenticate_user! method called before all

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

Saved successfully!

Ooh no, something went wrong!