debian-mirror-gitlab/spec/models/project_services/chat_message/wiki_page_message_spec.rb

171 lines
4.6 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe ChatMessage::WikiPageMessage do
2017-08-17 22:00:37 +05:30
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 description'
}
}
end
context 'without markdown' do
describe '#pretext' do
context 'when :action == "create"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'create'
end
2017-08-17 22:00:37 +05:30
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
2018-03-17 18:26:18 +05:30
'Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
2017-08-17 22:00:37 +05:30
'*Wiki page title*')
end
end
context 'when :action == "update"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'update'
end
2017-08-17 22:00:37 +05:30
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
2018-03-17 18:26:18 +05:30
'Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
2017-08-17 22:00:37 +05:30
'*Wiki page title*')
end
end
end
describe '#attachments' do
let(:color) { '#345' }
context 'when :action == "create"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'create'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for a new wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page description",
2017-09-10 17:25:29 +05:30
color: color
2017-08-17 22:00:37 +05:30
}
])
end
end
context 'when :action == "update"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'update'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for an updated wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page description",
2017-09-10 17:25:29 +05:30
color: color
2017-08-17 22:00:37 +05:30
}
])
end
end
end
end
context 'with markdown' do
before do
args[:markdown] = true
end
describe '#pretext' do
context 'when :action == "create"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'create'
end
2017-08-17 22:00:37 +05:30
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
2018-03-17 18:26:18 +05:30
'Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
2017-08-17 22:00:37 +05:30
end
end
context 'when :action == "update"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'update'
end
2017-08-17 22:00:37 +05:30
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
2018-03-17 18:26:18 +05:30
'Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
2017-08-17 22:00:37 +05:30
end
end
end
describe '#attachments' do
context 'when :action == "create"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'create'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for a new wiki page' do
expect(subject.attachments).to eq('Wiki page description')
end
end
context 'when :action == "update"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'update'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for an updated wiki page' do
expect(subject.attachments).to eq('Wiki page description')
end
end
end
describe '#activity' do
context 'when :action == "create"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'create'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for a new wiki page' do
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Test User (test.user) created [wiki page](http://url.com)',
2017-08-17 22:00:37 +05:30
subtitle: 'in [project_name](http://somewhere.com)',
text: 'Wiki page title',
image: 'http://someavatar.com'
})
end
end
context 'when :action == "update"' do
2017-09-10 17:25:29 +05:30
before do
args[:object_attributes][:action] = 'update'
end
2017-08-17 22:00:37 +05:30
it 'returns the attachment for an updated wiki page' do
expect(subject.activity).to eq({
2018-03-17 18:26:18 +05:30
title: 'Test User (test.user) edited [wiki page](http://url.com)',
2017-08-17 22:00:37 +05:30
subtitle: 'in [project_name](http://somewhere.com)',
text: 'Wiki page title',
image: 'http://someavatar.com'
})
end
end
end
end
end