Welcome to mirror list, hosted at ThFree Co, Russian Federation.

target_spec.rb « audit « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c06cd117a9d69ebfc438d3cbd8146a1cb821a1b (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Audit::Target do
  let(:object) { double('object') } # rubocop:disable RSpec/VerifiedDoubles

  subject { described_class.new(object) }

  describe '#id' do
    it 'returns object id' do
      allow(object).to receive(:id).and_return(object_id)

      expect(subject.id).to eq(object_id)
    end
  end

  describe '#type' do
    it 'returns object class name' do
      allow(object).to receive_message_chain(:class, :name).and_return('User')

      expect(subject.type).to eq('User')
    end
  end

  describe '#details' do
    using RSpec::Parameterized::TableSyntax

    where(:name, :audit_details, :details) do
      'jackie' | 'wanderer' | 'jackie'
      'jackie' | nil        | 'jackie'
      nil      | 'wanderer' | 'wanderer'
      nil      | nil        | 'unknown'
    end

    before do
      allow(object).to receive(:name).and_return(name) if name
      allow(object).to receive(:audit_details).and_return(audit_details) if audit_details
    end

    with_them do
      it 'returns details' do
        expect(subject.details).to eq(details)
      end
    end
  end
end