Ruby On Rails Classroom image

Anil  Bist / 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
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)