summaryrefslogtreecommitdiff
path: root/spec/models/concerns/access_requestable_spec.rb
blob: 24eb3e8a1e685ac8753d46adcfa37fe4f43b74e4 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe AccessRequestable do
  describe 'Group' do
    describe '#request_access' do
      let(:group) { create(:group, :public) }
      let(:user) { create(:user) }

      it { expect(group.request_access(user)).to be_a(GroupMember) }
      it { expect(group.request_access(user).user).to eq(user) }
    end

    describe '#access_requested?' do
      let(:group) { create(:group, :public) }
      let(:user) { create(:user) }

      before do
        group.request_access(user)
      end

      it { expect(group.requesters.exists?(user_id: user)).to be_truthy }
    end
  end

  describe 'Project' do
    describe '#request_access' do
      let(:project) { create(:project, :public) }
      let(:user) { create(:user) }

      it { expect(project.request_access(user)).to be_a(ProjectMember) }
    end

    describe '#access_requested?' do
      let(:project) { create(:project, :public) }
      let(:user) { create(:user) }

      before do
        project.request_access(user)
      end

      it { expect(project.requesters.exists?(user_id: user)).to be_truthy }
    end
  end
end