Invalidate cards when entropy configuration changes
This commit is contained in:
@@ -11,6 +11,11 @@ class Account < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# This lets us use the account as a generic card container. See +Entropy::Configuration+.
|
||||
def cards
|
||||
Card.all
|
||||
end
|
||||
|
||||
def slug
|
||||
"/#{tenant}"
|
||||
end
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
class Entropy::Configuration < ApplicationRecord
|
||||
belongs_to :container, polymorphic: true
|
||||
|
||||
after_commit :touch_all_container_cards_later
|
||||
|
||||
class << self
|
||||
def default
|
||||
Account.sole.default_entropy_configuration
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def touch_all_container_cards_later
|
||||
Card::TouchAllJob.perform_later(container)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
require "test_helper"
|
||||
|
||||
class Entropy::ConfigurationTest < ActiveSupport::TestCase
|
||||
test "touch cards when configuration changes for collection container" do
|
||||
collection = collections(:writebook)
|
||||
config = collection.entropy_configuration || collection.create_entropy_configuration!(auto_postpone_period: 30.days)
|
||||
|
||||
assert_enqueued_with(job: Card::TouchAllJob, args: [ collection ]) do
|
||||
config.update!(auto_postpone_period: 15.days)
|
||||
end
|
||||
end
|
||||
|
||||
test "touch cards when configuration changes for account container" do
|
||||
account = Account.sole
|
||||
|
||||
assert_enqueued_with(job: Card::TouchAllJob, args: [ account ]) do
|
||||
account.default_entropy_configuration.update!(auto_postpone_period: 45.days)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user