Skip to content
代码片段 群组 项目
未验证 提交 212741ae 编辑于 作者: Marc Saleiko's avatar Marc Saleiko 提交者: GitLab
浏览文件

Merge branch...

Merge branch 'ms/custom-status/nm-relation-between-system-defined-lifecycle-and-status' into 'master' 

Allow has many association for status and lifecycle

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/183385



Merged-by: default avatarMarc Saleiko <msaleiko@gitlab.com>
Approved-by: default avatarAgnes Slota <aslota@gitlab.com>
Approved-by: default avatarAlexandru Croitor <acroitor@gitlab.com>
Reviewed-by: default avatarMarc Saleiko <msaleiko@gitlab.com>
Reviewed-by: default avatarAgnes Slota <aslota@gitlab.com>
Co-authored-by: default avatarMarc Saleiko <marc.saleiko@komadesign.de>
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -13,13 +13,21 @@ class Lifecycle ...@@ -13,13 +13,21 @@ class Lifecycle
{ {
id: 1, id: 1,
name: 'Default', name: 'Default',
work_item_base_types: [:issue, :task] work_item_base_types: [:issue, :task],
status_ids: [1, 2, 3, 4, 5],
default_open_status_id: 1,
default_closed_status_id: 3,
default_duplicate_status_id: 5
} }
].freeze ].freeze
attribute :id, :integer attribute :id, :integer
attribute :name, :string attribute :name, :string
attribute :work_item_base_types attribute :work_item_base_types
attribute :status_ids
attribute :default_open_status_id, :integer
attribute :default_closed_status_id, :integer
attribute :default_duplicate_status_id, :integer
class << self class << self
def of_work_item_base_type(base_type) def of_work_item_base_type(base_type)
...@@ -36,12 +44,24 @@ def work_item_types ...@@ -36,12 +44,24 @@ def work_item_types
end end
def statuses def statuses
Status.where(lifecycle_id: id) Status.where(id: status_ids)
end end
def find_available_status_by_name(name) def find_available_status_by_name(name)
statuses.find { |status| status.matches_name?(name) } statuses.find { |status| status.matches_name?(name) }
end end
def default_open_status
Status.find(default_open_status_id)
end
def default_closed_status
Status.find(default_closed_status_id)
end
def default_duplicate_status
Status.find(default_duplicate_status_id)
end
end end
end end
end end
......
...@@ -15,40 +15,32 @@ class Status ...@@ -15,40 +15,32 @@ class Status
id: 1, id: 1,
name: 'To do', name: 'To do',
color: '#737278', color: '#737278',
category: :to_do, category: :to_do
default_open: true,
lifecycle_id: 1
}, },
{ {
id: 2, id: 2,
name: 'In progress', name: 'In progress',
color: '#1f75cb', color: '#1f75cb',
category: :in_progress, category: :in_progress
lifecycle_id: 1
}, },
{ {
id: 3, id: 3,
name: 'Done', name: 'Done',
color: '#108548', color: '#108548',
category: :done, category: :done
default_closed: true,
lifecycle_id: 1
}, },
{ {
id: 4, id: 4,
name: "Won't do", name: "Won't do",
color: '#DD2B0E', color: '#DD2B0E',
category: :cancelled, category: :cancelled
lifecycle_id: 1
}, },
{ {
id: 5, id: 5,
name: 'Duplicate', name: 'Duplicate',
color: '#DD2B0E', color: '#DD2B0E',
category: :cancelled, category: :cancelled,
default_duplicated: true, position: 10
position: 10,
lifecycle_id: 1
} }
].freeze ].freeze
...@@ -56,11 +48,10 @@ class Status ...@@ -56,11 +48,10 @@ class Status
attribute :name, :string attribute :name, :string
attribute :color, :string attribute :color, :string
attribute :category attribute :category
# For custom statuses position will be on the join model between
# custom lifecycle and custom status to allow modification per lifecycle.
# We don't plan to change the position of the status for system defined lifecycles.
attribute :position, :integer, default: 0 attribute :position, :integer, default: 0
attribute :default_open, :boolean, default: false
attribute :default_closed, :boolean, default: false
attribute :default_duplicated, :boolean, default: false
attribute :lifecycle_id, :integer
def icon_name def icon_name
CATEGORY_ICONS[category] CATEGORY_ICONS[category]
......
...@@ -7,8 +7,14 @@ ...@@ -7,8 +7,14 @@
describe 'validations' do describe 'validations' do
it 'has the correct structure for each item' do it 'has the correct structure for each item' do
expected_attributes = [
:id, :name, :work_item_base_types, :status_ids,
:default_open_status_id, :default_closed_status_id,
:default_duplicate_status_id
]
described_class::ITEMS.each do |item| described_class::ITEMS.each do |item|
expect(item).to include(:id, :name, :work_item_base_types) expect(item).to include(*expected_attributes)
expect(item[:status_ids]).to be_an(Array)
expect(item[:work_item_base_types]).to be_an(Array) expect(item[:work_item_base_types]).to be_an(Array)
end end
end end
...@@ -44,10 +50,9 @@ ...@@ -44,10 +50,9 @@
let(:statuses) { lifecycle.statuses } let(:statuses) { lifecycle.statuses }
it 'returns statuses for the lifecycle' do it 'returns statuses for the lifecycle' do
# We could make this more explicit and check for concrete statuses
# but this would increase coupling.
expect(statuses).to be_an(Array) expect(statuses).to be_an(Array)
expect(statuses.first).to be_an(WorkItems::Statuses::SystemDefined::Status) expect(statuses.first).to be_an(WorkItems::Statuses::SystemDefined::Status)
expect(statuses.map(&:id)).to contain_exactly(1, 2, 3, 4, 5)
end end
end end
...@@ -62,6 +67,20 @@ ...@@ -62,6 +67,20 @@
end end
end end
describe 'default status methods' do
{
default_open_status: 1,
default_closed_status: 3,
default_duplicate_status: 5
}.each do |method_name, expected_id|
it "returns assigned status for ##{method_name}" do
status = lifecycle.public_send(method_name)
expect(status).to be_an(WorkItems::Statuses::SystemDefined::Status)
expect(status.id).to eq(expected_id)
end
end
end
it 'has the correct attributes' do it 'has the correct attributes' do
is_expected.to have_attributes( is_expected.to have_attributes(
id: 1, id: 1,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
describe 'validations' do describe 'validations' do
it 'has the correct minimal structure for each item' do it 'has the correct minimal structure for each item' do
expect(described_class::ITEMS).to all(include(:id, :name, :color, :category, :lifecycle_id)) expect(described_class::ITEMS).to all(include(:id, :name, :color, :category))
end end
it 'has unique names for all statuses' do it 'has unique names for all statuses' do
...@@ -46,19 +46,12 @@ ...@@ -46,19 +46,12 @@
name: 'To do', name: 'To do',
color: '#737278', color: '#737278',
category: :to_do, category: :to_do,
position: 0, position: 0
default_open: true,
lifecycle_id: 1
) )
end end
it 'has default values for some attributes' do it 'has default value for position' do
expect(described_class.new).to have_attributes( expect(described_class.new.position).to eq(0)
position: 0,
default_open: false,
default_closed: false,
default_duplicated: false
)
end end
describe 'included modules' do describe 'included modules' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册