Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination. #79

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

JakeWengroff
Copy link

Hi @chalmagean,

I added pagination via the will_paginate rubygem. Not sure if this is the route you wanted to go, but I guess it does the job.

Jake

@chalmagean
Copy link
Contributor

That's awesome, but let's use the kaminari gem instead of will paginate because it's actively maintained.

Also please add a some tests (in spec/features) around that enhancement.

@JakeWengroff
Copy link
Author

Hi, Cezar,

I changed the pagination gem to Kaminari, and wrote a Controller test in RSpec, but it's still not passing.
I think it has to do with the Controller, not the test.
Let's discuss.

Jake

@@ -10,6 +10,9 @@ gemspec
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

gem 'kaminari'
gem 'kaminari-rspec'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one should probably go in the test group

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I added kaminari-rspec to the test group.

I added a paginate_posts_index_spec.rb feature test to the spec/features folder, which seems to be passing, but Kaminari's paginate method seems to be throwing errors across other tests.
I made changes to the Views, and ALL of the Features tests are passing (!!!)
@@ -4,7 +4,7 @@ class BlogPostsController < ApplicationController
before_filter :find_blog_post!, :only => :show

def index
@blog_posts = BlogPost.all
@blog_posts = BlogPost.all.page(params[:page]).per(5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to call .all here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have more than 5 posts on a page (.per(5)). Also you should put the number in a constant.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. No need to call .all, and I set the number of posts per page to 10, in the config/initializers/kaminari_config.rb file

I made suggested changes, but still need to revise the paginate posts spec file. The tests are all passing, however.
@@ -45,6 +45,8 @@
</tr>
<% end %>
</table>
<% @blog_posts = BlogPost.page(params[:page]) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blog_posts is already set in the controller. You don't need to set it again in the view.

@@ -6,6 +6,7 @@
namespace :admin do
resources :blog_posts do
get "/get_tags" => "blog_posts#get_tags", as: :get_tags, on: :collection
get '/blog/:page', :action => :index, :on => :collection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to use the new hash syntax key: :value instead of :key => :value

@JakeWengroff
Copy link
Author

Hi, Cezar,
I fixed the outstanding issues, but now rspec features is broken.
Jake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants