diff --git a/app/jobs/card/touch_all_job.rb b/app/jobs/card/touch_all_job.rb deleted file mode 100644 index 7b96fa5b7..000000000 --- a/app/jobs/card/touch_all_job.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Card::TouchAllJob < ApplicationJob - queue_as :backend - - def perform(container) - container.cards.in_batches(&:touch_all) - end -end diff --git a/app/models/collection/cards.rb b/app/models/collection/cards.rb index 17ed592aa..105f4912b 100644 --- a/app/models/collection/cards.rb +++ b/app/models/collection/cards.rb @@ -4,11 +4,6 @@ module Collection::Cards included do has_many :cards, dependent: :destroy - after_update_commit :touch_all_cards_later, if: :saved_change_to_name? + after_update_commit -> { cards.touch_all }, if: :saved_change_to_name? end - - private - def touch_all_cards_later - Card::TouchAllJob.perform_later(self) - end end diff --git a/app/models/column.rb b/app/models/column.rb index 0285ab185..d0c1ce102 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -8,23 +8,11 @@ class Column < ApplicationRecord validates :color, presence: true before_validation :set_default_color - after_save_commit :touch_all_cards_later, if: :should_invalidate_cards? - after_destroy_commit :touch_all_collection_cards + after_save_commit -> { cards.touch_all }, if: -> { saved_change_to_name? || saved_change_to_color? } + after_destroy_commit -> { collection.cards.touch_all } private def set_default_color self.color ||= Card::DEFAULT_COLOR end - - def touch_all_cards_later - Card::TouchAllJob.perform_later(self) - end - - def should_invalidate_cards? - saved_change_to_name? || saved_change_to_color? - end - - def touch_all_collection_cards - Card::TouchAllJob.perform_later(collection) - end end diff --git a/app/models/entropy.rb b/app/models/entropy.rb index 613d1a315..6940ed813 100644 --- a/app/models/entropy.rb +++ b/app/models/entropy.rb @@ -1,16 +1,11 @@ class Entropy < ApplicationRecord belongs_to :container, polymorphic: true - after_commit :touch_all_cards_later + after_commit -> { container.cards.touch_all } class << self def default Account.sole.default_entropy end end - - private - def touch_all_cards_later - Card::TouchAllJob.perform_later(container) - end end diff --git a/test/models/collection/cards_test.rb b/test/models/collection/cards_test.rb index f2ec9b9db..34bed8d8c 100644 --- a/test/models/collection/cards_test.rb +++ b/test/models/collection/cards_test.rb @@ -4,11 +4,11 @@ class Collection::CardsTest < ActiveSupport::TestCase test "touch cards when the name changes" do collection = collections(:writebook) - assert_enqueued_with(job: Card::TouchAllJob) do + assert_changes -> { collection.cards.first.updated_at } do collection.update!(name: "New Name") end - assert_no_enqueued_jobs(only: Card::TouchAllJob) do + assert_no_changes -> { collection.cards.first.updated_at } do collection.update!(updated_at: 1.hour.from_now) end end diff --git a/test/models/column_test.rb b/test/models/column_test.rb index d924de308..e4786abfb 100644 --- a/test/models/column_test.rb +++ b/test/models/column_test.rb @@ -10,15 +10,15 @@ class ColumnTest < ActiveSupport::TestCase test "touch all the cards when the name or color changes" do column = columns(:writebook_triage) - assert_enqueued_with(job: Card::TouchAllJob) do + assert_changes -> { column.cards.first.updated_at } do column.update!(name: "New Name") end - assert_enqueued_with(job: Card::TouchAllJob) do + assert_changes -> { column.cards.first.updated_at } do column.update!(color: "#FF0000") end - assert_no_enqueued_jobs(only: Card::TouchAllJob) do + assert_no_changes -> { column.cards.first.updated_at } do column.update!(updated_at: 1.hour.from_now) end end @@ -26,7 +26,7 @@ class ColumnTest < ActiveSupport::TestCase test "touch all collection cards when column is destroyed" do column = columns(:writebook_triage) - assert_enqueued_with(job: Card::TouchAllJob, args: [ column.collection ]) do + assert_changes -> { column.collection.cards.first.updated_at } do column.destroy end end diff --git a/test/models/entropy_test.rb b/test/models/entropy_test.rb index 08fbf8600..f5056cf76 100644 --- a/test/models/entropy_test.rb +++ b/test/models/entropy_test.rb @@ -1,20 +1,17 @@ require "test_helper" class Entropy::Test < ActiveSupport::TestCase - test "touch cards when entropy changes for collection container" do - collection = collections(:writebook) - config = collection.entropy || collection.create_entropy!(auto_postpone_period: 30.days) - - assert_enqueued_with(job: Card::TouchAllJob, args: [ collection ]) do - config.update!(auto_postpone_period: 15.days) + test "touch cards when entropy changes for collection" do + assert_changes -> { collections(:writebook).cards.first.updated_at } do + collections(:writebook).entropy.update!(auto_postpone_period: 15.days) end end test "touch cards when entropy changes for account container" do account = Account.sole - assert_enqueued_with(job: Card::TouchAllJob, args: [ account ]) do - account.default_entropy.update!(auto_postpone_period: 45.days) + assert_changes -> { account.cards.first.updated_at } do + collections(:writebook).entropy.update!(auto_postpone_period: 15.days) end end end