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.

Restricting actions to admins only<br />

key-value pair of the hash, the action 1 and method change. You pass in the :id parameter<br />

because, without it, the controller can’t route to the edit, update, or destroy<br />

action. The new and create actions ignore this parameter.<br />

The remainder of this spec is unchanged, and when you run bin/rspec spec/controllers/projects_controller_spec.rb,<br />

you should see all six examples passing:<br />

6 examples, 0 failures<br />

Now’s a good time to ensure you haven’t broken anything, so let’s run rake cucumber<br />

:ok spec:<br />

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

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

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

Oops. Three scenarios are broken. They failed because, for these features, you’re not<br />

signing in as an admin user—or, in fact, as any user!—which is now required for performing<br />

the actions in the scenario. You can fix these scenarios by signing in as an<br />

admin user.<br />

7.3.1 Fixing three more broken scenarios<br />

For the features/deleting_projects.feature, add a new Background, as shown in the following<br />

listing.<br />

Listing 7.10 features/deleting_projects.feature<br />

Background:<br />

Given there are the following users:<br />

| email | password | admin |<br />

| admin@ticketee.com | password | true |<br />

And I am signed in as them<br />

When you run this feature, it once again passes:<br />

1 scenario (1 passed)<br />

8 steps (8 passed)<br />

For the editing_projects.feature, use the steps from listing 7.10 again, putting them at<br />

the top of the already existing Background:<br />

Given there are the following users:<br />

| email | password | admin |<br />

| admin@ticketee.com | password | true |<br />

And I am signed in as them<br />

Now this feature also passes. Check it using bin/cucumber features/editing<br />

_projects.feature:<br />

2 scenarios (2 passed)<br />

21 steps (21 passed)<br />

1 The action variable is a frozen string in Ruby 1.9.2 (because it’s a block parameter), so you need to duplicate<br />

the object because Rails forces the encoding on it to be UTF-8.<br />

143

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

Saved successfully!

Ooh no, something went wrong!