Commit a2718eba authored by Rémy Coutable's avatar Rémy Coutable

Make user/author use project.creator in most factories

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 9c34c023
...@@ -23,7 +23,7 @@ FactoryBot.define do ...@@ -23,7 +23,7 @@ FactoryBot.define do
end end
after(:build) do |commit, evaluator| after(:build) do |commit, evaluator|
allow(commit).to receive(:author).and_return(evaluator.author || build(:author)) allow(commit).to receive(:author).and_return(evaluator.author || build_stubbed(:author))
end end
trait :without_author do trait :without_author do
......
...@@ -3,13 +3,14 @@ FactoryBot.define do ...@@ -3,13 +3,14 @@ FactoryBot.define do
sha '97de212e80737a608d939f648d959671fb0a0142' sha '97de212e80737a608d939f648d959671fb0a0142'
ref 'master' ref 'master'
tag false tag false
user user nil
project nil project nil
deployable factory: :ci_build deployable factory: :ci_build
environment factory: :environment environment factory: :environment
after(:build) do |deployment, evaluator| after(:build) do |deployment, evaluator|
deployment.project ||= deployment.environment.project deployment.project ||= deployment.environment.project
deployment.user ||= deployment.project.creator
unless deployment.project.repository_exists? unless deployment.project.repository_exists?
allow(deployment.project.repository).to receive(:create_ref) allow(deployment.project.repository).to receive(:create_ref)
......
FactoryBot.define do FactoryBot.define do
factory :event do factory :event do
project project
author factory: :user author(factory: :user) { project.creator }
action Event::JOINED action Event::JOINED
trait(:created) { action Event::CREATED } trait(:created) { action Event::CREATED }
......
FactoryBot.define do FactoryBot.define do
factory :issue do factory :issue do
title { generate(:title) } title { generate(:title) }
author
project project
author { project.creator }
trait :confidential do trait :confidential do
confidential true confidential true
......
FactoryBot.define do FactoryBot.define do
factory :merge_request do factory :merge_request do
title { generate(:title) } title { generate(:title) }
author
association :source_project, :repository, factory: :project association :source_project, :repository, factory: :project
target_project { source_project } target_project { source_project }
author { source_project.creator }
# $ git log --pretty=oneline feature..master # $ git log --pretty=oneline feature..master
# 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com # 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com
......
...@@ -6,7 +6,7 @@ FactoryBot.define do ...@@ -6,7 +6,7 @@ FactoryBot.define do
factory :note do factory :note do
project project
note { generate(:title) } note { generate(:title) }
author author { project&.creator || create(:user) }
on_issue on_issue
factory :note_on_commit, traits: [:on_commit] factory :note_on_commit, traits: [:on_commit]
......
...@@ -3,7 +3,7 @@ FactoryBot.define do ...@@ -3,7 +3,7 @@ FactoryBot.define do
skip_create skip_create
project project
user factory: :user user { project.creator }
initialize_with { new(project, user) } initialize_with { new(project, user) }
end end
end end
FactoryBot.define do FactoryBot.define do
factory :sent_notification do factory :sent_notification do
project project
recipient factory: :user recipient { project.creator }
noteable { create(:issue, project: project) } noteable { create(:issue, project: project) }
reply_key { SentNotification.reply_key } reply_key { SentNotification.reply_key }
end end
......
...@@ -21,6 +21,7 @@ FactoryBot.define do ...@@ -21,6 +21,7 @@ FactoryBot.define do
factory :project_snippet, parent: :snippet, class: :ProjectSnippet do factory :project_snippet, parent: :snippet, class: :ProjectSnippet do
project project
author { project.creator }
end end
factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do
......
FactoryBot.define do FactoryBot.define do
factory :subscription do factory :subscription do
user
project project
user { project.creator }
subscribable factory: :issue subscribable factory: :issue
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FactoryBot.define do FactoryBot.define do
factory :timelog do factory :timelog do
time_spent 3600 time_spent 3600
user
issue issue
user { issue.project.creator }
end end
end end
FactoryBot.define do FactoryBot.define do
factory :todo do factory :todo do
project project
author author { project.creator }
user user { project.creator }
target factory: :issue target factory: :issue
action { Todo::ASSIGNED } action { Todo::ASSIGNED }
......
...@@ -44,36 +44,38 @@ feature 'Dashboard Merge Requests' do ...@@ -44,36 +44,38 @@ feature 'Dashboard Merge Requests' do
context 'merge requests exist' do context 'merge requests exist' do
let!(:assigned_merge_request) do let!(:assigned_merge_request) do
create(:merge_request, assignee: current_user, target_project: project, source_project: project) create(:merge_request,
assignee: current_user,
source_project: project,
author: create(:user))
end end
let!(:assigned_merge_request_from_fork) do let!(:assigned_merge_request_from_fork) do
create(:merge_request, create(:merge_request,
source_branch: 'markdown', assignee: current_user, source_branch: 'markdown', assignee: current_user,
target_project: public_project, source_project: forked_project target_project: public_project, source_project: forked_project,
) author: create(:user))
end end
let!(:authored_merge_request) do let!(:authored_merge_request) do
create(:merge_request, create(:merge_request,
source_branch: 'markdown', author: current_user, source_branch: 'markdown',
target_project: project, source_project: project source_project: project,
) author: current_user)
end end
let!(:authored_merge_request_from_fork) do let!(:authored_merge_request_from_fork) do
create(:merge_request, create(:merge_request,
source_branch: 'feature_conflict', source_branch: 'feature_conflict',
author: current_user, author: current_user,
target_project: public_project, source_project: forked_project target_project: public_project, source_project: forked_project)
)
end end
let!(:other_merge_request) do let!(:other_merge_request) do
create(:merge_request, create(:merge_request,
source_branch: 'fix', source_branch: 'fix',
target_project: project, source_project: project source_project: project,
) author: create(:user))
end end
before do before do
......
...@@ -3,7 +3,7 @@ require 'rails_helper' ...@@ -3,7 +3,7 @@ require 'rails_helper'
describe 'Merge request > User awards emoji', :js do describe 'Merge request > User awards emoji', :js do
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator } let(:user) { project.creator }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project, author: create(:user)) }
describe 'logged in' do describe 'logged in' do
before do before do
......
...@@ -5,7 +5,7 @@ describe Gitlab::SlashCommands::IssueSearch do ...@@ -5,7 +5,7 @@ describe Gitlab::SlashCommands::IssueSearch do
let!(:issue) { create(:issue, project: project, title: 'find me') } let!(:issue) { create(:issue, project: project, title: 'find me') }
let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') } let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { issue.author } let(:user) { create(:user) }
let(:regex_match) { described_class.match("issue search find") } let(:regex_match) { described_class.match("issue search find") }
subject do subject do
......
...@@ -92,7 +92,7 @@ describe ProjectPolicy do ...@@ -92,7 +92,7 @@ describe ProjectPolicy do
it 'does not include the read_issue permission when the issue author is not a member of the private project' do it 'does not include the read_issue permission when the issue author is not a member of the private project' do
project = create(:project, :private) project = create(:project, :private)
issue = create(:issue, project: project) issue = create(:issue, project: project, author: create(:user))
user = issue.author user = issue.author
expect(project.team.member?(issue.author)).to be false expect(project.team.member?(issue.author)).to be false
......
...@@ -4,7 +4,7 @@ describe Issues::CloseService do ...@@ -4,7 +4,7 @@ describe Issues::CloseService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:guest) { create(:user) } let(:guest) { create(:user) }
let(:issue) { create(:issue, assignees: [user2]) } let(:issue) { create(:issue, assignees: [user2], author: create(:user)) }
let(:project) { issue.project } let(:project) { issue.project }
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) } let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
......
...@@ -13,7 +13,8 @@ describe Issues::UpdateService, :mailer do ...@@ -13,7 +13,8 @@ describe Issues::UpdateService, :mailer do
create(:issue, title: 'Old title', create(:issue, title: 'Old title',
description: "for #{user2.to_reference}", description: "for #{user2.to_reference}",
assignee_ids: [user3.id], assignee_ids: [user3.id],
project: project) project: project,
author: create(:user))
end end
before do before do
......
...@@ -4,7 +4,7 @@ describe MergeRequests::CloseService do ...@@ -4,7 +4,7 @@ describe MergeRequests::CloseService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:guest) { create(:user) } let(:guest) { create(:user) }
let(:merge_request) { create(:merge_request, assignee: user2) } let(:merge_request) { create(:merge_request, assignee: user2, author: create(:user)) }
let(:project) { merge_request.project } let(:project) { merge_request.project }
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) } let!(:todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) }
......
...@@ -7,7 +7,8 @@ describe MergeRequests::FfMergeService do ...@@ -7,7 +7,8 @@ describe MergeRequests::FfMergeService do
create(:merge_request, create(:merge_request,
source_branch: 'flatten-dir', source_branch: 'flatten-dir',
target_branch: 'improve/awesome', target_branch: 'improve/awesome',
assignee: user2) assignee: user2,
author: create(:user))
end end
let(:project) { merge_request.project } let(:project) { merge_request.project }
......
...@@ -4,7 +4,7 @@ describe MergeRequests::ReopenService do ...@@ -4,7 +4,7 @@ describe MergeRequests::ReopenService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:guest) { create(:user) } let(:guest) { create(:user) }
let(:merge_request) { create(:merge_request, :closed, assignee: user2) } let(:merge_request) { create(:merge_request, :closed, assignee: user2, author: create(:user)) }
let(:project) { merge_request.project } let(:project) { merge_request.project }
before do before do
......
...@@ -12,7 +12,8 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -12,7 +12,8 @@ describe MergeRequests::UpdateService, :mailer do
create(:merge_request, :simple, title: 'Old title', create(:merge_request, :simple, title: 'Old title',
description: "FYI #{user2.to_reference}", description: "FYI #{user2.to_reference}",
assignee_id: user3.id, assignee_id: user3.id,
source_project: project) source_project: project,
author: create(:user))
end end
before do before do
......
...@@ -458,7 +458,7 @@ describe NotificationService, :mailer do ...@@ -458,7 +458,7 @@ describe NotificationService, :mailer do
context "merge request diff note" do context "merge request diff note" do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, source_project: project, assignee: user) } let(:merge_request) { create(:merge_request, source_project: project, assignee: user, author: create(:user)) }
let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) } let(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request) }
before do before do
...@@ -469,11 +469,13 @@ describe NotificationService, :mailer do ...@@ -469,11 +469,13 @@ describe NotificationService, :mailer do
describe '#new_note' do describe '#new_note' do
it "records sent notifications" do it "records sent notifications" do
# Ensure create SentNotification by noteable = merge_request 6 times, not noteable = note # 3 SentNotification are sent: the MR assignee and author, and the @u_watcher
expect(SentNotification).to receive(:record_note).with(note, any_args).exactly(3).times.and_call_original expect(SentNotification).to receive(:record_note).with(note, any_args).exactly(3).times.and_call_original
notification.new_note(note) notification.new_note(note)
expect(SentNotification.last(3).map(&:recipient).map(&:id))
.to contain_exactly(merge_request.assignee.id, merge_request.author.id, @u_watcher.id)
expect(SentNotification.last.in_reply_to_discussion_id).to eq(note.discussion_id) expect(SentNotification.last.in_reply_to_discussion_id).to eq(note.discussion_id)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment