diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 15:07:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-17 15:07:33 +0300 |
commit | 6b75320f525f841454f1ab162d141d3610f2e77b (patch) | |
tree | 4971c27759e4fbc18b85e71800c3b9c12346317e /spec/lib/banzai | |
parent | 4226aca420920c1844e8eade4798a2dff188a6fc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/banzai')
3 files changed, 143 insertions, 0 deletions
diff --git a/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb new file mode 100644 index 00000000000..1be279375bd --- /dev/null +++ b/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Banzai::ReferenceParser::MentionedUserParser do + include ReferenceParserHelpers + + let(:group) { create(:group, :private) } + let(:user) { create(:user) } + let(:new_user) { create(:user) } + let(:project) { create(:project, group: group, creator: user) } + let(:link) { empty_html_link } + + subject { described_class.new(Banzai::RenderContext.new(project, new_user)) } + + describe '#gather_references' do + context 'when the link has a data-group attribute' do + context 'using an existing group ID' do + before do + link['data-group'] = project.group.id.to_s + group.add_developer(new_user) + end + + it 'returns empty list of users' do + expect(subject.gather_references([link])).to eq([]) + end + end + end + + context 'when the link has a data-project attribute' do + context 'using an existing project ID' do + before do + link['data-project'] = project.id.to_s + project.add_developer(new_user) + end + + it 'returns empty list of users' do + expect(subject.gather_references([link])).to eq([]) + end + end + end + + context 'when the link has a data-user attribute' do + it 'returns an Array of users' do + link['data-user'] = user.id.to_s + + expect(subject.referenced_by([link])).to eq([user]) + end + end + end +end diff --git a/spec/lib/banzai/reference_parser/mentioned_users_by_group_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_users_by_group_parser_spec.rb new file mode 100644 index 00000000000..99d607629eb --- /dev/null +++ b/spec/lib/banzai/reference_parser/mentioned_users_by_group_parser_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Banzai::ReferenceParser::MentionedUsersByGroupParser do + include ReferenceParserHelpers + + let(:group) { create(:group, :private) } + let(:user) { create(:user) } + let(:new_user) { create(:user) } + let(:project) { create(:project, group: group, creator: user) } + let(:link) { empty_html_link } + + subject { described_class.new(Banzai::RenderContext.new(project, new_user)) } + + describe '#gather_references' do + context 'when the link has a data-group attribute' do + context 'using an existing group ID where user does not have access' do + it 'returns empty array' do + link['data-group'] = project.group.id.to_s + + expect(subject.gather_references([link])).to eq([]) + end + end + + context 'using an existing group ID' do + before do + link['data-group'] = project.group.id.to_s + group.add_developer(new_user) + end + + it 'returns groups' do + expect(subject.gather_references([link])).to eq([group]) + end + end + + context 'using a non-existing group ID' do + it 'returns an empty Array' do + link['data-group'] = 'test-non-existing' + + expect(subject.gather_references([link])).to eq([]) + end + end + end + end +end diff --git a/spec/lib/banzai/reference_parser/mentioned_users_by_project_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_users_by_project_parser_spec.rb new file mode 100644 index 00000000000..155f2189d9e --- /dev/null +++ b/spec/lib/banzai/reference_parser/mentioned_users_by_project_parser_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Banzai::ReferenceParser::MentionedUsersByProjectParser do + include ReferenceParserHelpers + + let(:group) { create(:group, :private) } + let(:user) { create(:user) } + let(:new_user) { create(:user) } + let(:project) { create(:project, group: group, creator: user) } + let(:link) { empty_html_link } + + subject { described_class.new(Banzai::RenderContext.new(project, new_user)) } + + describe '#gather_references' do + context 'when the link has a data-project attribute' do + context 'using an existing project ID where user does not have access' do + it 'returns empty Array' do + link['data-project'] = project.id.to_s + + expect(subject.gather_references([link])).to eq([]) + end + end + + context 'using an existing project ID' do + before do + link['data-project'] = project.id.to_s + project.add_developer(new_user) + end + + it 'returns an Array of referenced projects' do + expect(subject.gather_references([link])).to eq([project]) + end + end + + context 'using a non-existing project ID' do + it 'returns an empty Array' do + link['data-project'] = 'inexisting-project-id' + + expect(subject.gather_references([link])).to eq([]) + end + end + end + end +end |