gitlab-org--gitlab-foss/spec/models/project_services/chat_message/merge_message_spec.rb

108 lines
3.4 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe ChatMessage::MergeMessage do
2016-11-25 19:36:37 +00:00
subject { described_class.new(args) }
2015-06-22 20:00:54 +00:00
let(:args) do
{
user: {
name: 'Test User',
2017-04-04 15:10:21 +00:00
username: 'test.user',
avatar_url: 'http://someavatar.com'
},
project_name: 'project_name',
2016-12-19 12:34:03 +00:00
project_url: 'http://somewhere.com',
object_attributes: {
2017-04-04 15:10:21 +00:00
title: "Merge Request title\nSecond line",
id: 10,
iid: 100,
assignee_id: 1,
2016-12-19 12:34:03 +00:00
url: 'http://url.com',
state: 'opened',
2017-04-04 15:10:21 +00:00
description: 'merge request description',
source_branch: 'source_branch',
target_branch: 'target_branch'
}
}
2015-06-22 20:00:54 +00:00
end
# Integration point in EE
context 'when state is overridden' do
it 'respects the overridden state' do
allow(subject).to receive(:state_or_action_text) { 'devoured' }
aggregate_failures do
expect(subject.summary).not_to include('opened')
expect(subject.summary).to include('devoured')
activity_title = subject.activity[:title]
expect(activity_title).not_to include('opened')
expect(activity_title).to include('devoured')
end
end
end
2017-04-04 15:10:21 +00:00
context 'without markdown' do
let(:color) { '#345' }
2017-04-04 15:10:21 +00:00
context 'open' do
it 'returns a message regarding opening of merge requests' do
expect(subject.pretext).to eq(
'Test User (test.user) opened <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
2017-04-04 15:10:21 +00:00
expect(subject.attachments).to be_empty
end
end
context 'close' do
before do
args[:object_attributes][:state] = 'closed'
end
it 'returns a message regarding closing of merge requests' do
expect(subject.pretext).to eq(
'Test User (test.user) closed <http://somewhere.com/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
2017-04-04 15:10:21 +00:00
expect(subject.attachments).to be_empty
end
end
end
2017-04-04 15:10:21 +00:00
context 'with markdown' do
before do
2017-04-04 15:10:21 +00:00
args[:markdown] = true
end
context 'open' do
it 'returns a message regarding opening of merge requests' do
expect(subject.pretext).to eq(
'Test User (test.user) opened [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)')
2017-04-04 15:10:21 +00:00
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
title: 'Merge Request opened by Test User (test.user)',
2017-04-04 15:10:21 +00:00
subtitle: 'in [project_name](http://somewhere.com)',
text: '[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)',
image: 'http://someavatar.com'
})
end
end
2017-04-04 15:10:21 +00:00
context 'close' do
before do
args[:object_attributes][:state] = 'closed'
end
it 'returns a message regarding closing of merge requests' do
expect(subject.pretext).to eq(
'Test User (test.user) closed [!100 *Merge Request title*](http://somewhere.com/merge_requests/100) in [project_name](http://somewhere.com)')
2017-04-04 15:10:21 +00:00
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
title: 'Merge Request closed by Test User (test.user)',
2017-04-04 15:10:21 +00:00
subtitle: 'in [project_name](http://somewhere.com)',
text: '[!100 *Merge Request title*](http://somewhere.com/merge_requests/100)',
image: 'http://someavatar.com'
})
end
end
end
end