summaryrefslogtreecommitdiff
path: root/spec/serializers/project_serializer_spec.rb
blob: 4bf0657129f04c7193ecff527fc314fb5cbb4196 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProjectSerializer do
  let_it_be(:project) { create(:project) }
  let(:provider_url) { 'http://provider.com' }

  context 'when serializer option is :import' do
    subject do
      described_class.new.represent(project, serializer: :import, provider_url: provider_url)
    end

    before do
      allow(ProjectImportEntity).to receive(:represent)
    end

    it 'represents with ProjectImportEntity' do
      subject

      expect(ProjectImportEntity)
        .to have_received(:represent)
              .with(project, serializer: :import, provider_url: provider_url, request: an_instance_of(EntityRequest))
    end
  end

  context 'when serializer option is omitted' do
    subject do
      described_class.new.represent(project)
    end

    before do
      allow(ProjectEntity).to receive(:represent)
    end

    it 'represents with ProjectEntity' do
      subject

      expect(ProjectEntity)
        .to have_received(:represent)
              .with(project, request: an_instance_of(EntityRequest))
    end
  end
end