Someone use kaminari for pagination? I''m doing some tests but I don''t know why I have an undefined method page. Here is my simple test: describe "GET index" do it "assigns all fire_preventions as @fire_preventions" do FirePrevention.stub(:search) { [mock_fire_prevention] } get :index assigns(:fire_preventions).should eq([mock_fire_prevention]) end end The index action is: def index @search = FirePrevention.search(params[:search]) @fire_preventions @search.page(params[:page]).per(Settings.fire_preventions_per_page) end I''m using meta_search. The test error is: Failure/Error: get :index NoMethodError: undefined method `page'' for [#<FirePrevention:0x976 @name="FirePrevention_1002">]:Array -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sent from my iPhone On May 26, 2011, at 11:07 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Someone use kaminari for pagination? > I''m doing some tests but I don''t know why I have an undefined method page. > Here is my simple test: > > describe "GET index" do > it "assigns all fire_preventions as @fire_preventions" do > FirePrevention.stub(:search) { [mock_fire_prevention] } > get :index > assigns(:fire_preventions).should eq([mock_fire_prevention]) > end > end > > The index action is: > > def index > @search = FirePrevention.search(params[:search]) > @fire_preventions > @search.page(params[:page]).per(Settings.fire_preventions_per_page) > end > > I''m using meta_search. > > The test error is: > > Failure/Error: get :index > NoMethodError: > undefined method `page'' for [#<FirePrevention:0x976 > @name="FirePrevention_1002">]:Array >It looks like you are getting back an Array as your search result the contains lots of FirePrevention objects. While a FirePrevention object may have a page method there is no page method for an Array. You need to loop over the returned Array to access each object in it to get to that object''s page method. B.> -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2011 17:55, Bryan Crossland <bacrossland-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sent from my iPhone > > On May 26, 2011, at 11:07 AM, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Someone use kaminari for pagination? >> I''m doing some tests but I don''t know why I have an undefined method page. >> Here is my simple test: >> >> describe "GET index" do >> it "assigns all fire_preventions as @fire_preventions" do >> FirePrevention.stub(:search) { [mock_fire_prevention] } >> get :index >> assigns(:fire_preventions).should eq([mock_fire_prevention]) >> end >> end >> >> The index action is: >> >> def index >> @search = FirePrevention.search(params[:search]) >> @fire_preventions >> @search.page(params[:page]).per(Settings.fire_preventions_per_page) >> end >> >> I''m using meta_search. >> >> The test error is: >> >> Failure/Error: get :index >> NoMethodError: >> undefined method `page'' for [#<FirePrevention:0x976 >> @name="FirePrevention_1002">]:Array >> > > It looks like you are getting back an Array as your search result the contains lots of FirePrevention objects. While a FirePrevention object may have a page method there is no page method for an Array. You need to loop over the returned Array to access each object in it to get to that object''s page method.mmmmmmm.... I need an example for that, there aren''t examples with rspec anche kaminari in internet. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Here''s my chance to give back ;) Make a file called kaminari.rb in /specs/support Puts this in it: module Kaminari::ActionViewExtension::InstanceMethods def paginate(scope, options = {}, &block) end end Make sure this file is loaded in your spec_helper.rb: Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} You should probably have this line already, but check just to be sure. That should do it. I don''t know a lot about rails, but I actually knew this answer ;) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.