BigW Consortium Gitlab

Commit a2718eba by Rémy Coutable

Make user/author use project.creator in most factories

Signed-off-by: 's avatarRémy Coutable <remy@rymai.me>
parent 9c34c023
......@@ -23,7 +23,7 @@ FactoryBot.define do
end
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
trait :without_author do
......
......@@ -3,13 +3,14 @@ FactoryBot.define do
sha '97de212e80737a608d939f648d959671fb0a0142'
ref 'master'
tag false
user
user nil
project nil
deployable factory: :ci_build
environment factory: :environment
after(:build) do |deployment, evaluator|
deployment.project ||= deployment.environment.project
deployment.user ||= deployment.project.creator
unless deployment.project.repository_exists?
allow(deployment.project.repository).to receive(:create_ref)
......
FactoryBot.define do
factory :event do
project
author factory: :user
author(factory: :user) { project.creator }
action Event::JOINED
trait(:created) { action Event::CREATED }
......
FactoryBot.define do
factory :issue do
title { generate(:title) }
author
project
author { project.creator }
trait :confidential do
confidential true
......
FactoryBot.define do
factory :merge_request do
title { generate(:title) }
author
association :source_project, :repository, factory: :project
target_project { source_project }
author { source_project.creator }
# $ git log --pretty=oneline feature..master
# 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com
......
......@@ -6,7 +6,7 @@ FactoryBot.define do
factory :note do
project
note { generate(:title) }
author
author { project&.creator || create(:user) }
on_issue
factory :note_on_commit, traits: [:on_commit]
......
......@@ -3,7 +3,7 @@ FactoryBot.define do
skip_create
project
user factory: :user
user { project.creator }
initialize_with { new(project, user) }
end
end
FactoryBot.define do
factory :sent_notification do
project
recipient factory: :user
recipient { project.creator }
noteable { create(:issue, project: project) }
reply_key { SentNotification.reply_key }
end
......
......@@ -21,6 +21,7 @@ FactoryBot.define do
factory :project_snippet, parent: :snippet, class: :ProjectSnippet do
project
author { project.creator }
end
factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do
......
FactoryBot.define do
factory :subscription do
user
project
user { project.creator }
subscribable factory: :issue
end
end
......@@ -3,7 +3,7 @@
FactoryBot.define do
factory :timelog do
time_spent 3600
user
issue
user { issue.project.creator }
end
end
FactoryBot.define do
factory :todo do
project
author
user
author { project.creator }
user { project.creator }
target factory: :issue
action { Todo::ASSIGNED }
......
......@@ -44,36 +44,38 @@ feature 'Dashboard Merge Requests' do
context 'merge requests exist' 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
let!(:assigned_merge_request_from_fork) do
create(:merge_request,
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
let!(:authored_merge_request) do
create(:merge_request,
source_branch: 'markdown', author: current_user,
target_project: project, source_project: project
)
source_branch: 'markdown',
source_project: project,
author: current_user)
end
let!(:authored_merge_request_from_fork) do
create(:merge_request,
source_branch: 'feature_conflict',
author: current_user,
target_project: public_project, source_project: forked_project
)
target_project: public_project, source_project: forked_project)
end
let!(:other_merge_request) do
create(:merge_request,
source_branch: 'fix',
target_project: project, source_project: project
)
source_project: project,
author: create(:user))
end
before do
......
......@@ -3,7 +3,7 @@ require 'rails_helper'
describe 'Merge request > User awards emoji', :js do
let(:project) { create(:project, :public, :repository) }
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
before do
......
......@@ -5,7 +5,7 @@ describe Gitlab::SlashCommands::IssueSearch do
let!(:issue) { create(:issue, project: project, title: 'find me') }
let!(:confidential) { create(:issue, :confidential, project: project, title: 'mepmep find') }
let(:project) { create(:project) }
let(:user) { issue.author }
let(:user) { create(:user) }
let(:regex_match) { described_class.match("issue search find") }
subject 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
project = create(:project, :private)
issue = create(:issue, project: project)
issue = create(:issue, project: project, author: create(:user))
user = issue.author
expect(project.team.member?(issue.author)).to be false
......
......@@ -4,7 +4,7 @@ describe Issues::CloseService do
let(:user) { create(:user) }
let(:user2) { 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!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
......
......@@ -13,7 +13,8 @@ describe Issues::UpdateService, :mailer do
create(:issue, title: 'Old title',
description: "for #{user2.to_reference}",
assignee_ids: [user3.id],
project: project)
project: project,
author: create(:user))
end
before do
......
......@@ -4,7 +4,7 @@ describe MergeRequests::CloseService do
let(:user) { create(:user) }
let(:user2) { 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!(:todo) { create(:todo, :assigned, user: user, project: project, target: merge_request, author: user2) }
......
......@@ -7,7 +7,8 @@ describe MergeRequests::FfMergeService do
create(:merge_request,
source_branch: 'flatten-dir',
target_branch: 'improve/awesome',
assignee: user2)
assignee: user2,
author: create(:user))
end
let(:project) { merge_request.project }
......
......@@ -4,7 +4,7 @@ describe MergeRequests::ReopenService do
let(:user) { create(:user) }
let(:user2) { 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 }
before do
......
......@@ -12,7 +12,8 @@ describe MergeRequests::UpdateService, :mailer do
create(:merge_request, :simple, title: 'Old title',
description: "FYI #{user2.to_reference}",
assignee_id: user3.id,
source_project: project)
source_project: project,
author: create(:user))
end
before do
......
......@@ -458,7 +458,7 @@ describe NotificationService, :mailer do
context "merge request diff note" do
let(:project) { create(:project, :repository) }
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) }
before do
......@@ -469,11 +469,13 @@ describe NotificationService, :mailer do
describe '#new_note' 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
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)
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