2014-03-18 13:27:03 -04:00
|
|
|
require_relative '../../app/models/project_services/slack_message'
|
|
|
|
|
|
|
|
describe SlackMessage do
|
|
|
|
subject { SlackMessage.new(args) }
|
|
|
|
|
|
|
|
let(:args) {
|
|
|
|
{
|
|
|
|
after: 'after',
|
|
|
|
before: 'before',
|
|
|
|
project_name: 'project_name',
|
|
|
|
ref: 'refs/heads/master',
|
|
|
|
user_name: 'user_name',
|
|
|
|
project_url: 'url'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-06 05:57:48 -04:00
|
|
|
let(:color) { '#345' }
|
|
|
|
|
2014-03-18 13:27:03 -04:00
|
|
|
context 'push' do
|
|
|
|
before do
|
|
|
|
args[:commits] = [
|
2014-04-06 05:57:48 -04:00
|
|
|
{ message: 'message1', url: 'url1', id: 'abcdefghijkl', author: { name: 'author1' } },
|
|
|
|
{ message: 'message2', url: 'url2', id: '123456789012', author: { name: 'author2' } },
|
2014-03-18 13:27:03 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding pushes' do
|
2014-04-06 05:57:48 -04:00
|
|
|
subject.pretext.should ==
|
2014-03-18 13:27:03 -04:00
|
|
|
'user_name pushed to branch <url/commits/master|master> of ' <<
|
2014-04-06 05:57:48 -04:00
|
|
|
'<url|project_name> (<url/compare/before...after|Compare changes>)'
|
|
|
|
subject.attachments.should == [
|
|
|
|
{
|
|
|
|
text: "<url1|abcdefghi>: message1 - author1\n" <<
|
|
|
|
"<url2|123456789>: message2 - author2",
|
|
|
|
color: color,
|
|
|
|
}
|
|
|
|
]
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'new branch' do
|
|
|
|
before do
|
|
|
|
args[:before] = '000000'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding a new branch' do
|
2014-04-06 05:57:48 -04:00
|
|
|
subject.pretext.should ==
|
2014-03-18 13:27:03 -04:00
|
|
|
'user_name pushed new branch <url/commits/master|master> to ' <<
|
|
|
|
'<url|project_name>'
|
2014-04-06 05:57:48 -04:00
|
|
|
subject.attachments.should be_empty
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'removed branch' do
|
|
|
|
before do
|
|
|
|
args[:after] = '000000'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a message regarding a removed branch' do
|
2014-04-06 05:57:48 -04:00
|
|
|
subject.pretext.should ==
|
2014-03-18 13:27:03 -04:00
|
|
|
'user_name removed branch master from <url|project_name>'
|
2014-04-06 05:57:48 -04:00
|
|
|
subject.attachments.should be_empty
|
2014-03-18 13:27:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|