-
Notifications
You must be signed in to change notification settings - Fork 54
/
current_user_serializer_spec.rb
65 lines (49 loc) · 2.22 KB
/
current_user_serializer_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
# frozen_string_literal: true
RSpec.describe CurrentUserSerializer do
fab!(:user1) { Fabricate(:user, trust_level: 3) }
let(:user2) { Fabricate(:user) }
fab!(:guardian) { Guardian.new(user1) }
fab!(:category)
fab!(:topic1) { Fabricate(:topic, category_id: category.id) }
let(:topic2) { Fabricate(:topic, category_id: category.id) }
let(:topic3) { Fabricate(:topic, category_id: category.id) }
let(:topic4) { Fabricate(:topic, category_id: category.id) }
it "does not return attributes related to voting if disabled" do
SiteSetting.voting_enabled = false
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_exceeded]).to eq(nil)
expect(json[:vote_count]).to eq(nil)
expect(json[:votes_left]).to eq(nil)
end
describe "votes_exceeded" do
it "returns false when within voting limits" do
SiteSetting.voting_enabled = true
SiteSetting.voting_tl3_vote_limit = 1
Fabricate(:topic_voting_votes, user: user2, topic: topic1)
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_exceeded]).to eq(false)
end
it "returns true when hit voting limits" do
SiteSetting.voting_enabled = true
SiteSetting.voting_tl3_vote_limit = 1
Fabricate(:topic_voting_votes, user: user1, topic: topic1)
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_exceeded]).to eq(true)
end
end
describe "votes_left" do
it "returns the number of votes the user has left" do
SiteSetting.voting_tl3_vote_limit = 3
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_left]).to eq(3)
Fabricate(:topic_voting_votes, user: user1, topic: topic1)
Fabricate(:topic_voting_votes, user: user1, topic: topic2)
Fabricate(:topic_voting_votes, user: user1, topic: topic3)
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_left]).to eq(0)
Fabricate(:topic_voting_votes, user: user1, topic: topic4)
json = described_class.new(user1, scope: guardian, root: false).as_json
expect(json[:votes_left]).to eq(0)
end
end
end