2016-06-28 22:14:11 +00:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe NotesHelper do
|
2016-07-20 04:52:31 +00:00
|
|
|
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) }
|
2016-06-28 22:14:11 +00:00
|
|
|
|
2016-07-20 04:52:31 +00:00
|
|
|
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] }
|
2016-06-29 13:11:42 +00:00
|
|
|
|
2016-07-20 04:52:31 +00:00
|
|
|
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
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'returns human access levels' do
|
2016-06-28 22:14:11 +00:00
|
|
|
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
|
2016-06-29 13:11:42 +00:00
|
|
|
|
|
|
|
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
|
2016-06-28 22:14:11 +00:00
|
|
|
end
|
2016-07-20 04:52:31 +00:00
|
|
|
|
|
|
|
describe '#preload_max_access_for_authors' do
|
2016-08-05 06:37:45 +00:00
|
|
|
before do
|
2016-08-12 07:11:16 +00:00
|
|
|
# #preload_max_access_for_authors would read cache from RequestStore,
|
|
|
|
# so we should make sure it's clean.
|
|
|
|
RequestStore.clear!
|
2016-08-05 06:37:45 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 04:52:31 +00:00
|
|
|
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
|
2016-06-28 22:14:11 +00:00
|
|
|
end
|