diff options
author | Robert Speicher <robert@gitlab.com> | 2018-06-05 18:27:35 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-06-05 18:27:35 +0300 |
commit | ffe87460f0925f6e091352552ba52aecea5bf4a8 (patch) | |
tree | 85a146300722e66a25a9560804115bf81089da81 /spec/models | |
parent | 1fd2c6460d0d8ff3167fb742b41a4b010cc7ad8b (diff) | |
parent | 285ffb223896f2226531be2ba10933414194155c (diff) |
Merge branch '46585-gdpr-terms-acceptance' into 'master'
Resolve "Missing Accept button for terms of service"
Closes #46585
See merge request gitlab-org/gitlab-ce!19156
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/application_setting/term_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/term_agreement_spec.rb | 9 |
2 files changed, 46 insertions, 0 deletions
diff --git a/spec/models/application_setting/term_spec.rb b/spec/models/application_setting/term_spec.rb index 1eddf3c56ff..aa49594f4d1 100644 --- a/spec/models/application_setting/term_spec.rb +++ b/spec/models/application_setting/term_spec.rb @@ -12,4 +12,41 @@ describe ApplicationSetting::Term do expect(described_class.latest).to eq(terms) end end + + describe '#accepted_by_user?' do + let(:user) { create(:user) } + 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 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 diff --git a/spec/models/term_agreement_spec.rb b/spec/models/term_agreement_spec.rb index a59bf119692..950dfa09a6a 100644 --- a/spec/models/term_agreement_spec.rb +++ b/spec/models/term_agreement_spec.rb @@ -5,4 +5,13 @@ describe TermAgreement do it { is_expected.to validate_presence_of(:term) } it { is_expected.to validate_presence_of(:user) } end + + describe '.accepted' do + it 'only includes accepted terms' do + accepted = create(:term_agreement, :accepted) + create(:term_agreement, :declined) + + expect(described_class.accepted).to contain_exactly(accepted) + end + end end |