include EmailMethods
include SessionMethods
include UserMethods
+ include PaginationMethods
layout "site"
redirect_to url_for(:status => params[:status], :ip => params[:ip], :page => params[:page])
else
- @params = params.permit(:status, :ip)
+ @params = params.permit(:status, :ip, :before, :after)
- conditions = {}
- conditions[:status] = @params[:status] if @params[:status]
- conditions[:creation_ip] = @params[:ip] if @params[:ip]
+ users = User.all
+ users = users.where(:status => @params[:status]) if @params[:status]
+ users = users.where(:creation_ip => @params[:ip]) if @params[:ip]
- @user_pages, @users = paginate(:users,
- :conditions => conditions,
- :order => :id,
- :per_page => 50)
+ @users, @newer_users_id, @older_users_id = get_page_items(users, :limit => 50)
end
end
<% unless @users.empty? %>
<%= form_tag do %>
+ <%= render "shared/pagination",
+ :newer_key => "users.index.newer",
+ :older_key => "users.index.older",
+ :newer_id => @newer_users_id,
+ :older_id => @older_users_id %>
+
<%= hidden_field_tag :status, params[:status] if params[:status] %>
<%= hidden_field_tag :ip, params[:ip] if params[:ip] %>
<%= hidden_field_tag :page, params[:page] if params[:page] %>
<thead>
<tr>
<td colspan="2">
- <%= t ".showing",
- :page => @user_pages.current_page.number,
- :first_item => @user_pages.current_page.first_item,
- :last_item => @user_pages.current_page.last_item,
- :items => @user_pages.item_count,
- :count => @user_pages.current_page.last_item - @user_pages.current_page.first_item + 1 %>
- <% if @user_pages.page_count > 1 %>
- | <%= raw pagination_links_each(@user_pages, {}) { |n| link_to n, @params.merge(:page => n) } %>
- <% end %>
</td>
<td>
<%= check_box_tag "user_all", "1", false %>
<%= render @users %>
</table>
+ <%= render "shared/pagination",
+ :newer_key => "users.index.newer",
+ :older_key => "users.index.older",
+ :newer_id => @newer_users_id,
+ :older_id => @older_users_id %>
+
<div>
<%= submit_tag t(".confirm"), :name => "confirm", :class => "btn btn-primary" %>
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-primary" %>
index:
title: Users
heading: Users
- showing:
- one: Page %{page} (%{first_item} of %{items})
- other: Page %{page} (%{first_item}-%{last_item} of %{items})
+ older: "Older Users"
+ newer: "Newer Users"
summary_html: "%{name} created from %{ip_address} on %{date}"
summary_no_ip_html: "%{name} created on %{date}"
confirm: Confirm Selected Users
# 100 examples, an administrator, and a granter for the admin.
assert_equal 102, User.count
+ next_path = users_path
- get users_path
+ get next_path
assert_response :success
assert_template :index
assert_select "table#user_list tbody tr", :count => 50
+ check_no_page_link "Newer Users"
+ next_path = check_page_link "Older Users"
- get users_path, :params => { :page => 2 }
+ get next_path
assert_response :success
assert_template :index
assert_select "table#user_list tbody tr", :count => 50
+ check_page_link "Newer Users"
+ next_path = check_page_link "Older Users"
- get users_path, :params => { :page => 3 }
+ get next_path
assert_response :success
assert_template :index
assert_select "table#user_list tbody tr", :count => 2
+ check_page_link "Newer Users"
+ check_no_page_link "Older Users"
+ end
+
+ private
+
+ def check_no_page_link(name)
+ assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/, :count => 0 }, "unexpected #{name} page link"
end
+ def check_page_link(name)
+ assert_select "a.page-link", { :text => /#{Regexp.quote(name)}/ }, "missing #{name} page link" do |buttons|
+ return buttons.first.attributes["href"].value
+ end
+ end
+
+ public
+
def test_index_post_confirm
inactive_user = create(:user, :pending)
suspended_user = create(:user, :suspended)