blob: 6c7f29cbd7135db9c6b6a7052bd3d7ea52377c57 (
plain)
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ApplicationSetting::Term do
it { is_expected.to validate_presence_of(:terms) }
describe '.latest' do
it 'finds the latest terms' do
terms = create(:term)
expect(described_class.latest).to eq(terms)
end
end
describe '#accepted_by_user?' do
let(:user) { create(:user) }
let(:project_bot) { create(:user, :project_bot) }
let(:term) { create(:term) }
it 'is true when the user accepted the terms' do
accept_terms(term, user)
expect(term.accepted_by_user?(user)).to be(true)
end
it 'is true when user is a bot' do
expect(term.accepted_by_user?(project_bot)).to be(true)
end
it 'is false when the user declined the terms' do
decline_terms(term, user)
expect(term.accepted_by_user?(user)).to be(false)
end
it 'does not cause a query when the user accepted the current terms' do
accept_terms(term, user)
expect { term.accepted_by_user?(user) }.not_to exceed_query_limit(0)
end
it 'returns false if the currently accepted terms are different' do
accept_terms(create(:term), user)
expect(term.accepted_by_user?(user)).to be(false)
end
def accept_terms(term, user)
Users::RespondToTermsService.new(user, term).execute(accepted: true)
end
def decline_terms(term, user)
Users::RespondToTermsService.new(user, term).execute(accepted: false)
end
end
end
|