BigW Consortium Gitlab

notes_helper_spec.rb 1.86 KB
Newer Older
1 2 3
require "spec_helper"

describe NotesHelper do
4 5 6 7 8 9
  let(:owner) { create(:owner) }
  let(:group) { create(:group) }
  let(:project) { create(:empty_project, namespace: group) }
  let(:master) { create(:user) }
  let(:reporter) { create(:user) }
  let(:guest) { create(:user) }
10

11 12 13 14
  let(:owner_note) { create(:note, author: owner, project: project) }
  let(:master_note) { create(:note, author: master, project: project) }
  let(:reporter_note) { create(:note, author: reporter, project: project) }
  let!(:notes) { [owner_note, master_note, reporter_note] }
15

16 17 18 19 20 21 22 23
  before do
    group.add_owner(owner)
    project.team << [master, :master]
    project.team << [reporter, :reporter]
    project.team << [guest, :guest]
  end

  describe "#notes_max_access_for_users" do
24
    it 'returns human access levels' do
25 26 27 28
      expect(helper.note_max_access_for_user(owner_note)).to eq('Owner')
      expect(helper.note_max_access_for_user(master_note)).to eq('Master')
      expect(helper.note_max_access_for_user(reporter_note)).to eq('Reporter')
    end
29 30 31 32 33 34 35 36 37

    it 'handles access in different projects' do
      second_project = create(:empty_project)
      second_project.team << [master, :reporter]
      other_note = create(:note, author: master, project: second_project)

      expect(helper.note_max_access_for_user(master_note)).to eq('Master')
      expect(helper.note_max_access_for_user(other_note)).to eq('Reporter')
    end
38
  end
39 40

  describe '#preload_max_access_for_authors' do
41
    before do
42
      # This method reads cache from RequestStore, so make sure it's clean.
43
      RequestStore.clear!
44 45
    end

46 47 48 49 50 51 52 53 54 55
    it 'loads multiple users' do
      expected_access = {
        owner.id => Gitlab::Access::OWNER,
        master.id => Gitlab::Access::MASTER,
        reporter.id => Gitlab::Access::REPORTER
      }

      expect(helper.preload_max_access_for_authors(notes, project)).to eq(expected_access)
    end
  end
56
end