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
|
require 'spec_helper'
require 'ffaker'
describe Banzai::Filter::CommitTrailersFilter do
include FilterSpecHelper
include CommitTrailersSpecHelper
let(:secondary_email) { create(:email, :confirmed) }
let(:user) { create(:user) }
let(:trailer) { "#{FFaker::Lorem.word}-by:"}
let(:commit_message) { trailer_line(trailer, user.name, user.email) }
let(:commit_message_html) { commit_html(commit_message) }
context 'detects' do
let(:email) { FFaker::Internet.email }
it 'trailers in the form of *-by and replace users with links' do
doc = filter(commit_message_html)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
end
it 'trailers prefixed with whitespaces' do
message_html = commit_html("\n\r #{commit_message}")
doc = filter(message_html)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
end
it 'GitLab users via a secondary email' do
_, message_html = build_commit_message(
trailer: trailer,
name: secondary_email.user.name,
email: secondary_email.email
)
doc = filter(message_html)
expect_to_have_user_link_with_avatar(
doc,
user: secondary_email.user,
trailer: trailer,
email: secondary_email.email
)
end
it 'non GitLab users and replaces them with mailto links' do
_, message_html = build_commit_message(
trailer: trailer,
name: FFaker::Name.name,
email: email
)
doc = filter(message_html)
expect_to_have_mailto_link(doc, email: email, trailer: trailer)
end
it 'multiple trailers in the same message' do
different_trailer = "#{FFaker::Lorem.word}-by:"
message = commit_html %(
#{commit_message}
#{trailer_line(different_trailer, FFaker::Name.name, email)}
)
doc = filter(message)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
expect_to_have_mailto_link(doc, email: email, trailer: different_trailer)
end
context 'special names' do
where(:name) do
[
'John S. Doe',
'L33t H@x0r'
]
end
with_them do
it do
message, message_html = build_commit_message(
trailer: trailer,
name: name,
email: email
)
doc = filter(message_html)
expect_to_have_mailto_link(doc, email: email, trailer: trailer)
expect(doc.text).to match Regexp.escape(message)
end
end
end
end
context "ignores" do
it 'commit messages without trailers' do
exp = message = commit_html(FFaker::Lorem.sentence)
doc = filter(message)
expect(doc.to_html).to match Regexp.escape(exp)
end
it 'trailers that are inline the commit message body' do
message = commit_html %(
#{FFaker::Lorem.sentence} #{commit_message} #{FFaker::Lorem.sentence}
)
doc = filter(message)
expect(doc.css('a').size).to eq 0
end
end
context "structure" do
it 'preserves the commit trailer structure' do
doc = filter(commit_message_html)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
expect(doc.text).to match Regexp.escape(commit_message)
end
it 'preserves the original name used in the commit message' do
message, message_html = build_commit_message(
trailer: trailer,
name: FFaker::Name.name,
email: user.email
)
doc = filter(message_html)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
expect(doc.text).to match Regexp.escape(message)
end
it 'preserves the original email used in the commit message' do
message, message_html = build_commit_message(
trailer: trailer,
name: secondary_email.user.name,
email: secondary_email.email
)
doc = filter(message_html)
expect_to_have_user_link_with_avatar(
doc,
user: secondary_email.user,
trailer: trailer,
email: secondary_email.email
)
expect(doc.text).to match Regexp.escape(message)
end
it 'only replaces trailer lines not the full commit message' do
commit_body = FFaker::Lorem.paragraph
message = commit_html %(
#{commit_body}
#{commit_message}
)
doc = filter(message)
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
expect(doc.text).to include(commit_body)
end
end
end
|