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

Issue 5069: Add pagination to product drives #5077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/product_drives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def index
.class_filter(filter_params)
.within_date_range(@selected_date_range)
.order(start_date: :desc)
@paginated_product_drives = @product_drives.page(params[:page])

# to be used in the name filter to sort product drives in alpha order
@product_drives_alphabetical = @product_drives.sort_by { |pd| pd.name.downcase }
@item_categories = current_organization.item_categories
Expand Down
8 changes: 4 additions & 4 deletions app/views/product_drives/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</tr>
</thead>
<tbody>
<% @product_drives.each do |product_drive| %>
<% @paginated_product_drives.each do |product_drive| %>
<tr>
<td><%= product_drive.name %></td>
<td><%= product_drive.start_date.strftime("%m-%d-%Y") %></td>
Expand All @@ -119,9 +119,9 @@
</table>
</div>
<!-- /.card-body -->
<!-- <div class="card-footer clearfix">-->
<%#= paginate @paginated_requests %>
<!-- </div>-->
<div class="card-footer clearfix">
<%= paginate @paginated_product_drives %>
</div>
<!-- /.card-footer-->
</div>
<!-- /.card -->
Expand Down
34 changes: 34 additions & 0 deletions spec/requests/product_drives_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@
end
end
end

describe "pagination" do
around do |ex|
Kaminari.config.default_per_page = 2
ex.run
Kaminari.config.default_per_page = 5
end

before do
# Create a list of Product Drives to exceed pagination limit
create_list(:product_drive, 10, organization: organization)

# Fetch Product Drives before assertions
get product_drives_path
end

it "displays pagination controls when there are more product drives than default per page" do
expect(response).to be_successful

parsed_html = Nokogiri::HTML(response.body)

# Select the Product Drives table, which is the only table in the view
# and count the rows
product_drives_table = parsed_html.at_css("table.table")
row_count = product_drives_table.css("tbody tr").size

# There should be 2 rows on the first page--the default per page configured above
expect(row_count).to eq(2)

# Check that pagination controls (e.g., "Next" button) appear
next_button = parsed_html.at_css('a, button') { |el| el.text.strip == 'Next' }
expect(next_button).not_to be_nil
end
end
end

describe "GET #new" do
Expand Down