Ruby On Rails Classroom image

Neha  Jaggi / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5|Last
Lessons:-Pagination

Because the will paginate gem is in wide use, there’s no need to test it thoroughly, so we’ll take a lightweight approach. First, we’ll test for a div with CSS class ‘‘pagination’’, which is what gets output by will paginate. Then we’ll verify that the correct users appear on the first page of results. This requires the use of the paginate method, which we’ll cover shortly.

          As before, we’ll use Factory Girl to simulate users, but immediately we have a problem: User email addresses must be unique, which would appear to require creating more than 30 users by hand—a terribly cumbersome job. In addition, when testing for user listings it would be convenient for them all to have different names. Fortunately, Factory Girl anticipates this issue, and provides sequences to solve it. Our original factory (Listing 7.8) hard-coded the name and email address: 

 

 

Instead, we can arrangefor a sequence of names and email addresses using the sequence method:

 

 

Here sequence takes a symbol corresponding to the desired attribute (such as :name) and a block with one variable, which we have called n. Upon successive invocations of the FactoryGirl method,

FactoryGirl . create ( :user )

 

The block variable n is automatically incremented, so that the first user has name ‘‘Person 1’’ and email address ‘‘person 1@example.com’’, the second user has name ‘‘Person 2’’ and email address ‘‘person 2@example.com’’, and so on. The full code appears in Listing 9.32.

 

 

 

 

 

 
 
 
image
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


Explore
 

  Students (0)