5

I'm running some rspec unit tests involving getting data back through kaminari paging, but the default page size for our application is 20, whereas 2 would work fine for test.

How do a set a different configuration for the default kaminari page size for test, or how do I set it up during the rspec setup for the test?

Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56
  • I think my issue is with a lack of rails configuration knowledge and not Kaminari specifically, so this question should be closed. – Steve Mitcham Sep 27 '11 at 14:33
  • This question contains the answer that I actually need: http://stackoverflow.com/questions/4820987/rails-per-environment-initializers – Steve Mitcham Sep 27 '11 at 14:36

2 Answers2

6

In your model you can override the default per_page:

class Something < ActiveRecord::Base
  paginates_per Rails.env.test? ? 2 : 20
end
James
  • 4,797
  • 25
  • 29
  • is that something I can set from the outside the class during a test setup, or is it only settable internal as you show? – Steve Mitcham Sep 26 '11 at 21:41
  • 1
    I haven't tried this but it looks like you can set it in an intializer. https://github.com/amatsuda/kaminari/blob/master/lib/generators/kaminari/templates/kaminari_config.rb – James Sep 26 '11 at 21:51
  • yes, that is where I am setting it right now. I think I probably need to ask a more general question about rails configuration instead of limiting it to Kaminari. – Steve Mitcham Sep 27 '11 at 14:32
  • Based on the information in the other question and then re-reading your answer, I think I can get what I need done. – Steve Mitcham Sep 27 '11 at 14:38
-6

Don't. You are supposed to test the data as similar to the production environment as possible.

Joost Baaij
  • 7,538
  • 3
  • 32
  • 34
  • 1
    This is a specific unit test related to paging that is difficult to wade through 200 lines of JSON data when 20 lines would do. – Steve Mitcham Sep 26 '11 at 21:40