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.

172 CHAPTER 8 More authorization<br />

.......<br />

7 examples, 0 failures<br />

All right! The examples for this controller are passing, but how about the feature—<br />

the one you wrote previously to test that users can access this show action if they have<br />

the correct permissions? This spec tested the negative, making sure a user without<br />

permission can’t access this project.<br />

With the code you just implemented, this feature should still pass as it did the last<br />

time you ran it. Let’s find out by running bin/cucumber features/viewing<br />

_projects.feature:<br />

1 scenario (1 passed)<br />

7 steps (7 passed)<br />

Isn’t that wonderful? You rewrote the feature and it still passed! You’ve tested both the<br />

granted and denied facets of this particular permission by writing a feature and spec<br />

respectively.<br />

Now that you implemented that little chunk of functionality and everything seems<br />

to be going smoothly, let’s make sure the entire application is going the same way by<br />

running rake cucumber:ok spec. Oh dear! You broke just about every feature in some<br />

way:<br />

Failing Scenarios:<br />

cucumber features/creating_projects.feature:14<br />

cucumber features/creating_tickets.feature:20<br />

cucumber features/deleting_projects.feature:12<br />

cucumber features/deleting_tickets.feature:19<br />

cucumber features/editing_projects.feature:16<br />

cucumber features/editing_tickets.feature:20<br />

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

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

features/viewing_tickets.feature:20<br />

33 scenarios (9 failed, 4 skipped, 20 passed)<br />

289 steps (9 failed, 87 skipped, 193 passed)<br />

These features are all broken because you restricted the permissions on the find_project<br />

method, and all of these features depend on this functionality in one way or another.<br />

Let’s fix these, from the top, one at a time.<br />

8.3 Fixing what you broke<br />

Currently, you have a whole bundle of features that are failing! When this happens, it<br />

may seem like everything’s broken (and maybe some things are on fire), but in reality<br />

it’s not as bad as it seems. The best way to fix a mess like this is to break it down into<br />

smaller chunks and tackle it one chunk at a time. The output from rake cucumber:ok<br />

spec provided a list of the broken features: they are your chunks. Let’s go through<br />

them and fix them, starting with the Editing Projects feature.

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

Saved successfully!

Ooh no, something went wrong!