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.

280 CHAPTER 10 Tracking state<br />

33 of features/creating_comments.feature, which should be the scenario title of<br />

“Changing a ticket’s state”:<br />

Given "user@ticketee.com" can change states on the "Ticketee" project<br />

With the step in your scenario using this step definition now, the scenario will pass<br />

when you rerun it using bin/cucumber features/creating_comments.feature:33:<br />

1 scenario (1 passed)<br />

16 steps (16 passed)<br />

Good! All the scenarios in this feature should now be passing; you’ll check that in a<br />

minute. Your next step was going to be to ensure that the state_id parameter wasn’t<br />

passed through if the user doesn’t have access to create a state, but you’ve just added a<br />

new permission to the system. You should ensure that this permission is assignable to<br />

users before continuing, which you can do by adding a scenario to the Assigning Permissions<br />

feature.<br />

10.5.2 Bestowing changing state permissions<br />

The features/assigning_permissions.feature file contains the Assigning Permissions feature,<br />

which you’ve used to ensure that permissions are assignable from the permissions<br />

page in the backend accessible by admins. Let’s add another scenario now to test<br />

that you can assign this “change states” permission, as shown in the following listing.<br />

Listing 10.29 features/assigning_permissions.feature<br />

Scenario: Changing states for a ticket<br />

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

And I check "Change States" 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 />

When I fill in "Text" with "Opening this ticket."<br />

And I select "Open" from "State"<br />

And I press "Create Comment"<br />

Then I should see "Comment has been created."<br />

And I should see "Open" within "#ticket .state"<br />

When you run this scenario with the command bec features/assigning<br />

_permissions.feature:73, you see that it can’t find the Change States select box for<br />

the TextMate 2 project:<br />

cannot check field, no checkbox ... 'permissions_1_change_states'<br />

This is fine. You haven’t added it to the list of permissions inside of app/helpers/<br />

admin/permissions_helper.rb yet. You can add this now by adding this key-value pair to<br />

the Hash object in the permissions method’s hash:<br />

"change states" => "Change States"

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

Saved successfully!

Ooh no, something went wrong!