mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-01 18:40:15 +01:00
Changed UsersController#index to use will_paginate plugin instead of classic_pagination
Made corresponding change in view. Added User.per_page method to provide number of users per page to User.paginate button. I can remove and just pass the param to the method in the controller if that is more desirable. Added 2 controller tests for pagination. No view tests have been added.
This commit is contained in:
parent
2f1b15fed3
commit
ed76cf55d2
4 changed files with 20 additions and 3 deletions
|
|
@ -16,7 +16,7 @@ class UsersController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
@page_title = "TRACKS::Manage Users"
|
@page_title = "TRACKS::Manage Users"
|
||||||
@user_pages, @users = paginate :users, :order => 'login ASC', :per_page => 10
|
@users = User.paginate :page => params[:page], :order => 'login ASC'
|
||||||
@total_users = User.count
|
@total_users = User.count
|
||||||
# When we call users/signup from the admin page
|
# When we call users/signup from the admin page
|
||||||
# we store the URL so that we get returned here when signup is successful
|
# we store the URL so that we get returned here when signup is successful
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,10 @@ class User < ActiveRecord::Base
|
||||||
before_create :crypt_password, :generate_token
|
before_create :crypt_password, :generate_token
|
||||||
before_update :crypt_password
|
before_update :crypt_password
|
||||||
before_save :normalize_open_id_url
|
before_save :normalize_open_id_url
|
||||||
|
|
||||||
|
#for will_paginate plugin
|
||||||
|
cattr_accessor :per_page
|
||||||
|
@@per_page = 1
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
unless Tracks::Config.auth_schemes.include?(auth_type)
|
unless Tracks::Config.auth_schemes.include?(auth_type)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<%= link_to "« Previous page", { :page => @user_pages.current.previous } if @user_pages.current.previous %>
|
<%= will_paginate @users %>
|
||||||
<%= link_to "Next page »", { :page => @user_pages.current.next } if @user_pages.current.next %>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><%= link_to 'Signup new user', signup_path %></p>
|
<p><%= link_to 'Signup new user', signup_path %></p>
|
||||||
|
|
@ -34,6 +34,20 @@ class UsersControllerTest < Test::Rails::TestCase
|
||||||
assert_equal 3, assigns['total_users']
|
assert_equal 3, assigns['total_users']
|
||||||
assert_equal "/users", session['return-to']
|
assert_equal "/users", session['return-to']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_index_pagination_page_1
|
||||||
|
User.per_page = 1
|
||||||
|
login_as :admin_user
|
||||||
|
get :index
|
||||||
|
assert_equal assigns['users'],[User.find_by_login('admin')]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_index_pagination_page_2
|
||||||
|
User.per_page = 1
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, :page => 2
|
||||||
|
assert_equal assigns['users'],[User.find_by_login('jane')]
|
||||||
|
end
|
||||||
|
|
||||||
def test_destroy_user
|
def test_destroy_user
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue