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.

Summary<br />

And "user@ticketee.com" has created a ticket for this project:<br />

| title | description |<br />

| Make it shiny! | Gradients! Starbursts! Oh my! |<br />

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

passes once again:<br />

1 scenario (1 passed)<br />

11 steps (11 passed)<br />

There! The last of the broken features is fixed.<br />

Now that the known failing scenarios are working, let’s check for any other breakages<br />

with rake cucumber:ok spec. You should see this output:<br />

16 scenarios (16 passed)<br />

148 steps (148 passed)<br />

# and<br />

6 examples, 0 failures, 4 pending<br />

Great! Let’s commit and push that to GitHub now:<br />

git add .<br />

git commit -m "When creating tickets, attribute them to the creator."<br />

git push<br />

You’ve added the feature to add attribution to the tickets so that when a ticket is created,<br />

you know who created it. You’ve also restricted certain actions in the Tickets-<br />

Controller on the basis of whether or not a user is signed in.<br />

6.6 Summary<br />

This chapter covered how to set up authentication so that users can sign up and sign<br />

in to your application to accomplish certain tasks.<br />

We began with Devise, a gem that provides the signing up and signing in capabilities<br />

right out of the box by way of being a Rails engine. Using Devise, you tested the<br />

functionality provided by the gem in the same way you tested functionality you wrote<br />

yourself: by writing Cucumber features to go with it.<br />

Then you moved into testing whether emails were sent out to the right people by<br />

using another gem called email_spec. The gem allows you to click a link in an email to<br />

confirm a user’s account and then have Devise automatically sign in the user.<br />

Then came linking tickets to users, so you can track which user created which<br />

ticket. This was done by using the setter method provided by the belongs_to<br />

method’s presence on the Ticket class. You were also able to use Hash’s lovely merge!<br />

method in the TicketsController’s create action to link any ticket that was being<br />

created to the currently signed-in user.<br />

In the next chapter, we look at restricting certain actions to only users who are<br />

signed in or who have a special attribute set on them.<br />

135

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

Saved successfully!

Ooh no, something went wrong!