-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51b6064
commit 9f27743
Showing
2 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe Kaminari::Helpers::HelperMethods do | ||
let(:dummy_class) { Class.new { extend Kaminari::Helpers::HelperMethods } } | ||
let(:scope) { double('FacetPaginator', instance_variable_get: 20) } | ||
let(:valid_page) { 1 } | ||
let(:total_entries) { 100 } | ||
let(:options) { { some_option: 'value' } } | ||
|
||
describe '#link_to_specific_page' do | ||
before do | ||
# Stub Kaminari::Helpers::Page.new to return a mock URL | ||
allow(Kaminari::Helpers::Page).to receive(:new).and_return(double(url: '/some_path')) | ||
end | ||
|
||
it 'generates a valid link for correct input' do | ||
result = dummy_class.path_to_specific_page(scope, valid_page, total_entries, options) | ||
expect(Rails.logger).to_not receive(:error) | ||
# Expect the method to return the mocked URL | ||
expect(result).to eq('/some_path') | ||
end | ||
|
||
|
||
it 'logs and returns nil for invalid page input' do | ||
invalid_page = -1 | ||
expect(Rails.logger).to receive(:error).with(/Page number must be a positive integer/) | ||
expect(dummy_class.link_to_specific_page(scope, invalid_page, total_entries, **options)) | ||
.to be_nil | ||
end | ||
|
||
it 'logs and returns nil if page exceeds total pages' do | ||
invalid_page = 999 | ||
expect(Rails.logger).to receive(:error).with(/Page number exceeds total pages/) | ||
expect(dummy_class.link_to_specific_page(scope, invalid_page, total_entries, **options)) | ||
.to be_nil | ||
end | ||
|
||
it 'logs and returns nil if an unexpected error occurs' do | ||
allow(Kaminari::Helpers::Page).to receive(:new).and_raise(StandardError, 'Simulated Kaminari Error') | ||
expect(Rails.logger).to receive(:error).with(/Unexpected error in path_to_specific_page/) | ||
expect(dummy_class.link_to_specific_page(scope, valid_page, total_entries, **options)) | ||
.to be_nil | ||
end | ||
end | ||
end |