Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
15411bad
Commit
15411bad
authored
Apr 27, 2020
by
Patrick Derichs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix AttributesRewriter for ResourceMilestoneEvents without milestone
Update specs as well
parent
87d63f10
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
13 deletions
+66
-13
app/models/resource_milestone_event.rb
app/models/resource_milestone_event.rb
+4
-0
app/services/issuable/clone/attributes_rewriter.rb
app/services/issuable/clone/attributes_rewriter.rb
+23
-10
ee/spec/features/epics/issue_promotion_spec.rb
ee/spec/features/epics/issue_promotion_spec.rb
+19
-0
spec/models/resource_milestone_event_spec.rb
spec/models/resource_milestone_event_spec.rb
+17
-0
spec/services/issuable/clone/attributes_rewriter_spec.rb
spec/services/issuable/clone/attributes_rewriter_spec.rb
+3
-3
No files found.
app/models/resource_milestone_event.rb
View file @
15411bad
...
...
@@ -25,4 +25,8 @@ class ResourceMilestoneEvent < ResourceEvent
def
self
.
issuable_attrs
%i(issue merge_request)
.
freeze
end
def
milestone_title
milestone
&
.
title
end
end
app/services/issuable/clone/attributes_rewriter.rb
View file @
15411bad
...
...
@@ -67,21 +67,29 @@ module Issuable
end
def
copy_resource_milestone_events
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
return
unless
milestone_events_supported?
copy_events
(
ResourceMilestoneEvent
.
table_name
,
original_entity
.
resource_milestone_events
)
do
|
event
|
matching_destination_milestone
=
matching_milestone
(
event
.
milestone
.
title
)
if
event
.
remove?
event_attributes_with_milestone
(
event
,
nil
)
else
matching_destination_milestone
=
matching_milestone
(
event
.
milestone_title
)
event_attributes_with_milestone
(
event
,
matching_destination_milestone
)
if
matching_destination_milestone
.
present?
end
end
end
def
event_attributes_with_milestone
(
event
,
milestone
)
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
if
matching_destination_milestone
.
present?
event
.
attributes
.
except
(
'id'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
'milestone_id'
=>
matching_destination_milestone
.
id
,
'milestone_id'
=>
milestone
&
.
id
,
'action'
=>
ResourceMilestoneEvent
.
actions
[
event
.
action
],
'state'
=>
ResourceMilestoneEvent
.
states
[
event
.
state
])
end
end
end
def
copy_events
(
table_name
,
events_to_copy
)
events_to_copy
.
find_in_batches
do
|
batch
|
...
...
@@ -96,6 +104,11 @@ module Issuable
def
entity_key
new_entity
.
class
.
name
.
parameterize
(
'_'
).
foreign_key
end
def
milestone_events_supported?
original_entity
.
respond_to?
(
:resource_milestone_events
)
&&
new_entity
.
respond_to?
(
:resource_milestone_events
)
end
end
end
end
ee/spec/features/epics/issue_promotion_spec.rb
View file @
15411bad
...
...
@@ -71,6 +71,25 @@ describe 'Issue promotion', :js do
expect
(
epic
.
description
).
to
eq
(
issue
.
description
)
expect
(
epic
.
author
).
to
eq
(
user
)
end
# Spec for https://gitlab.com/gitlab-org/gitlab/-/issues/215549
context
'if there is a remove resource milestone event'
do
let!
(
:resource_milestone_event
)
{
create
(
:resource_milestone_event
,
issue:
issue
,
action:
'remove'
,
milestone_id:
nil
)
}
it
'promotes the issue'
do
add_note
(
'/promote'
)
wait_for_requests
epic
=
Epic
.
last
expect
(
page
).
to
have_content
'Promoted issue to an epic.'
expect
(
issue
.
reload
).
to
be_closed
expect
(
epic
.
title
).
to
eq
(
issue
.
title
)
expect
(
epic
.
description
).
to
eq
(
issue
.
description
)
expect
(
epic
.
author
).
to
eq
(
user
)
end
end
end
context
'when issue is confidential'
do
...
...
spec/models/resource_milestone_event_spec.rb
View file @
15411bad
...
...
@@ -78,4 +78,21 @@ describe ResourceMilestoneEvent, type: :model do
let
(
:query_method
)
{
:remove?
}
end
end
describe
'#milestone_title'
do
let
(
:milestone
)
{
create
(
:milestone
,
title:
'v2.3'
)
}
let
(
:event
)
{
create
(
:resource_milestone_event
,
milestone:
milestone
)
}
it
'returns the expected title'
do
expect
(
event
.
milestone_title
).
to
eq
(
'v2.3'
)
end
context
'when milestone is nil'
do
let
(
:event
)
{
create
(
:resource_milestone_event
,
milestone:
nil
)
}
it
'returns nil'
do
expect
(
event
.
milestone_title
).
to
be_nil
end
end
end
end
spec/services/issuable/clone/attributes_rewriter_spec.rb
View file @
15411bad
...
...
@@ -89,7 +89,7 @@ describe Issuable::Clone::AttributesRewriter do
create_event
(
milestone1_project1
)
create_event
(
milestone2_project1
)
create_event
(
milestone1_project1
,
'remove'
)
create_event
(
nil
,
'remove'
)
create_event
(
milestone3_project1
)
end
...
...
@@ -101,7 +101,7 @@ describe Issuable::Clone::AttributesRewriter do
expect_milestone_event
(
new_issue_milestone_events
.
first
,
milestone:
milestone1_project2
,
action:
'add'
,
state:
'opened'
)
expect_milestone_event
(
new_issue_milestone_events
.
second
,
milestone:
milestone2_project2
,
action:
'add'
,
state:
'opened'
)
expect_milestone_event
(
new_issue_milestone_events
.
third
,
milestone:
milestone1_project2
,
action:
'remove'
,
state:
'opened'
)
expect_milestone_event
(
new_issue_milestone_events
.
third
,
milestone:
nil
,
action:
'remove'
,
state:
'opened'
)
end
def
create_event
(
milestone
,
action
=
'add'
)
...
...
@@ -109,7 +109,7 @@ describe Issuable::Clone::AttributesRewriter do
end
def
expect_milestone_event
(
event
,
expected_attrs
)
expect
(
event
.
milestone_id
).
to
eq
(
expected_attrs
[
:milestone
].
id
)
expect
(
event
.
milestone_id
).
to
eq
(
expected_attrs
[
:milestone
]
&
.
id
)
expect
(
event
.
action
).
to
eq
(
expected_attrs
[
:action
])
expect
(
event
.
state
).
to
eq
(
expected_attrs
[
:state
])
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment