summaryrefslogtreecommitdiff
path: root/spec/models/lfs_file_lock_spec.rb
blob: 5afad6c184fb1f756e7dfa50babffdd43471e827 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe LfsFileLock do
  let_it_be(:lfs_file_lock, reload: true) { create(:lfs_file_lock) }

  subject { lfs_file_lock }

  it { is_expected.to belong_to(:project) }
  it { is_expected.to belong_to(:user) }

  it { is_expected.to validate_presence_of(:project_id) }
  it { is_expected.to validate_presence_of(:user_id) }
  it { is_expected.to validate_presence_of(:path) }

  describe '#can_be_unlocked_by?' do
    let(:developer) { create(:user) }
    let(:maintainer) { create(:user) }

    before do
      project = lfs_file_lock.project

      project.add_developer(developer)
      project.add_maintainer(maintainer)
    end

    context "when it's forced" do
      it 'can be unlocked by the author' do
        user = lfs_file_lock.user

        expect(lfs_file_lock.can_be_unlocked_by?(user, true)).to eq(true)
      end

      it 'can be unlocked by a maintainer' do
        expect(lfs_file_lock.can_be_unlocked_by?(maintainer, true)).to eq(true)
      end

      it "can't be unlocked by other user" do
        expect(lfs_file_lock.can_be_unlocked_by?(developer, true)).to eq(false)
      end
    end

    context "when it isn't forced" do
      it 'can be unlocked by the author' do
        user = lfs_file_lock.user

        expect(lfs_file_lock.can_be_unlocked_by?(user)).to eq(true)
      end

      it "can't be unlocked by a maintainer" do
        expect(lfs_file_lock.can_be_unlocked_by?(maintainer)).to eq(false)
      end

      it "can't be unlocked by other user" do
        expect(lfs_file_lock.can_be_unlocked_by?(developer)).to eq(false)
      end
    end
  end
end