diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-07-10 10:38:42 +0300 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-07-24 09:13:43 +0300 |
commit | 7bee7b848aab883a6869e1fd2fbb9e66182d2023 (patch) | |
tree | 286029930e7c9af9402a752a1dd6f2ab9c607776 /spec/lib/banzai/pipeline | |
parent | 2fa22a07296223c1239bfab94654487cca222097 (diff) |
Support both internal and external issue trackers
Diffstat (limited to 'spec/lib/banzai/pipeline')
-rw-r--r-- | spec/lib/banzai/pipeline/gfm_pipeline_spec.rb | 89 |
1 files changed, 75 insertions, 14 deletions
diff --git a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb index 1eb90dc1847..601ffbb5456 100644 --- a/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/gfm_pipeline_spec.rb @@ -4,26 +4,87 @@ describe Banzai::Pipeline::GfmPipeline do describe 'integration between parsing regular and external issue references' do let(:project) { create(:redmine_project, :public) } - it 'allows to use shorthand external reference syntax for Redmine' do - markdown = '#12' + context 'when internal issue tracker is enabled' do + context 'when shorthand pattern #ISSUE_ID is used' do + it 'links an internal issue if it exists' do + issue = create(:issue, project: project) + markdown = issue.to_reference(project, full: true) - result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first - expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + expect(link['href']).to eq( + Gitlab::Routing.url_helpers.project_issue_path(project, issue) + ) + end + + it 'does not link any issue if it does not exist on GitLab' do + markdown = '#12' + + result = described_class.call(markdown, project: project)[:output] + expect(result.css('a')).to be_empty + end + end + + it 'allows to use long external reference syntax for Redmine' do + markdown = 'API_32-12' + + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first + + expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + end + + it 'parses cross-project references to regular issues' do + other_project = create(:empty_project, :public) + issue = create(:issue, project: other_project) + markdown = issue.to_reference(project, full: true) + + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first + + expect(link['href']).to eq( + Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) + ) + end end - it 'parses cross-project references to regular issues' do - other_project = create(:empty_project, :public) - issue = create(:issue, project: other_project) - markdown = issue.to_reference(project, full: true) + context 'when internal issue tracker is disabled' do + before do + project.issues_enabled = false + project.save! + end + + it 'allows to use shorthand external reference syntax for Redmine' do + markdown = '#12' + + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first + + expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + end + + it 'allows to use long external reference syntax for Redmine' do + markdown = 'API_32-12' + + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first + + expect(link['href']).to eq 'http://redmine/projects/project_name_in_redmine/issues/12' + end + + it 'parses cross-project references to regular issues' do + other_project = create(:empty_project, :public) + issue = create(:issue, project: other_project) + markdown = issue.to_reference(project, full: true) - result = described_class.call(markdown, project: project)[:output] - link = result.css('a').first + result = described_class.call(markdown, project: project)[:output] + link = result.css('a').first - expect(link['href']).to eq( - Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) - ) + expect(link['href']).to eq( + Gitlab::Routing.url_helpers.project_issue_path(other_project, issue) + ) + end end end end |