Checks in error filterable

This commit is contained in:
Colin Darie 2018-07-04 11:55:44 +02:00
parent 380960fa75
commit cac52c1007
No known key found for this signature in database
GPG Key ID: 4FB865FDBCA4BCC4
4 changed files with 14 additions and 0 deletions

View File

@ -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])

View File

@ -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 }

View File

@ -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") %>

View File

@ -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)