diff options
Diffstat (limited to 'spec/lib/banzai/reference_parser')
4 files changed, 65 insertions, 11 deletions
diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index d31ccccd6c3..9e77137795a 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -63,7 +63,7 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do context 'when the link does not have a data-project attribute' do it 'returns the nodes' do - expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) + expect(subject.nodes_visible_to_user(user, [link])).to match_array([link]) end end end diff --git a/spec/lib/banzai/reference_parser/commit_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_parser_spec.rb index 31cece108bf..3569a1019f0 100644 --- a/spec/lib/banzai/reference_parser/commit_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_parser_spec.rb @@ -12,12 +12,30 @@ RSpec.describe Banzai::ReferenceParser::CommitParser do let(:link) { empty_html_link } describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + context 'when the link has a data-project attribute' do before do - link['data-commit'] = 123 + link['data-project'] = project.id.to_s end it_behaves_like "referenced feature visibility", "repository" + + it 'includes the link if can_read_reference? returns true' do + expect(subject).to receive(:can_read_reference?).with(user, project, link).and_return(true) + + expect(subject.nodes_visible_to_user(user, [link])).to contain_exactly(link) + end + + it 'excludes the link if can_read_reference? returns false' do + expect(subject).to receive(:can_read_reference?).with(user, project, link).and_return(false) + + expect(subject.nodes_visible_to_user(user, [link])).to be_empty + end + end + + context 'when the link does not have a data-project attribute' do + it 'returns the nodes' do + expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) + end end end @@ -129,7 +147,7 @@ RSpec.describe Banzai::ReferenceParser::CommitParser do end end - context 'when checking commits on another projects' do + context 'when checking commits on another projects', :request_store do let!(:control_links) do [commit_link] end @@ -141,7 +159,7 @@ RSpec.describe Banzai::ReferenceParser::CommitParser do def commit_link project = create(:project, :repository, :public) - Nokogiri::HTML.fragment(%Q{<a data-commit="#{project.commit.id}" data-project="#{project.id}"></a>}).children[0] + Nokogiri::HTML.fragment(%(<a data-commit="#{project.commit.id}" data-project="#{project.id}"></a>)).children[0] end it_behaves_like 'no project N+1 queries' diff --git a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb index 2f64aef4fb7..172347fc421 100644 --- a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb @@ -12,12 +12,30 @@ RSpec.describe Banzai::ReferenceParser::CommitRangeParser do let(:link) { empty_html_link } describe '#nodes_visible_to_user' do - context 'when the link has a data-issue attribute' do + context 'when the link has a data-project attribute' do before do - link['data-commit-range'] = '123..456' + link['data-project'] = project.id.to_s end it_behaves_like "referenced feature visibility", "repository" + + it 'includes the link if can_read_reference? returns true' do + expect(subject).to receive(:can_read_reference?).with(user, project, link).and_return(true) + + expect(subject.nodes_visible_to_user(user, [link])).to contain_exactly(link) + end + + it 'excludes the link if can_read_reference? returns false' do + expect(subject).to receive(:can_read_reference?).with(user, project, link).and_return(false) + + expect(subject.nodes_visible_to_user(user, [link])).to be_empty + end + end + + context 'when the link does not have a data-project attribute' do + it 'returns the nodes' do + expect(subject.nodes_visible_to_user(user, [link])).to match_array([link]) + end end end @@ -136,4 +154,22 @@ RSpec.describe Banzai::ReferenceParser::CommitRangeParser do end end end + + context 'when checking commits ranges on another projects', :request_store do + let!(:control_links) do + [commit_range_link] + end + + let!(:actual_links) do + control_links + [commit_range_link, commit_range_link] + end + + def commit_range_link + project = create(:project, :repository, :public) + + Nokogiri::HTML.fragment(%(<a data-commit-range="123...456" data-project="#{project.id}"></a>)).children[0] + end + + it_behaves_like 'no project N+1 queries' + end end diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb index 7de78710d34..c180a42c91e 100644 --- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb @@ -5,10 +5,10 @@ require 'spec_helper' RSpec.describe Banzai::ReferenceParser::IssueParser do include ReferenceParserHelpers - let_it_be(:group) { create(:group, :public) } - let_it_be(:project) { create(:project, :public, group: group) } - let_it_be(:user) { create(:user) } - let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:group) { create(:group, :public) } + let_it_be_with_reload(:project) { create(:project, :public, group: group) } + let_it_be(:user) { create(:user) } + let_it_be(:issue) { create(:issue, project: project) } let(:link) { empty_html_link } |