Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/banzai/reference_parser/commit_parser_spec.rb')
-rw-r--r--spec/lib/banzai/reference_parser/commit_parser_spec.rb26
1 files changed, 22 insertions, 4 deletions
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'