diff --git a/app/controllers/checks_controller.rb b/app/controllers/checks_controller.rb index fff3482..7610ab3 100644 --- a/app/controllers/checks_controller.rb +++ b/app/controllers/checks_controller.rb @@ -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]) diff --git a/app/models/check.rb b/app/models/check.rb index 6d214a6..a54def2 100644 --- a/app/models/check.rb +++ b/app/models/check.rb @@ -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 } diff --git a/app/views/checks/index.html.erb b/app/views/checks/index.html.erb index 606ee1f..b6ce6b3 100644 --- a/app/views/checks/index.html.erb +++ b/app/views/checks/index.html.erb @@ -9,6 +9,7 @@

<%= t(".title") %>

<%= 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") %> diff --git a/test/controllers/checks_controller_test.rb b/test/controllers/checks_controller_test.rb index 54650cc..92e22d9 100644 --- a/test/controllers/checks_controller_test.rb +++ b/test/controllers/checks_controller_test.rb @@ -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)