1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'spec_helper'
describe ChatMessage::IssueMessage, models: true do
subject { described_class.new(args) }
let(:args) do
{
user: {
name: 'Test User',
username: 'test.user'
},
project_name: 'project_name',
project_url: 'http://somewhere.com',
object_attributes: {
title: 'Issue title',
id: 10,
iid: 100,
assignee_id: 1,
url: 'http://url.com',
action: 'open',
state: 'opened',
description: 'issue description'
}
}
end
let(:color) { '#C95823' }
context '#initialize' do
before do
args[:object_attributes][:description] = nil
end
it 'returns a non-null description' do
expect(subject.description).to eq('')
end
end
context 'open' do
it 'returns a message regarding opening of issues' do
expect(subject.pretext).to eq(
'[<http://somewhere.com|project_name>] Issue opened by test.user')
expect(subject.attachments).to eq([
{
title: "#100 Issue title",
title_link: "http://url.com",
text: "issue description",
color: color,
}
])
end
end
context 'close' do
before do
args[:object_attributes][:action] = 'close'
args[:object_attributes][:state] = 'closed'
end
it 'returns a message regarding closing of issues' do
expect(subject.pretext). to eq(
'[<http://somewhere.com|project_name>] Issue <http://url.com|#100 Issue title> closed by test.user')
expect(subject.attachments).to be_empty
end
end
end