-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathdirectory_item_spec.rb
105 lines (81 loc) · 2.91 KB
/
directory_item_spec.rb
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# frozen_string_literal: true
describe DirectoryItem, type: :model do
describe "Updating user directory with solutions count" do
fab!(:user)
fab!(:admin)
fab!(:topic1) { Fabricate(:topic, archetype: "regular", user:) }
fab!(:topic_post1) { Fabricate(:post, topic: topic1, user:, created_at: 10.years.ago) }
fab!(:topic2) { Fabricate(:topic, archetype: "regular", user:) }
fab!(:topic_post2) { Fabricate(:post, topic: topic2, user:, created_at: 10.years.ago) }
fab!(:pm) { Fabricate(:topic, archetype: "private_message", user:, category_id: nil) }
fab!(:pm_post) { Fabricate(:post, topic: pm, user:) }
before { SiteSetting.solved_enabled = true }
it "excludes PM post solutions from solutions" do
DiscourseSolved.accept_answer!(topic_post1, admin)
DiscourseSolved.accept_answer!(pm_post, admin)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:all],
).solutions,
).to eq(1)
end
it "excludes deleted posts from solutions" do
DiscourseSolved.accept_answer!(topic_post1, admin)
DiscourseSolved.accept_answer!(topic_post2, admin)
topic_post2.update(deleted_at: Time.zone.now)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:all],
).solutions,
).to eq(1)
end
it "excludes deleted topics from solutions" do
DiscourseSolved.accept_answer!(topic_post1, admin)
DiscourseSolved.accept_answer!(topic_post2, admin)
topic2.update(deleted_at: Time.zone.now)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:all],
).solutions,
).to eq(1)
end
it "excludes solutions for silenced users" do
user.update(silenced_till: Time.zone.now + 1.day)
DiscourseSolved.accept_answer!(topic_post1, admin)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:all],
)&.solutions,
).to eq(nil)
end
it "excludes solutions for suspended users" do
DiscourseSolved.accept_answer!(topic_post1, admin)
user.update(suspended_till: Time.zone.now + 1.day)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:all],
)&.solutions,
).to eq(0)
end
it "includes solutions for active users" do
DiscourseSolved.accept_answer!(topic_post1, admin)
DirectoryItem.refresh!
expect(
DirectoryItem.find_by(
user_id: user.id,
period_type: DirectoryItem.period_types[:daily],
).solutions,
).to eq(1)
end
end
end