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.

128 CHAPTER 6 Authentication and basic authorization<br />

Run your tests again before you commit these changes with rake cucumber:ok spec.<br />

Even though you didn’t change much code in this section, it’s still a good habit to run<br />

your tests before every commit to stop unintentional regressions. You should see the<br />

following summaries:<br />

16 scenarios (16 passed)<br />

127 steps (127 passed)<br />

# and<br />

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

Great, let’s commit and push:<br />

git add .<br />

git commit -m "Added feature for signing in via the Devise-provided form"<br />

git push<br />

6.5 Linking tickets to users<br />

Now that users can sign in and sign up to your application, it’s time to link a ticket<br />

with a user when it’s created automatically, clearly defining which user created the<br />

ticket. You also want to ensure that the user who created the ticket gets attribution on<br />

the ticket page.<br />

That part is easy: you need a “Created by [user]” message displayed on the ticket<br />

page. The setup before it is a little more difficult, but you’ll get through it.<br />

You can test for this functionality by amending the Creating a Ticket scenario<br />

inside features/creating_tickets.feature to have the following line as the final line for<br />

the scenario:<br />

Then I should see "Created by user@ticketee.com"<br />

When you run the feature using bin/cucumber features/creating_tickets.feature,<br />

it fails on this new step because it isn’t on the ticket show template:<br />

expected #has_content?("Created by user@ticketee.com")<br />

to return true, got false ...<br />

You need to make sure the user is signed in before they can create a ticket; otherwise,<br />

you won’t know who to make the owner of that ticket. When users go to a project page<br />

and click the New Ticket link, they should be redirected to the sign-in page and asked<br />

to sign in. Once they’re signed in, they should be able to create the ticket. Change the<br />

Background of the Feature in features/creating_tickets.feature to ensure this process<br />

happens, using the code from the following listing.<br />

Listing 6.8 features/creating_tickets.feature<br />

Given there is a project called "Internet Explorer"<br />

And there are the following users:<br />

| email | password |<br />

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

And I am on the homepage<br />

When I follow "Internet Explorer"<br />

And I follow "New Ticket"

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

Saved successfully!

Ooh no, something went wrong!