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.

Assigning permissions<br />

Listing 8.14 features/assigning_permissions.feature<br />

Feature: Assigning permissions<br />

In order to set up users with the correct permissions<br />

As an admin<br />

I want to check all the boxes<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 />

And there are the following users:<br />

| email | password |<br />

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

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

When I follow "Admin"<br />

And I follow "Users"<br />

And I follow "user@ticketee.com"<br />

And I follow "Permissions"<br />

Scenario: Viewing a project<br />

When I check "View" for "TextMate 2"<br />

And I press "Update"<br />

And I follow "Sign out"<br />

Given I am signed in as "user@ticketee.com"<br />

Then I should see "TextMate 2"<br />

This scenario has two users: an admin user and a standard user. You sign in as the<br />

admin user, go to the permissions page, check a box, click Update, and then sign out.<br />

Then you sign in as the user who was just granted permission to test that permission,<br />

which you do in the next step. This ensures that the assigning of the permissions always<br />

works. For now, you’re only testing the permission to view a project permission.<br />

When you run bin/cucumber features/assigning_permissions.feature, it fails<br />

when it tries to follow the Permissions link:<br />

And I follow "Permissions"<br />

no link with title, id or text 'Permissions' found<br />

➥(Capybara::ElementNotFound)<br />

If you look at how the Background gets to this point, you can see that it follows the<br />

Admin link, which leads to the admin dashboard, then to Users to take you to the place<br />

where you can see users, and finally clicks a user, taking you to the Admin::Users-<br />

Controllershow action. Therefore, you need to add the missing Permissions link to<br />

the app/views/admin/users/show.html.erb directly underneath the Delete User link:<br />

:delete,<br />

:confirm => "Are you sure you want<br />

➥to delete this user?" %><br />

<br />

199

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

Saved successfully!

Ooh no, something went wrong!