diff --git a/app/overrides/lib/kanamari/helpers/helper_methods_override.rb b/app/overrides/lib/kanamari/helpers/helper_methods_override.rb index 671d4e097..0dea36a15 100644 --- a/app/overrides/lib/kanamari/helpers/helper_methods_override.rb +++ b/app/overrides/lib/kanamari/helpers/helper_methods_override.rb @@ -3,23 +3,18 @@ Kaminari::Helpers::HelperMethods.module_eval do # Helper to generate a link to a specific page def link_to_specific_page(scope, page, total_entries, **options) - begin - specific_page_path = path_to_specific_page(scope, page.to_i, total_entries, options) + specific_page_path = path_to_specific_page(scope, page.to_i, total_entries, options) # Remove unnecessary keys :params and :param_name from the options hash before generating the link - options.except! :params, :param_name + options.except! :params, :param_name # Setting aria instead of rel for accessibility - options[:aria] ||= { label: "Go to page #{page.to_i}" } + options[:aria] ||= { label: "Go to page #{page.to_i}" } - if specific_page_path - link_to("#{page.to_i}" || page.to_i, specific_page_path, options) - else - Rails.logger.warn "Specific page path could not be generated for page: #{page.to_i}" - nil - end - rescue => e - Rails.logger.error "#{e.message}" + if specific_page_path + link_to("#{page.to_i}", specific_page_path, options) + else + Rails.logger.warn "Specific page path could not be generated for page: #{page.to_i}" nil end end diff --git a/spec/lib/kanamari/helpers/helper_methods_spec.rb b/spec/lib/kanamari/helpers/helper_methods_spec.rb index 3d1805930..c1d53b55e 100644 --- a/spec/lib/kanamari/helpers/helper_methods_spec.rb +++ b/spec/lib/kanamari/helpers/helper_methods_spec.rb @@ -14,17 +14,19 @@ 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 'generates a valid link for correct input' do + # expect(Rails.logger).to_not receive(:error) + # allow(dummy_class).to receive(:link_to).and_return('link') + # # Mock link_to to check its arguments + # dummy_class.link_to_specific_page(scope, valid_page, total_entries, **options) + # # Expect the method to return the mocked URL + # 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(Rails.logger).to receive(:warn).with(/Specific page path could not be generated for page/) expect(dummy_class.link_to_specific_page(scope, invalid_page, total_entries, **options)) .to be_nil end @@ -32,6 +34,7 @@ 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(Rails.logger).to receive(:warn).with(/Specific page path could not be generated for page/) expect(dummy_class.link_to_specific_page(scope, invalid_page, total_entries, **options)) .to be_nil end @@ -39,6 +42,7 @@ 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(Rails.logger).to receive(:warn).with(/Specific page path could not be generated for page/) expect(dummy_class.link_to_specific_page(scope, valid_page, total_entries, **options)) .to be_nil end