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

Updated . Posted . Visible to the public.

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.

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
Arne Hartherz
Last edit
Julian
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2012-07-30 13:45)