Skip to content
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
8 changes: 4 additions & 4 deletions app/views/solid_errors/occurrences/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@

<nav aria-label="Pages">
<% if (first_page = page.first) %>
<a href="<%= url_for(params.to_unsafe_hash.merge(page: first_page)) %>" aria-label="First" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&laquo;</a>
<a href="<%= url_for(page: first_page, items: params[:items]) %>" aria-label="First" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&laquo;</a>
<% else %>
<a role="link" aria-disabled="true" aria-label="First" class="border text-gray-500 bg-white py-1 px-2">&laquo;</a>
<% end %>

<% if (prev_page = page.prev) %>
<a href="<%= url_for(params.to_unsafe_hash.merge(page: prev_page)) %>" aria-label="Previous" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&lsaquo;</a>
<a href="<%= url_for(page: prev_page, items: params[:items]) %>" aria-label="Previous" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&lsaquo;</a>
<% else %>
<a role="link" aria-disabled="true" aria-label="Previous" class="border text-gray-500 bg-white py-1 px-2">&lsaquo;</a>
<% end %>

<% if (next_page = page.next) %>
<a href="<%= url_for(params.to_unsafe_hash.merge(page: next_page)) %>" aria-label="Next" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&rsaquo;</a>
<a href="<%= url_for(page: next_page, items: params[:items]) %>" aria-label="Next" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&rsaquo;</a>
<% else %>
<a role="link" aria-disabled="true" aria-label="Next" class="border text-gray-500 bg-white py-1 px-2">&rsaquo;</a>
<% end %>

<% if (last_page = page.last) %>
<a href="<%= url_for(params.to_unsafe_hash.merge(page: last_page)) %>" aria-label="Last" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&raquo;</a>
<a href="<%= url_for(page: last_page, items: params[:items]) %>" aria-label="Last" class="border border-black text-black bg-white py-1 px-2 cursor-pointer hover:bg-black hover:text-white">&raquo;</a>
<% else %>
<a role="link" aria-disabled="true" aria-label="Last" class="border text-gray-500 bg-white py-1 px-2">&raquo;</a>
<% end %>
Expand Down
52 changes: 52 additions & 0 deletions test/controllers/solid_errors/errors_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "test_helper"

class SolidErrors::ErrorsControllerTest < ActionDispatch::IntegrationTest
setup do
report_errors(2)
@error = SolidErrors::Error.last
end

test "occurrence pagination links use the default page size without an items param" do
report_errors(19)
get solid_errors.error_path(@error)

assert_response :success
assert_equal [solid_errors.error_path(@error, page: 2)] * 2, pagination_hrefs
end

test "occurrence pagination links keep the items param" do
get solid_errors.error_path(@error, items: 1)

assert_response :success
assert_equal [solid_errors.error_path(@error, items: 1, page: 2)] * 2, pagination_hrefs
end

test "occurrence pagination links ignore url_for options in the request params" do
get solid_errors.error_path(@error), params: {
items: 1,
script_name: "javascript:alert(1)//",
original_script_name: "javascript:alert(1)//",
host: "evil.example",
protocol: "https",
port: 6666,
anchor: "x"
}

assert_response :success
assert_equal [solid_errors.error_path(@error, items: 1, page: 2)] * 2, pagination_hrefs
end

private

def report_errors(count)
count.times do
raise StandardError, "oof"
rescue => error
Rails.error.report(error)
end
end

def pagination_hrefs
css_select("nav[aria-label=Pages] a[href]").map { |link| link["href"] }
end
end
2 changes: 2 additions & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", :as => :rails_health_check

mount SolidErrors::Engine, at: "/solid_errors"

# Defines the root path route ("/")
# root "posts#index"
end