Update Card::Entropic so its scopes work cross-accounts
with an eye towards making the postpone_all_due recurring job work efficiently.
This commit is contained in:
@@ -4,16 +4,19 @@ module Card::Entropic
|
||||
included do
|
||||
scope :due_to_be_postponed, -> do
|
||||
active
|
||||
.joins(board: :account)
|
||||
.left_outer_joins(board: :entropy)
|
||||
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, ?) SECOND)",
|
||||
Current.account.entropy.auto_postpone_period)
|
||||
.joins("LEFT OUTER JOIN entropies AS account_entropies ON account_entropies.account_id = accounts.id AND account_entropies.container_type = 'Account' AND account_entropies.container_id = accounts.id")
|
||||
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)")
|
||||
end
|
||||
|
||||
scope :postponing_soon, -> do
|
||||
active
|
||||
.joins(board: :account)
|
||||
.left_outer_joins(board: :entropy)
|
||||
.where("last_active_at > DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, ?) SECOND)", Current.account.entropy.auto_postpone_period)
|
||||
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL CAST(COALESCE(entropies.auto_postpone_period, ?) * 0.75 AS SIGNED) SECOND)", Current.account.entropy.auto_postpone_period)
|
||||
.joins("LEFT OUTER JOIN entropies AS account_entropies ON account_entropies.account_id = accounts.id AND account_entropies.container_type = 'Account' AND account_entropies.container_id = accounts.id")
|
||||
.where("last_active_at > DATE_SUB(NOW(), INTERVAL COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) SECOND)")
|
||||
.where("last_active_at <= DATE_SUB(NOW(), INTERVAL CAST(COALESCE(entropies.auto_postpone_period, account_entropies.auto_postpone_period) * 0.75 AS SIGNED) SECOND)")
|
||||
end
|
||||
|
||||
delegate :auto_postpone_period, to: :board
|
||||
|
||||
Vendored
+3
-3
@@ -12,9 +12,9 @@ private:
|
||||
all_access: false
|
||||
account: 37s_uuid
|
||||
|
||||
staplers:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("staplers", :uuid) %>
|
||||
name: Staplers
|
||||
miltons_wish_list:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("miltons_wish_list", :uuid) %>
|
||||
name: Milton's Wish List
|
||||
creator: mike_uuid
|
||||
all_access: true
|
||||
account: initech_uuid
|
||||
|
||||
Vendored
+21
@@ -58,3 +58,24 @@ buy_domain:
|
||||
last_active_at: <%= 1.week.ago %>
|
||||
account: 37s_uuid
|
||||
|
||||
radio:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("radio", :uuid) %>
|
||||
number: 1
|
||||
board: miltons_wish_list_uuid
|
||||
creator: mike_uuid
|
||||
title: I want to play my radio at a reasonable volume
|
||||
created_at: <%= 1.week.ago %>
|
||||
status: published
|
||||
last_active_at: <%= 1.week.ago %>
|
||||
account: initech_uuid
|
||||
|
||||
paycheck:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("paycheck", :uuid) %>
|
||||
number: 2
|
||||
board: miltons_wish_list_uuid
|
||||
creator: mike_uuid
|
||||
title: I haven't received my paycheck
|
||||
created_at: <%= 1.week.ago %>
|
||||
status: published
|
||||
last_active_at: <%= 1.week.ago %>
|
||||
account: initech_uuid
|
||||
|
||||
Vendored
+12
@@ -15,3 +15,15 @@ private_board:
|
||||
account: 37s_uuid
|
||||
container: private_uuid (Board)
|
||||
auto_postpone_period: <%= 30.days.to_i %>
|
||||
|
||||
initech_account:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("initech_account", :uuid) %>
|
||||
account: initech_uuid
|
||||
container: initech_uuid (Account)
|
||||
auto_postpone_period: <%= 30.days.to_i %>
|
||||
|
||||
miltons_wish_list_board:
|
||||
id: <%= ActiveRecord::FixtureSet.identify("miltons_wish_list_board", :uuid) %>
|
||||
account: initech_uuid
|
||||
container: miltons_wish_list_uuid (Board)
|
||||
auto_postpone_period: <%= 90.days.to_i %>
|
||||
|
||||
@@ -68,4 +68,26 @@ class Card::EntropicTest < ActiveSupport::TestCase
|
||||
assert_includes Card.postponing_soon, cards(:logo)
|
||||
assert_not_includes Card.postponing_soon, cards(:shipping)
|
||||
end
|
||||
|
||||
test "due_to_be_postponed scope works properly cross-account" do
|
||||
cards(:logo).update!(last_active_at: entropies(:writebook_board).auto_postpone_period.seconds.ago - 2.days)
|
||||
cards(:radio).update!(last_active_at: entropies(:miltons_wish_list_board).auto_postpone_period.seconds.ago - 2.days)
|
||||
|
||||
actual = Card.due_to_be_postponed.to_a
|
||||
|
||||
cards(:logo, :radio).each do |card|
|
||||
assert_includes actual, card
|
||||
end
|
||||
end
|
||||
|
||||
test "postponing_soon scope works properly cross-account" do
|
||||
cards(:logo).update!(last_active_at: entropies(:writebook_board).auto_postpone_period.seconds.ago + 2.days)
|
||||
cards(:radio).update!(last_active_at: entropies(:miltons_wish_list_board).auto_postpone_period.seconds.ago + 2.days)
|
||||
|
||||
actual = Card.postponing_soon.to_a
|
||||
|
||||
cards(:logo, :radio).each do |card|
|
||||
assert_includes actual, card
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -80,11 +80,12 @@ class CardTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "open" do
|
||||
assert_equal cards(:logo, :layout, :text, :buy_domain).to_set, Card.open.to_set
|
||||
assert_equal cards(:logo, :layout, :text, :buy_domain).to_set, accounts("37s").cards.open.to_set
|
||||
assert_equal cards(:radio, :paycheck).to_set, accounts("initech").cards.open.to_set
|
||||
end
|
||||
|
||||
test "card_unassigned" do
|
||||
assert_equal cards(:shipping, :text, :buy_domain).to_set, Card.unassigned.to_set
|
||||
assert_equal cards(:shipping, :text, :buy_domain).to_set, accounts("37s").cards.unassigned.to_set
|
||||
end
|
||||
|
||||
test "assigned to" do
|
||||
|
||||
Reference in New Issue
Block a user