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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# frozen_string_literal: true
require 'spec_helper'
describe ChatMessage::WikiPageMessage do
subject { described_class.new(args) }
let(:args) do
{
user: {
name: 'Test User',
username: 'test.user',
avatar_url: 'http://someavatar.com'
},
project_name: 'project_name',
project_url: 'http://somewhere.com',
object_attributes: {
title: 'Wiki page title',
url: 'http://url.com',
content: 'Wiki page content',
message: 'Wiki page commit message'
}
}
end
context 'without markdown' do
describe '#pretext' do
context 'when :action == "create"' do
before do
args[:object_attributes][:action] = 'create'
end
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
'Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
'*Wiki page title*')
end
end
context 'when :action == "update"' do
before do
args[:object_attributes][:action] = 'update'
end
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
'Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
'*Wiki page title*')
end
end
end
describe '#attachments' do
let(:color) { '#345' }
context 'when :action == "create"' do
before do
args[:object_attributes][:action] = 'create'
end
it 'returns the commit message for a new wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page commit message",
color: color
}
])
end
end
context 'when :action == "update"' do
before do
args[:object_attributes][:action] = 'update'
end
it 'returns the commit message for an updated wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page commit message",
color: color
}
])
end
end
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
describe '#pretext' do
context 'when :action == "create"' do
before do
args[:object_attributes][:action] = 'create'
end
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
'Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
end
end
context 'when :action == "update"' do
before do
args[:object_attributes][:action] = 'update'
end
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
'Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
end
end
end
describe '#attachments' do
context 'when :action == "create"' do
before do
args[:object_attributes][:action] = 'create'
end
it 'returns the commit message for a new wiki page' do
expect(subject.attachments).to eq('Wiki page commit message')
end
end
context 'when :action == "update"' do
before do
args[:object_attributes][:action] = 'update'
end
it 'returns the commit message for an updated wiki page' do
expect(subject.attachments).to eq('Wiki page commit message')
end
end
end
describe '#activity' do
context 'when :action == "create"' do
before do
args[:object_attributes][:action] = 'create'
end
it 'returns the attachment for a new wiki page' do
expect(subject.activity).to eq({
title: 'Test User (test.user) created [wiki page](http://url.com)',
subtitle: 'in [project_name](http://somewhere.com)',
text: 'Wiki page title',
image: 'http://someavatar.com'
})
end
end
context 'when :action == "update"' do
before do
args[:object_attributes][:action] = 'update'
end
it 'returns the attachment for an updated wiki page' do
expect(subject.activity).to eq({
title: 'Test User (test.user) edited [wiki page](http://url.com)',
subtitle: 'in [project_name](http://somewhere.com)',
text: 'Wiki page title',
image: 'http://someavatar.com'
})
end
end
end
end
end
|