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.

Locking down states<br />

With this added to the permissions hash, your scenario will move a little further<br />

toward success. When you rerun it, it will complain that it can’t find the Open state<br />

from your select box:<br />

And I select "Open" from "State"<br />

No such option 'Open' in this select box.<br />

Ah, not a problem! This means that the Open state isn’t yet defined in your test database.<br />

You need to create this state in the Background for this feature. You can do this<br />

by adding the following line at the bottom of the Background:<br />

Given there is a state called "Open"<br />

When you rerun this scenario using bin/cucumber features/assigning_permissions<br />

.feature:74, 4 it will now pass:<br />

1 scenario (1 passed)<br />

22 steps (22 passed)<br />

That’s good! Now admins are able to assign the “Change states” permission and users<br />

are able to see and touch the State select box on the comment form if they have this<br />

permission.<br />

This is a great halfway point before you go diving into the final stage of this particular<br />

set of features to run your Cucumber features and specs to ensure that nothing is<br />

broken. Let’s run rake cucumber:ok spec now; you should see that all your tests are<br />

passing:<br />

53 scenarios (53 passed)<br />

568 steps (568 passed)<br />

# and<br />

34 examples, 0 failures, 17 pending<br />

Yay! Everything is in working order, which means you can commit and push these<br />

changes to GitHub:<br />

git add .<br />

git commit -m "Only users with the 'change states' permission<br />

➥can change states"<br />

git push<br />

The final piece of your states puzzle is to stop the state parameter from being set in<br />

your CommentsController if a user passes it through and doesn’t have permission to<br />

set states. First, you’ll investigate how a user can fake this response. Afterward, you’ll<br />

write a controller spec that duplicates this and ensures that the state isn’t set.<br />

4 If you get no scenario and no steps running for this feature, are you sure you’re running the right line? Check<br />

to make sure you’re running line 75, not 74, which is now a blank line.<br />

281

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

Saved successfully!

Ooh no, something went wrong!