2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-24 12:28:04 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ApplicationSetting::Term do
|
2018-04-24 12:28:04 -04:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:terms) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.latest' do
|
|
|
|
it 'finds the latest terms' do
|
|
|
|
terms = create(:term)
|
|
|
|
|
|
|
|
expect(described_class.latest).to eq(terms)
|
|
|
|
end
|
|
|
|
end
|
2018-05-25 19:17:57 -04:00
|
|
|
|
|
|
|
describe '#accepted_by_user?' do
|
|
|
|
let(:user) { create(:user) }
|
2020-10-01 02:09:59 -04:00
|
|
|
let(:project_bot) { create(:user, :project_bot) }
|
2018-05-25 19:17:57 -04:00
|
|
|
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
|
|
|
|
|
2020-10-01 02:09:59 -04:00
|
|
|
it 'is true when user is a bot' do
|
|
|
|
expect(term.accepted_by_user?(project_bot)).to be(true)
|
|
|
|
end
|
|
|
|
|
2018-05-25 19:17:57 -04:00
|
|
|
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
|
2018-04-24 12:28:04 -04:00
|
|
|
end
|