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.

6.2 User signup<br />

User signup<br />

With Devise set up, you’re ready to write a feature that allows users to sign up. The<br />

Devise gem provides this functionality, so this feature will act as a safeguard to ensure<br />

that if the functionality were ever changed, the feature would break.<br />

To make sure this functionality is always available, you write a feature for it, using<br />

the following listing, and put it in a new file at features/signing_up.feature.<br />

Listing 6.2 features/signing_up.feature<br />

Feature: Signing up<br />

In order to be attributed for my work<br />

As a user<br />

I want to be able to sign up<br />

Scenario: Signing up<br />

Given I am on the homepage<br />

When I follow "Sign up"<br />

And I fill in "Email" with "user@ticketee.com"<br />

And I fill in "Password" with "password"<br />

And I fill in "Password confirmation" with "password"<br />

And I press "Sign up"<br />

Then I should see "You have signed up successfully."<br />

When you run this feature using bin/cucumber features/signing_up.feature,<br />

you’re told it can’t find a Sign Up link, probably because you haven’t added it yet:<br />

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

You should now add this link in a nav: 1<br />

<br />

<br />

<br />

You previously used the menu on the app/views/tickets/show.html.erb page to style the<br />

links there. Here you use a nav tag because this is a major navigation menu for the<br />

entire application, not just a single page’s navigation.<br />

With this link now in place, the entire feature passes when you run it because<br />

Devise does all the heavy lifting for you:<br />

1 scenario (1 passed)<br />

7 steps (7 passed)<br />

Because Devise has already implemented this functionality, you don’t need to write<br />

any code for it. This functionality could be overridden in your application, and this<br />

feature is insurance against anything changing for the worse.<br />

With the signup feature implemented, this is a great point to see if everything else<br />

is working by running rake cucumber:ok spec. You should see this output:<br />

1 nav is an HTML5 tag and may not be supported by some browsers. As an alternative, you could put instead, in app/views/layouts/application.html.erb, directly underneath the h1 tag for your<br />

application’s title.<br />

121

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

Saved successfully!

Ooh no, something went wrong!