BigW Consortium Gitlab

wiki_page_message_spec.rb 1.88 KB
Newer Older
1 2
require 'spec_helper'

3
describe ChatMessage::WikiPageMessage, models: true do
4
  subject { described_class.new(args) }
5 6 7 8 9

  let(:args) do
    {
      user: {
        name: 'Test User',
10
        username: 'test.user'
11 12
      },
      project_name: 'project_name',
13
      project_url: 'http://somewhere.com',
14 15
      object_attributes: {
        title: 'Wiki page title',
16
        url: 'http://url.com',
17 18 19 20 21
        content: 'Wiki page description'
      }
    }
  end

22 23 24 25
  describe '#pretext' do
    context 'when :action == "create"' do
      before { args[:object_attributes][:action] = 'create' }

26
      it 'returns a message that a new wiki page was created' do
Sebastian Klier committed
27
        expect(subject.pretext).to eq(
28
          'test.user created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
29 30 31 32 33 34 35
          '*Wiki page title*')
      end
    end

    context 'when :action == "update"' do
      before { args[:object_attributes][:action] = 'update' }

36
      it 'returns a message that a wiki page was updated' do
Sebastian Klier committed
37
        expect(subject.pretext).to eq(
38
          'test.user edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
39 40
          '*Wiki page title*')
      end
41 42 43
    end
  end

44
  describe '#attachments' do
45 46
    let(:color) { '#345' }

47 48 49
    context 'when :action == "create"' do
      before { args[:object_attributes][:action] = 'create' }

50
      it 'returns the attachment for a new wiki page' do
Sebastian Klier committed
51
        expect(subject.attachments).to eq([
52 53 54 55 56 57
          {
            text: "Wiki page description",
            color: color,
          }
        ])
      end
58
    end
59 60 61 62

    context 'when :action == "update"' do
      before { args[:object_attributes][:action] = 'update' }

63
      it 'returns the attachment for an updated wiki page' do
Sebastian Klier committed
64
        expect(subject.attachments).to eq([
65 66 67 68 69 70
          {
            text: "Wiki page description",
            color: color,
          }
        ])
      end
71 72 73
    end
  end
end