diff options
author | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-07-29 18:04:42 +0300 |
---|---|---|
committer | micael.bergeron <micael.bergeron@solutionstlm.com> | 2017-09-06 16:00:57 +0300 |
commit | 966b1128d884a318dad4277e23368334fe67e836 (patch) | |
tree | c0007ce9697dfe0fe93b52e619e21e8341c35120 /spec/helpers | |
parent | 8fe1aa5dbbb41cdefffb7177d9eda44ac8652cc7 (diff) |
WIP: refactor the first-contributor to Issuable
this will remove the need make N queries (per-note) at the
cost of having to mark notes with an attribute
this opens up the possibility for other special roles for notes
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/notes_helper_spec.rb | 77 |
1 files changed, 6 insertions, 71 deletions
diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index 613d6d6a423..cd15e27b497 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -23,10 +23,10 @@ describe NotesHelper do end describe "#notes_max_access_for_users" do - it 'returns human access levels' do - 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') + it 'returns access levels' do + expect(helper.note_max_access_for_user(owner_note)).to eq(Gitlab::Access::OWNER) + expect(helper.note_max_access_for_user(master_note)).to eq(Gitlab::Access::MASTER) + expect(helper.note_max_access_for_user(reporter_note)).to eq(Gitlab::Access::REPORTER) end it 'handles access in different projects' do @@ -34,73 +34,8 @@ describe NotesHelper do 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 - end - - describe '#note_first_contribution_for_user?' do - let(:project) { create(:empty_project) } - let(:other_project) { create(:empty_project) } - - let(:contributor) { create(:user) } - let(:first_time_contributor) { create(:user) } - - # there should be a way to disable the lazy loading on these - let(:merged_mr) { create(:merge_request, :merged, author: contributor, target_project: project, source_project: project) } - let(:open_mr) { create(:merge_request, author: first_time_contributor, target_project: project, source_project: project) } - let(:merged_mr_other_project) { create(:merge_request, :merged, author: first_time_contributor, target_project: other_project, source_project: other_project) } - - context "notes for a merge request" do - let(:guest_merge_request) { create(:merge_request, author: guest, target_project: project, source_project: project) } - let(:contributor_note) { create(:note, noteable: merged_mr, author: contributor, project: merged_mr.project) } - let(:first_time_contributor_note) { create(:note, noteable: open_mr, author: first_time_contributor, project: open_mr.project) } - let(:first_time_contributor_note_other_project) { create(:note, noteable: merged_mr_other_project, author: first_time_contributor, project: merged_mr_other_project.project) } - let(:guest_note) { create(:note, noteable: guest_merge_request, author: first_time_contributor, project: project) } - - it "is true when you don't have any merged MR" do - expect(helper.note_first_contribution_for_user? contributor_note).to be false - expect(helper.note_first_contribution_for_user? first_time_contributor_note).to be true - end - - it "handle multiple projects separately" do - expect(helper.note_first_contribution_for_user? first_time_contributor_note).to be true - expect(helper.note_first_contribution_for_user? first_time_contributor_note_other_project).to be false - end - - it "should only apply to the noteable's author" do - expect(helper.note_first_contribution_for_user? guest_note).to be false - end - end - - context "notes for an issue" do - let(:guest_issue) { create(:issue, author: guest, project: project) } - let(:contributor_issue) { create(:issue, author: contributor, project: project) } - let(:first_time_contributor_issue) { create(:issue, author: first_time_contributor, project: project) } - let(:first_time_contributor_issue_other_project) { create(:issue, author: first_time_contributor, project: other_project) } - - let(:contributor_note) { create(:note, noteable: contributor_issue, author: contributor, project: project) } - let(:first_time_contributor_note) { create(:note, noteable: first_time_contributor_issue, author: first_time_contributor, project: project) } - let(:first_time_contributor_note_other_project) { create(:note, noteable: first_time_contributor_issue_other_project, author: first_time_contributor, project: other_project) } - let(:guest_note) { create(:note, noteable: guest_issue, author: first_time_contributor, project: project) } - - it "is true when you don't have any merged MR" do - expect(merged_mr).to be - expect(helper.note_first_contribution_for_user? contributor_note).to be false - expect(helper.note_first_contribution_for_user? first_time_contributor_note).to be true - end - - it "handle multiple projects separately" do - expect(merged_mr).to be - expect(merged_mr_other_project).to be - expect(helper.note_first_contribution_for_user? first_time_contributor_note).to be true - expect(helper.note_first_contribution_for_user? first_time_contributor_note_other_project).to be false - end - - it "should only apply to the noteable's author" do - expect(merged_mr).to be - expect(helper.note_first_contribution_for_user? guest_note).to be false - end + expect(helper.note_max_access_for_user(master_note)).to eq(Gitlab::Access::MASTER) + expect(helper.note_max_access_for_user(other_note)).to eq(Gitlab::Access::REPORTER) end end |