diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-26 15:12:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-26 15:12:11 +0300 |
commit | 0594381ba711725d7d676db202902dfcbe9ec4a0 (patch) | |
tree | 9922e6dcee0fae9c04539f3763a8b5314c1060c4 /spec/helpers | |
parent | e48c28ed86567f049865a590fdda4569a760ee1f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/terms_helper_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/helpers/terms_helper_spec.rb b/spec/helpers/terms_helper_spec.rb new file mode 100644 index 00000000000..9120aad4627 --- /dev/null +++ b/spec/helpers/terms_helper_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe TermsHelper do + let_it_be(:current_user) { build(:user) } + let_it_be(:terms) { build(:term) } + + before do + allow(helper).to receive(:current_user).and_return(current_user) + end + + describe '#terms_data' do + let_it_be(:redirect) { '%2F' } + let_it_be(:terms_markdown) { 'Lorem ipsum dolor sit amet' } + let_it_be(:accept_path) { '/-/users/terms/14/accept?redirect=%2F' } + let_it_be(:decline_path) { '/-/users/terms/14/decline?redirect=%2F' } + + subject(:result) { Gitlab::Json.parse(helper.terms_data(terms, redirect)) } + + it 'returns correct json' do + expect(helper).to receive(:markdown_field).with(terms, :terms).and_return(terms_markdown) + expect(helper).to receive(:can?).with(current_user, :accept_terms, terms).and_return(true) + expect(helper).to receive(:can?).with(current_user, :decline_terms, terms).and_return(true) + expect(helper).to receive(:accept_term_path).with(terms, { redirect: redirect }).and_return(accept_path) + expect(helper).to receive(:decline_term_path).with(terms, { redirect: redirect }).and_return(decline_path) + + expected = { + terms: terms_markdown, + permissions: { + can_accept: true, + can_decline: true + }, + paths: { + accept: accept_path, + decline: decline_path, + root: root_path + } + }.as_json + + expect(result).to eq(expected) + end + end +end |