gitlab-org--gitlab-foss/spec/factories/merge_requests.rb
Yorick Peterse 6ef87a2083
Merge issuable "reopened" state into "opened"
Having two states that essentially mean the same thing is very much like
having a boolean "true" and boolean "mostly-true": it's rather silly.
This commit merges the "reopened" state into the "opened" state while
taking care of system notes still showing messages along the lines of
"Alice reopened this issue".

A big benefit from having only two states (opened and closed) is that
indexing and querying becomes simpler and more performant. For example,
to get all the opened queries we no longer have to query both states:

    SELECT *
    FROM issues
    WHERE project_id = 2
    AND state IN ('opened', 'reopened');

Instead we can query a single state directly, which can be much faster:

    SELECT *
    FROM issues
    WHERE project_id = 2
    AND state = 'opened';

Further, only having two states makes indexing easier as we will only
ever filter (and thus scan an index) using a single value. Partial
indexes could help but aren't supported on MySQL, complicating the
development process and not being helpful for MySQL.
2017-07-28 13:31:51 +02:00

91 lines
2.1 KiB
Ruby

FactoryGirl.define do
factory :merge_request do
title { generate(:title) }
author
association :source_project, :repository, factory: :project
target_project { source_project }
# $ git log --pretty=oneline feature..master
# 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com
# 570e7b2abdd848b95f2f578043fc23bd6f6fd24d Change some files
# 6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 More submodules
# d14d6c0abdd253381df51a723d58691b2ee1ab08 Remove ds_store files
# c1acaa58bbcbc3eafe538cb8274ba387047b69f8 Ignore DS files
#
# See also RepoHelpers.sample_compare
#
source_branch "master"
target_branch "feature"
merge_status "can_be_merged"
trait :with_diffs do
end
trait :without_diffs do
source_branch "improve/awesome"
target_branch "master"
end
trait :conflict do
source_branch "feature_conflict"
target_branch "feature"
end
trait :merged do
state :merged
end
trait :closed do
state :closed
end
trait :opened do
state :opened
end
trait :locked do
state :locked
end
trait :simple do
source_branch "feature"
target_branch "master"
end
trait :rebased do
source_branch "markdown"
target_branch "improve/awesome"
end
trait :diverged do
source_branch "feature"
target_branch "master"
end
trait :merge_when_pipeline_succeeds do
merge_when_pipeline_succeeds true
merge_user author
end
factory :merged_merge_request, traits: [:merged]
factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:opened]
factory :merge_request_with_diffs, traits: [:with_diffs]
factory :merge_request_with_diff_notes do
after(:create) do |mr|
create(:diff_note_on_merge_request, noteable: mr, project: mr.source_project)
end
end
factory :labeled_merge_request do
transient do
labels []
end
after(:create) do |merge_request, evaluator|
merge_request.update_attributes(labels: evaluator.labels)
end
end
end
end