Add scopes and filters for falling back soon and auto closing soon
This commit is contained in:
@@ -24,6 +24,8 @@ class Card < ApplicationRecord
|
||||
when "oldest" then chronologically
|
||||
when "latest" then latest
|
||||
when "stalled" then stalled.chronologically
|
||||
when "closing_soon" then closing_soon.chronologically
|
||||
when "falling_back_soon" then falling_back_soon.chronologically
|
||||
when "closed" then closed
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,23 @@ module Card::Entropic
|
||||
end
|
||||
|
||||
scope :stagnated, -> { doing.entropic_by(:auto_reconsider_period) }
|
||||
|
||||
scope :due_to_be_closed, -> { considering.entropic_by(:auto_close_period) }
|
||||
|
||||
scope :closing_soon, -> do
|
||||
considering
|
||||
.left_outer_joins(collection: :entropy_configuration)
|
||||
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropy_configurations.auto_close_period, ?) || ' seconds')", Entropy::Configuration.default.auto_close_period)
|
||||
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropy_configurations.auto_close_period, ?) * 0.75 AS INTEGER) || ' seconds')", Entropy::Configuration.default.auto_close_period)
|
||||
end
|
||||
|
||||
scope :falling_back_soon, -> do
|
||||
doing
|
||||
.left_outer_joins(collection: :entropy_configuration)
|
||||
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropy_configurations.auto_reconsider_period, ?) || ' seconds')", Entropy::Configuration.default.auto_reconsider_period)
|
||||
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropy_configurations.auto_reconsider_period, ?) * 0.75 AS INTEGER) || ' seconds')", Entropy::Configuration.default.auto_reconsider_period)
|
||||
end
|
||||
|
||||
delegate :auto_close_period, :auto_reconsider_period, to: :collection
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Filter::Fields
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
INDEXES = %w[ newest oldest latest stalled ]
|
||||
INDEXES = %w[ newest oldest latest stalled closing_soon falling_back_soon ]
|
||||
|
||||
delegate :default_value?, to: :class
|
||||
|
||||
|
||||
@@ -70,6 +70,16 @@ class Card::EntropicTest < ActiveSupport::TestCase
|
||||
assert_not cards(:shipping).reload.closed?
|
||||
end
|
||||
|
||||
test "closing soon scope" do
|
||||
cards(:logo, :shipping).each(&:published!).each(&:reconsider)
|
||||
|
||||
cards(:logo).update!(last_active_at: entropy_configurations(:writebook_collection).auto_close_period.seconds.ago + 2.days)
|
||||
cards(:shipping).update!(last_active_at: entropy_configurations(:writebook_collection).auto_close_period.seconds.ago - 2.days)
|
||||
|
||||
assert_includes Card.closing_soon, cards(:logo)
|
||||
assert_not_includes Card.closing_soon, cards(:shipping)
|
||||
end
|
||||
|
||||
test "auto consider all stagnated using the default account entropy configuration" do
|
||||
travel_to Time.current
|
||||
|
||||
@@ -104,4 +114,16 @@ class Card::EntropicTest < ActiveSupport::TestCase
|
||||
assert cards(:logo).reload.considering?
|
||||
assert_equal Time.current, cards(:logo).last_active_at
|
||||
end
|
||||
|
||||
test "falling back scope" do
|
||||
travel_to Time.current
|
||||
|
||||
cards(:logo, :shipping).each(&:engage)
|
||||
|
||||
cards(:logo).update!(last_active_at: 1.day.ago - entropy_configurations("writebook_collection").auto_close_period)
|
||||
cards(:shipping).update!(last_active_at: 1.day.from_now - entropy_configurations("writebook_collection").auto_close_period)
|
||||
|
||||
assert_includes Card.falling_back_soon, cards(:shipping)
|
||||
assert_not_includes Card.falling_back_soon, cards(:logo)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user