2014-10-13 00:07:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EventsHelper do
|
2016-10-17 06:07:44 -04:00
|
|
|
describe '#event_commit_title' do
|
2018-11-02 07:06:03 -04:00
|
|
|
let(:message) { 'foo & bar ' + 'A' * 70 + '\n' + 'B' * 80 }
|
2016-10-17 06:07:44 -04:00
|
|
|
subject { helper.event_commit_title(message) }
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns the first line, truncated to 70 chars' do
|
2016-10-17 06:07:44 -04:00
|
|
|
is_expected.to eq(message[0..66] + "...")
|
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'is not html-safe' do
|
2016-10-17 06:07:44 -04:00
|
|
|
is_expected.not_to be_a(ActiveSupport::SafeBuffer)
|
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'handles empty strings' do
|
2016-10-17 06:07:44 -04:00
|
|
|
expect(helper.event_commit_title("")).to eq("")
|
|
|
|
end
|
2017-08-21 11:27:06 -04:00
|
|
|
|
|
|
|
it 'handles nil values' do
|
|
|
|
expect(helper.event_commit_title(nil)).to eq('')
|
|
|
|
end
|
2018-02-15 06:06:57 -05:00
|
|
|
|
|
|
|
it 'does not escape HTML entities' do
|
2018-11-02 07:06:03 -04:00
|
|
|
expect(helper.event_commit_title('foo & bar')).to eq('foo & bar')
|
2018-02-15 06:06:57 -05:00
|
|
|
end
|
2016-10-17 06:07:44 -04:00
|
|
|
end
|
2018-09-05 07:29:04 -04:00
|
|
|
|
|
|
|
describe '#event_feed_url' do
|
|
|
|
let(:event) { create(:event) }
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
context 'issue' do
|
|
|
|
before do
|
|
|
|
event.target = create(:issue)
|
|
|
|
end
|
2018-09-05 07:29:04 -04:00
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns the project issue url' do
|
|
|
|
expect(helper.event_feed_url(event)).to eq(project_issue_url(event.project, event.target))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the project issue IID link' do
|
|
|
|
expect(helper.event_feed_title(event)).to include("##{event.target.iid}")
|
|
|
|
end
|
2018-09-05 07:29:04 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
context 'merge request' do
|
|
|
|
before do
|
|
|
|
event.target = create(:merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the project merge request url' do
|
|
|
|
expect(helper.event_feed_url(event)).to eq(project_merge_request_url(event.project, event.target))
|
|
|
|
end
|
2018-09-05 07:29:04 -04:00
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'contains the project merge request IID link' do
|
|
|
|
expect(helper.event_feed_title(event)).to include("!#{event.target.iid}")
|
|
|
|
end
|
2018-09-05 07:29:04 -04:00
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns project commit url' do
|
2018-09-05 07:29:04 -04:00
|
|
|
event.target = create(:note_on_commit, project: project)
|
|
|
|
|
|
|
|
expect(helper.event_feed_url(event)).to eq(project_commit_url(event.project, event.note_target))
|
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns event note target url' do
|
2018-09-05 07:29:04 -04:00
|
|
|
event.target = create(:note)
|
|
|
|
|
|
|
|
expect(helper.event_feed_url(event)).to eq(event_note_target_url(event))
|
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns project url' do
|
2018-09-05 07:29:04 -04:00
|
|
|
event.project = project
|
|
|
|
event.action = 1
|
|
|
|
|
|
|
|
expect(helper.event_feed_url(event)).to eq(project_url(event.project))
|
|
|
|
end
|
|
|
|
|
2018-11-02 07:06:03 -04:00
|
|
|
it 'returns push event feed url' do
|
2018-09-05 07:29:04 -04:00
|
|
|
event = create(:push_event)
|
|
|
|
create(:push_event_payload, event: event, action: :pushed)
|
|
|
|
|
|
|
|
expect(helper.event_feed_url(event)).to eq(push_event_feed_url(event))
|
|
|
|
end
|
|
|
|
end
|
2018-11-14 00:07:35 -05:00
|
|
|
|
|
|
|
describe '#event_note_target_url' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:event) { create(:event, project: project) }
|
|
|
|
let(:project_base_url) { namespace_project_url(namespace_id: project.namespace, id: project) }
|
|
|
|
|
|
|
|
subject { helper.event_note_target_url(event) }
|
|
|
|
|
|
|
|
it 'returns a commit note url' do
|
|
|
|
event.target = create(:note_on_commit, note: '+1 from me')
|
|
|
|
|
|
|
|
expect(subject).to eq("#{project_base_url}/commit/#{event.target.commit_id}#note_#{event.target.id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a project snippet note url' do
|
|
|
|
event.target = create(:note, :on_snippet, note: 'keep going')
|
|
|
|
|
|
|
|
expect(subject).to eq("#{project_base_url}/snippets/#{event.note_target.id}#note_#{event.target.id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a project issue url' do
|
|
|
|
event.target = create(:note_on_issue, note: 'nice work')
|
|
|
|
|
|
|
|
expect(subject).to eq("#{project_base_url}/issues/#{event.note_target.iid}#note_#{event.target.id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a merge request url' do
|
|
|
|
event.target = create(:note_on_merge_request, note: 'LGTM!')
|
|
|
|
|
|
|
|
expect(subject).to eq("#{project_base_url}/merge_requests/#{event.note_target.iid}#note_#{event.target.id}")
|
|
|
|
end
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
end
|