mirror of https://github.com/Evolix/chexpire.git
Checks in error filterable
This commit is contained in:
parent
380960fa75
commit
cac52c1007
|
@ -6,6 +6,7 @@ class ChecksController < ApplicationController
|
|||
|
||||
has_scope :kind
|
||||
has_scope :by_domain
|
||||
has_scope :recurrent_failures, type: :boolean
|
||||
|
||||
def index
|
||||
@checks = apply_scopes(policy_scope(Check)).order(current_sort).page(params[:page])
|
||||
|
|
|
@ -60,6 +60,10 @@ class Check < ApplicationRecord
|
|||
|
||||
scope :kind, ->(kind) { where(kind: kind) }
|
||||
scope :by_domain, ->(domain) { where("domain LIKE ?", "%#{domain}%") }
|
||||
scope :recurrent_failures, -> {
|
||||
where("last_run_at IS NOT NULL").
|
||||
where("last_success_at IS NULL OR last_success_at <= DATE_SUB(last_run_at, INTERVAL 72 HOUR)")
|
||||
}
|
||||
|
||||
def self.default_sort
|
||||
{ domain_expires_at: :asc }
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<h1><%= t(".title") %></h1>
|
||||
<%= link_to("Domains", checks_path(current_criterias.merge(kind: :domain))) %>
|
||||
<%= link_to("SSL", checks_path(current_criterias.merge(kind: :ssl))) %>
|
||||
<%= link_to("In error", checks_path(current_criterias.merge(recurrent_failures: true))) %>
|
||||
<%= form_tag(checks_path(current_scopes), method: :get) do %>
|
||||
<%= search_field_tag :by_domain, current_scopes[:by_domain] %>
|
||||
<%= button_tag t(".filter") %>
|
||||
|
|
|
@ -116,6 +116,14 @@ class ChecksControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_empty current_checks
|
||||
end
|
||||
|
||||
test "checks in error are filtered" do
|
||||
c1 = create(:check, :last_runs_failed, user: @user)
|
||||
create(:check, user: @user)
|
||||
|
||||
get checks_path(recurrent_failures: true)
|
||||
assert_equal [c1], current_checks
|
||||
end
|
||||
|
||||
test "checks are paginated" do
|
||||
create_list(:check, 40, user: @user)
|
||||
|
||||
|
|
Loading…
Reference in New Issue