summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import/representation/to_hash_spec.rb
blob: 2770e5c539710d221d8f5015df51235eb324c79b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Representation::ToHash do
  describe '#to_hash' do
    let(:user) { double(:user, attributes: { login: 'alice' }) }

    let(:issue) do
      double(
        :issue,
        attributes: { user: user, assignees: [user], number: 42 }
      )
    end

    let(:issue_hash) { issue.to_hash }

    before do
      user.extend(described_class)
      issue.extend(described_class)
    end

    it 'converts an object to a Hash' do
      expect(issue_hash).to be_an_instance_of(Hash)
    end

    it 'converts nested objects to Hashes' do
      expect(issue_hash[:user]).to eq({ login: 'alice' })
    end

    it 'converts Array values to Hashes' do
      expect(issue_hash[:assignees]).to eq([{ login: 'alice' }])
    end

    it 'keeps values as-is if they do not respond to #to_hash' do
      expect(issue_hash[:number]).to eq(42)
    end
  end
end