From 53572ef63b8e0477d48924e9c83857d0407b8f50 Mon Sep 17 00:00:00 2001 From: Kevin Dai Date: Mon, 28 Oct 2024 18:05:15 -0400 Subject: [PATCH] add rspec tests for user pagination options --- spec/controllers/users_controller_spec.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index e19ba856282..88f2bd67745 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -392,4 +392,30 @@ expect(response).to redirect_to('/tree_display/drill') end end + + context '#paginate_list' do + before do + # Seed the database with a number of users for pagination tests + create_list(:user, 120) + + it 'displays 25 users per page when per_page is 25' do + get :paginate_list, params: { per_page: '1' } + expect(assigns(:users).length).to eq(25) + end + + it 'displays 50 users per page when per_page is 50' do + get :paginate_list, params: { per_page: '2' } + expect(assigns(:users).length).to eq(50) + end + + it 'displays 100 users per page when per_page is 100' do + get :paginate_list, params: { per_page: '3' } + expect(assigns(:users).length).to eq(100) + end + + it 'displays all users on a single page when per_page is "all"' do + get :paginate_list, params: { per_page: '4' } + expect(assigns(:users).length).to eq(User.count) + end + end end