diff --git a/app/controllers/staffs/accounts_controller.rb b/app/controllers/staffs/accounts_controller.rb index b2fb04b..ae20f11 100644 --- a/app/controllers/staffs/accounts_controller.rb +++ b/app/controllers/staffs/accounts_controller.rb @@ -9,7 +9,7 @@ class Staffs::AccountsController < ApplicationController @accounts = policy_scope( Account, policy_scope_class: Staff::AccountPolicy::Scope, - ) + ).page(params[:page]) end # GET /staff/accounts/:nickname diff --git a/app/views/staffs/accounts/index.html.erb b/app/views/staffs/accounts/index.html.erb index 6e155f0..b290060 100644 --- a/app/views/staffs/accounts/index.html.erb +++ b/app/views/staffs/accounts/index.html.erb @@ -5,4 +5,5 @@ ) %> <%= render partial: 'table', locals: { accounts: @accounts } %> + <%= pagination @accounts %> diff --git a/config/locales/activerecord/en.yml b/config/locales/activerecord/en.yml index a1929ff..4f25753 100644 --- a/config/locales/activerecord/en.yml +++ b/config/locales/activerecord/en.yml @@ -3,6 +3,7 @@ en: models: account: one: Account + few: Accounts many: Accounts contact: one: Contact diff --git a/config/locales/activerecord/ru.yml b/config/locales/activerecord/ru.yml index 3079638..7a0ed6b 100644 --- a/config/locales/activerecord/ru.yml +++ b/config/locales/activerecord/ru.yml @@ -3,6 +3,7 @@ ru: models: account: one: Аккаунт + few: Аккаунты many: Аккаунты contact: one: Контакт diff --git a/spec/requests/staff/accounts/index_spec.rb b/spec/requests/staff/accounts/index_spec.rb index c9730ea..87b7374 100644 --- a/spec/requests/staff/accounts/index_spec.rb +++ b/spec/requests/staff/accounts/index_spec.rb @@ -3,12 +3,16 @@ require 'rails_helper' RSpec.describe 'GET /staff/accounts' do + let(:current_account) { create :superuser_account } + + let :accounts_count do + [0, 1, rand(2..4), rand(5..10), rand(20..40)].sample + end + before do sign_in current_account.user if current_account&.user - create :usual_account - create :personal_account - create :superuser_account + create_list :personal_account, accounts_count get '/staff/accounts' end @@ -24,4 +28,44 @@ RSpec.describe 'GET /staff/accounts' do expect(response).to have_http_status :ok end end + + context 'when there are no accounts' do + let(:accounts_count) { 0 } + + specify do + expect(response).to have_http_status :ok + end + end + + context 'when there is one account' do + let(:accounts_count) { 1 } + + specify do + expect(response).to have_http_status :ok + end + end + + context 'when there are few accounts' do + let(:accounts_count) { rand 2..4 } + + specify do + expect(response).to have_http_status :ok + end + end + + context 'when there are many accounts' do + let(:accounts_count) { rand 5..10 } + + specify do + expect(response).to have_http_status :ok + end + end + + context 'when there are lot of accounts' do + let(:accounts_count) { rand 20..40 } + + specify do + expect(response).to have_http_status :ok + end + end end