From 804a2488cfd6704726c0dc7e6b0facc7e2ff7ce3 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 27 Feb 2015 10:47:37 +0100 Subject: [PATCH] Fix and test User#contributed_projects_ids. --- app/models/user.rb | 1 + spec/models/user_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 27ac93f4841..55768a351e3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -629,5 +629,6 @@ class User < ActiveRecord::Base reorder(project_id: :desc). select(:project_id). uniq + .map(&:project_id) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c015a1d2687..29d0c24e87e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -505,4 +505,32 @@ describe User do expect(User.sort(nil).first).to eq(@user) end end + + describe "#contributed_projects_ids" do + + subject { create(:user) } + let!(:project1) { create(:project) } + let!(:project2) { create(:project, forked_from_project: project3) } + let!(:project3) { create(:project) } + let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) } + let!(:push_event) { create(:event, action: Event::PUSHED, project: project1, target: project1, author: subject) } + let!(:merge_event) { create(:event, action: Event::CREATED, project: project3, target: merge_request, author: subject) } + + before do + project1.team << [subject, :master] + project2.team << [subject, :master] + end + + it "includes IDs for projects the user has pushed to" do + expect(subject.contributed_projects_ids).to include(project1.id) + end + + it "includes IDs for projects the user has had merge requests merged into" do + expect(subject.contributed_projects_ids).to include(project3.id) + end + + it "doesn't include IDs for unrelated projects" do + expect(subject.contributed_projects_ids).not_to include(project2.id) + end + end end