2016-11-16 06:09:09 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PreviewMarkdownService do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-11-16 06:09:09 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'user references' do
|
|
|
|
let(:params) { { text: "Take a look #{user.to_reference}" } }
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
|
|
|
it 'returns users referenced in text' do
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:users]).to eq [user.username]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
context 'new note with quick actions' do
|
2016-11-16 06:09:09 -05:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
text: "Please do it\n/assign #{user.to_reference}",
|
2017-05-31 01:50:53 -04:00
|
|
|
quick_actions_target_type: 'Issue',
|
|
|
|
quick_actions_target_id: issue.id
|
2016-11-16 06:09:09 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
it 'removes quick actions from text' do
|
2016-11-16 06:09:09 -05:00
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:text]).to eq 'Please do it'
|
|
|
|
end
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
it 'explains quick actions effect' do
|
2016-11-16 06:09:09 -05:00
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:commands]).to eq "Assigns #{user.to_reference}."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge request description' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
text: "My work\n/estimate 2y",
|
2017-05-31 01:50:53 -04:00
|
|
|
quick_actions_target_type: 'MergeRequest'
|
2016-11-16 06:09:09 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
it 'removes quick actions from text' do
|
2016-11-16 06:09:09 -05:00
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:text]).to eq 'My work'
|
|
|
|
end
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
it 'explains quick actions effect' do
|
2016-11-16 06:09:09 -05:00
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:commands]).to eq 'Sets time estimate to 2y.'
|
2017-05-31 01:50:53 -04:00
|
|
|
end
|
2016-11-16 06:09:09 -05:00
|
|
|
end
|
2018-07-06 14:49:33 -04:00
|
|
|
|
2018-07-28 17:43:21 -04:00
|
|
|
context 'commit description' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:commit) { project.commit }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
text: "My work\n/tag v1.2.3 Stable release",
|
|
|
|
quick_actions_target_type: 'Commit',
|
|
|
|
quick_actions_target_id: commit.id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
|
|
|
it 'removes quick actions from text' do
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:text]).to eq 'My work'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'explains quick actions effect' do
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:commands]).to eq 'Tags this commit to v1.2.3 with "Stable release".'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-06 14:49:33 -04:00
|
|
|
it 'sets correct markdown engine' do
|
|
|
|
service = described_class.new(project, user, { markdown_version: CacheMarkdownField::CACHE_REDCARPET_VERSION })
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:markdown_engine]).to eq :redcarpet
|
|
|
|
|
|
|
|
service = described_class.new(project, user, { markdown_version: CacheMarkdownField::CACHE_COMMONMARK_VERSION })
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:markdown_engine]).to eq :common_mark
|
|
|
|
end
|
2018-09-02 11:24:27 -04:00
|
|
|
|
|
|
|
it 'honors the legacy_render parameter' do
|
|
|
|
service = described_class.new(project, user, { legacy_render: '1' })
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:markdown_engine]).to eq :redcarpet
|
|
|
|
end
|
2016-11-16 06:09:09 -05:00
|
|
|
end
|