summaryrefslogtreecommitdiff
path: root/spec/services/members/standard_member_builder_spec.rb
blob: 16daff53d3103aed7aa02700d2e09fa150f27be6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Members::StandardMemberBuilder do
  let_it_be(:source) { create(:group) }
  let_it_be(:existing_member) { create(:group_member) }

  let(:existing_members) { { existing_member.user.id => existing_member } }

  describe '#execute' do
    it 'returns member from existing members hash' do
      expect(described_class.new(source, existing_member.user, existing_members).execute).to eq existing_member
    end

    it 'builds a new member' do
      user = create(:user)

      member = described_class.new(source, user, existing_members).execute

      expect(member).to be_new_record
      expect(member.user).to eq user
    end
  end
end