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/models/concerns/issuable_spec.rb | |
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/models/concerns/issuable_spec.rb')
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 37f6fd3a25b..9b83b8bfb7e 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -480,4 +480,77 @@ describe Issuable do end end end + + describe '#first_contribution?' do + let(:group) { create(:group) } + let(:project) { create(:empty_project, namespace: group) } + let(:other_project) { create(:empty_project) } + let(:owner) { create(:owner) } + let(:master) { create(:user) } + let(:reporter) { create(:user) } + let(:guest) { create(:user) } + + let(:contributor) { create(:user) } + let(:first_time_contributor) { create(:user) } + let!(:access_users) { [owner, master, reporter] } + + before do + group.add_owner(owner) + project.team << [master, :master] + project.team << [reporter, :reporter] + project.team << [guest, :guest] + project.team << [contributor, :guest] + project.team << [first_time_contributor, :guest] + end + + 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 "for merge requests" do + it "is false for MASTER" do + mr = create(:merge_request, author: master, target_project: project, source_project: project) + expect(mr.first_contribution?).to be_falsey + end + + it "is false for OWNER" do + mr = create(:merge_request, author: owner, target_project: project, source_project: project) + expect(mr.first_contribution?).to be_falsey + end + + it "is false for REPORTER" do + mr = create(:merge_request, author: reporter, target_project: project, source_project: project) + expect(mr.first_contribution?).to be_falsey + end + + it "is true when you don't have any merged MR" do + expect(open_mr.first_contribution?).to be_truthy + expect(merged_mr.first_contribution?).to be_falsey + end + + it "handle multiple projects separately" do + expect(open_mr.first_contribution?).to be_truthy + expect(merged_mr_other_project.first_contribution?).to be_falsey + end + end + + context "for issues" do + 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) } + + it "is true when you don't have any merged MR" do + expect(merged_mr).to be + expect(first_time_contributor_issue.first_contribution?).to be_truthy + expect(contributor_issue.first_contribution?).to be_falsey + end + + it "handle multiple projects separately" do + expect(merged_mr).to be + expect(merged_mr_other_project).to be + expect(first_time_contributor_issue.first_contribution?).to be_truthy + expect(first_time_contributor_issue_other_project.first_contribution?).to be_falsey + end + end + end end |