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.

208 CHAPTER 8 More authorization<br />

Listing 8.20 features/assigning_permissions.feature<br />

Scenario: Updating a ticket for a project<br />

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

And I check "Edit tickets" 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 />

When I follow "TextMate 2"<br />

And I follow "Shiny!"<br />

And I follow "Edit"<br />

And I fill in "Title" with "Really shiny!"<br />

And I press "Update Ticket"<br />

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

Scenario: Deleting a ticket for a project<br />

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

And I check "Delete tickets" 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 />

When I follow "TextMate 2"<br />

And I follow "Shiny!"<br />

And I follow "Delete"<br />

Then I should see "Ticket has been deleted."<br />

The scenarios should be descriptive enough to understand—no particular magic<br />

going on here. But you’re acting on a ticket in both these scenarios that doesn’t exist:<br />

the Shiny! ticket. You need to create this ticket in your Background if you want these<br />

scenarios to pass. Add this step definition right under the line in the Background that<br />

creates the TextMate 2 project, as shown next:<br />

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

| title | description |<br />

| Shiny! | Eye-blindingly so |<br />

Now when you run this feature, your two newest scenarios are failing, both with similar<br />

errors:<br />

cannot check field, no checkbox with id, name,<br />

or label 'permissions_1_update_tickets' found<br />

# and<br />

cannot check field, no checkbox with id, name,<br />

or label 'permissions_1_delete_tickets' found<br />

Of course! You have no check boxes for Capybara to check yet! Add them now by changing<br />

the permissions method in app/helper/admin/permissions_helper.rb from this<br />

def permissions<br />

{<br />

"view" => "View",<br />

"create tickets" => "Create Tickets"<br />

}<br />

end

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

Saved successfully!

Ooh no, something went wrong!