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.

Pagination<br />

the tickets page with more than 50 tickets in the system, you will see a pagination link<br />

somewhere on that page. You should be able to click Next and then see the next 50<br />

tickets.<br />

16.1.2 Paginating an interface<br />

You’re going to now implement paging for your tickets listing, showing 50 tickets at a<br />

time. Users will be able to navigate between pages by clicking the Next and Prev links.<br />

These two links will be provided by a helper from the kaminari gem.<br />

TESTING PAGINATION<br />

To test this, you’ll write a new scenario at features/paginating_tickets.feature, shown in<br />

the following listing. If you create 100 tickets in this feature, you’ll see the pagination<br />

links and can then make sure they’re working.<br />

Listing 16.1 features/paginating_tickets.feature<br />

Feature: Paginating tickets<br />

In order to ease the load on the server<br />

As the system<br />

I want paginate ticket results<br />

Background:<br />

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

Given there are the following users:<br />

| email | password |<br />

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

And "user@ticketee.com" can view the "Internet Explorer" project<br />

And I am signed in as them<br />

And there are 100 tickets for this project B Create tickets<br />

When I am on the homepage<br />

And I follow "Internet Explorer"<br />

Scenario: Viewing the second page<br />

Then I should see 2 pages of pagination<br />

When I follow "Next" within ".pagination .next"<br />

Then I see page 2 of tickets for this project<br />

In this feature you use the “Given there is a project” step you’ve used many times<br />

before to create a project, and then a new step B, which will create a given number of<br />

tickets for the project. This is required so that the pagination links will appear on your<br />

tickets. If you didn’t have enough tickets in your project to warrant pagination, then<br />

the links would not appear at all.<br />

You then go through the motions of creating a user, giving them access to that<br />

project so that they can see into it, signing in as them, and then navigating to that<br />

project. On that project’s page you should see the pagination links displaying two<br />

pages’ worth of pagination. When you click the Next link within the pagination element,<br />

you should be on the second page.<br />

You’ve got three undefined steps within this feature, and you can get the step definitions<br />

for these steps by running this feature using the bin/cucumber features/<br />

paginating_tickets.feature:<br />

437

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

Saved successfully!

Ooh no, something went wrong!