|
3 | 3 | describe DiscourseSolved::FirstAcceptedPostSolutionValidator do |
4 | 4 | fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) } |
5 | 5 |
|
6 | | - context "when user is under max trust level" do |
7 | | - context "with no post accepted yet" do |
8 | | - it "validates the post" do |
9 | | - post_1 = create_post(user: user_tl1) |
10 | | - expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(true) |
11 | | - end |
| 6 | + context "when trust level is 'any'" do |
| 7 | + it "validates the post" do |
| 8 | + post = Fabricate(:post, user: user_tl1) |
| 9 | + DiscourseSolved.accept_answer!(post, Discourse.system_user) |
| 10 | + |
| 11 | + expect(described_class.check(post, trust_level: "any")).to eq(true) |
12 | 12 | end |
13 | 13 |
|
14 | | - context "with already had accepted posts" do |
15 | | - before do |
16 | | - accepted_post = create_post(user: user_tl1) |
17 | | - DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user) |
18 | | - end |
| 14 | + it "invalidates if post user already has an accepted post" do |
| 15 | + previously_accepted_post = Fabricate(:post, user: user_tl1) |
| 16 | + DiscourseSolved.accept_answer!(previously_accepted_post, Discourse.system_user) |
19 | 17 |
|
20 | | - it "doesn’t validate the post" do |
21 | | - post_1 = create_post(user: user_tl1) |
22 | | - expect(described_class.check(post_1, trust_level: TrustLevel[2])).to eq(false) |
23 | | - end |
| 18 | + newly_accepted_post = Fabricate(:post, user: user_tl1) |
| 19 | + DiscourseSolved.accept_answer!(newly_accepted_post, Discourse.system_user) |
| 20 | + |
| 21 | + expect(described_class.check(newly_accepted_post, trust_level: "any")).to eq(false) |
24 | 22 | end |
25 | 23 | end |
26 | 24 |
|
27 | | - context "when a user is above or equal max trust level" do |
28 | | - context "with no post accepted yet" do |
29 | | - it "doesn’t validate the post" do |
30 | | - post_1 = create_post(user: user_tl1) |
31 | | - expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false) |
32 | | - end |
33 | | - end |
| 25 | + context "with specified trust level that is not 'any'" do |
| 26 | + # the automation indicates "users under this Trust Level will trigger this automation" |
34 | 27 |
|
35 | | - context "when a post is already accepted" do |
36 | | - before do |
37 | | - accepted_post = create_post(user: user_tl1) |
38 | | - DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user) |
39 | | - end |
| 28 | + it "invalidates if the user is higher than or equal to the specified trust level" do |
| 29 | + post = Fabricate(:post, user: user_tl1) |
| 30 | + DiscourseSolved.accept_answer!(post, Discourse.system_user) |
40 | 31 |
|
41 | | - it "doesn’t validate the post" do |
42 | | - post_1 = create_post(user: user_tl1) |
43 | | - expect(described_class.check(post_1, trust_level: TrustLevel[1])).to eq(false) |
44 | | - end |
| 32 | + expect(described_class.check(post, trust_level: TrustLevel[0])).to eq(false) |
| 33 | + expect(described_class.check(post, trust_level: TrustLevel[1])).to eq(false) |
45 | 34 | end |
46 | | - end |
47 | 35 |
|
48 | | - context "when using any trust level" do |
49 | | - it "validates the post" do |
50 | | - post_1 = create_post(user: user_tl1) |
51 | | - expect(described_class.check(post_1, trust_level: "any")).to eq(true) |
52 | | - end |
| 36 | + it "validates the post when user is under specified trust level" do |
| 37 | + post = Fabricate(:post, user: user_tl1) |
| 38 | + DiscourseSolved.accept_answer!(post, Discourse.system_user) |
53 | 39 |
|
54 | | - it "invalidates if post user already has an accepted post" do |
55 | | - accepted_post = create_post(user: user_tl1) |
56 | | - DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user) |
57 | | - post_1 = create_post(user: user_tl1) |
58 | | - expect(described_class.check(post_1, trust_level: "any")).to eq(false) |
| 40 | + expect(described_class.check(post, trust_level: TrustLevel[2])).to eq(true) |
59 | 41 | end |
60 | 42 | end |
61 | 43 |
|
|
0 commit comments