Read more

How to change will_paginate's "per_page" in Cucumber features

Arne Hartherz
July 30, 2012Software engineer at makandra GmbH

The will_paginate gem Show archive.org snapshot will show a default of 30 records per page.
If you want to test pagination in a Cucumber feature, you don't want to create 31 records just for that.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Instead, you probably want to modify the number of items shown, by saying something like this:

Given we paginate after 2 users

Using the following step definition, you now can! :)

require 'cucumber/rspec/doubles'

Given /^paginate after (\d+) (.*)$/ do |per_page, model_name|
  model = model_name.singularize.gsub(/[^A-Z]+/, '_').camelize.constantize
  allow(model).to receive(:per_page).and_return(per_page)
end

It will change the pagination settings per model, so you can apply different pagination rules:

Given we paginate after 2 users
  And we paginate after 5 blog posts
Posted by Arne Hartherz to makandra dev (2012-07-30 15:45)