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.

Good stuff. Push it:<br />

Editing users<br />

git add .<br />

git commit -<br />

m "Added the ability to create admin users through the admin backend"<br />

git push<br />

Now you can create normal and admin users through the backend. In the future, you<br />

may need to modify an existing user’s details or delete a user, so we examine the updating<br />

and deleting parts of the CRUD next.<br />

7.7 Editing users<br />

This section focuses on creating the updating capabilities for the Admin::Users-<br />

Controller. Additionally, you need some functionality on the backend to enable users<br />

to confirm their account, and you can put it on the editing page.<br />

As usual, you start by writing a feature to cover this functionality, placing the file at<br />

features/editing_users.feature and filling it with the content from the following listing.<br />

Listing 7.26 features/editing_users.feature<br />

Feature: Editing a user<br />

In order to change a user's details<br />

As an admin<br />

I want to be able to modify them through the backend<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 />

Given there are the following users:<br />

| email | password |<br />

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

Given I am on the homepage<br />

When I follow "Admin"<br />

And I follow "Users"<br />

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

And I follow "Edit User"<br />

Scenario: Updating a user's details<br />

When I fill in "Email" with "newguy@ticketee.com"<br />

And I press "Update User"<br />

Then I should see "User has been updated."<br />

And I should see "newguy@ticketee.com"<br />

And I should not see "user@ticketee.com"<br />

Scenario: Toggling a user's admin ability<br />

When I check "Is an admin?"<br />

And I press "Update User"<br />

Then I should see "User has been updated."<br />

And I should see "user@ticketee.com (Admin)"<br />

Scenario: Updating with an invalid email fails<br />

157

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

Saved successfully!

Ooh no, something went wrong!