forked from basecamp/fizzy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentropic_test.rb
More file actions
85 lines (63 loc) · 3.4 KB
/
Copy pathentropic_test.rb
File metadata and controls
85 lines (63 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require "test_helper"
class Card::EntropicTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
end
test "auto_postpone_at uses the period defined in the account by default" do
freeze_time
entropies(:writebook_board).destroy
entropies("37s_account").reload.update! auto_postpone_period: 365.days
cards(:layout).update! last_active_at: 2.day.ago
assert_equal (365 - 2).days.from_now, cards(:layout).entropy.auto_clean_at
end
test "auto_postpone_at infers the period from the board when present" do
freeze_time
entropies(:writebook_board).update! auto_postpone_period: 90.days
cards(:layout).update! last_active_at: 2.day.ago
assert_equal (90 - 2).days.from_now, cards(:layout).entropy.auto_clean_at
end
test "setting auto_postpone_period in the board without entropy will create it, without affecting the account entropy" do
account_entropy = entropies("37s_account")
original_period = account_entropy.auto_postpone_period
entropies(:writebook_board).destroy
boards(:writebook).update! auto_postpone_period: 365.days
assert_equal original_period, account_entropy.reload.auto_postpone_period
end
test "auto postpone all due using the default account entropy" do
entropies(:writebook_board).destroy
cards(:logo).update!(last_active_at: 1.day.ago - entropies("37s_account").auto_postpone_period)
cards(:shipping).update!(last_active_at: 1.day.from_now - entropies("37s_account").auto_postpone_period)
assert_difference -> { Card.postponed.count }, +1 do
Card.auto_postpone_all_due
end
assert cards(:logo).reload.postponed?
assert_equal accounts("37s").system_user, cards(:logo).postponed_by
assert_not cards(:shipping).reload.postponed?
end
test "auto postpone all due using entropy defined at the board level" do
cards(:logo).update!(last_active_at: 1.day.ago - entropies(:writebook_board).auto_postpone_period)
cards(:shipping).update!(last_active_at: 1.day.from_now - entropies(:writebook_board).auto_postpone_period)
assert_difference -> { Card.postponed.count }, +1 do
Card.auto_postpone_all_due
end
assert cards(:logo).reload.postponed?
assert_not cards(:shipping).reload.postponed?
end
test "postponing soon scope" do
cards(:logo, :shipping).each(&:published!)
cards(:logo).update!(last_active_at: entropies(:writebook_board).auto_postpone_period.seconds.ago + 2.days)
cards(:shipping).update!(last_active_at: entropies(:writebook_board).auto_postpone_period.seconds.ago - 2.days)
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)
assert_equal(cards(:logo, :radio).to_set, Card.due_to_be_postponed.to_set)
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)
assert_equal(cards(:logo, :radio).to_set, Card.postponing_soon.to_set)
end
end