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
8d793951
Commit
8d793951
authored
May 04, 2020
by
Patrick Derichs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ResourceStateEvent model
Also extended specs
parent
b4a35f5a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
117 additions
and
7 deletions
+117
-7
app/models/concerns/state_eventable.rb
app/models/concerns/state_eventable.rb
+9
-0
app/models/issue.rb
app/models/issue.rb
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+1
-0
app/models/resource_state_event.rb
app/models/resource_state_event.rb
+15
-0
app/services/issuable/clone/attributes_rewriter.rb
app/services/issuable/clone/attributes_rewriter.rb
+23
-7
ee/spec/models/issue_spec.rb
ee/spec/models/issue_spec.rb
+12
-0
spec/factories/resource_state_event.rb
spec/factories/resource_state_event.rb
+10
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+2
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+4
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+4
-0
spec/models/resource_state_event_spec.rb
spec/models/resource_state_event_spec.rb
+14
-0
spec/services/issuable/clone/attributes_rewriter_spec.rb
spec/services/issuable/clone/attributes_rewriter_spec.rb
+22
-0
No files found.
app/models/concerns/state_eventable.rb
0 → 100644
View file @
8d793951
# frozen_string_literal: true
module
StateEventable
extend
ActiveSupport
::
Concern
included
do
has_many
:resource_state_events
end
end
app/models/issue.rb
View file @
8d793951
...
...
@@ -17,6 +17,7 @@ class Issue < ApplicationRecord
include
IgnorableColumns
include
MilestoneEventable
include
WhereComposite
include
StateEventable
DueDateStruct
=
Struct
.
new
(
:title
,
:name
).
freeze
NoDueDate
=
DueDateStruct
.
new
(
'No Due Date'
,
'0'
).
freeze
...
...
app/models/merge_request.rb
View file @
8d793951
...
...
@@ -19,6 +19,7 @@ class MergeRequest < ApplicationRecord
include
ShaAttribute
include
IgnorableColumns
include
MilestoneEventable
include
StateEventable
sha_attribute
:squash_commit_sha
...
...
app/models/resource_state_event.rb
0 → 100644
View file @
8d793951
# frozen_string_literal: true
class
ResourceStateEvent
<
ResourceEvent
include
IssueResourceEvent
include
MergeRequestResourceEvent
validate
:exactly_one_issuable
# state is used for issue and merge request states.
enum
state:
Issue
.
available_states
.
merge
(
MergeRequest
.
available_states
).
merge
(
reopened:
5
)
def
self
.
issuable_attrs
%i(issue merge_request)
.
freeze
end
end
app/services/issuable/clone/attributes_rewriter.rb
View file @
8d793951
...
...
@@ -20,6 +20,7 @@ module Issuable
copy_resource_label_events
copy_resource_weight_events
copy_resource_milestone_events
copy_resource_state_events
end
private
...
...
@@ -47,8 +48,6 @@ module Issuable
end
def
copy_resource_label_events
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
copy_events
(
ResourceLabelEvent
.
table_name
,
original_entity
.
resource_label_events
)
do
|
event
|
event
.
attributes
.
except
(
'id'
,
'reference'
,
'reference_html'
)
...
...
@@ -80,9 +79,18 @@ module Issuable
end
end
def
event_attributes_with_milestone
(
event
,
milestone
)
entity_key
=
new_entity
.
class
.
name
.
underscore
.
foreign_key
def
copy_resource_state_events
return
unless
state_events_supported?
copy_events
(
ResourceStateEvent
.
table_name
,
original_entity
.
resource_state_events
)
do
|
event
|
event
.
attributes
.
except
(
'id'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
'state'
=>
ResourceStateEvent
.
states
[
event
.
state
])
end
end
def
event_attributes_with_milestone
(
event
,
milestone
)
event
.
attributes
.
except
(
'id'
)
.
merge
(
entity_key
=>
new_entity
.
id
,
...
...
@@ -102,12 +110,20 @@ module Issuable
end
def
entity_key
new_entity
.
class
.
name
.
parameterize
(
'_'
)
.
foreign_key
new_entity
.
class
.
name
.
underscore
.
foreign_key
end
def
milestone_events_supported?
original_entity
.
respond_to?
(
:resource_milestone_events
)
&&
new_entity
.
respond_to?
(
:resource_milestone_events
)
both_respond_to?
(
:resource_milestone_events
)
end
def
state_events_supported?
both_respond_to?
(
:resource_state_events
)
end
def
both_respond_to?
(
method
)
original_entity
.
respond_to?
(
method
)
&&
new_entity
.
respond_to?
(
method
)
end
end
end
...
...
ee/spec/models/issue_spec.rb
View file @
8d793951
...
...
@@ -7,6 +7,18 @@ describe Issue do
using
RSpec
::
Parameterized
::
TableSyntax
describe
'associations'
do
subject
{
build
(
:issue
)
}
it
{
is_expected
.
to
have_many
(
:resource_weight_events
)
}
end
describe
'modules'
do
subject
{
build
(
:issue
)
}
it
{
is_expected
.
to
include_module
(
EE
::
WeightEventable
)
}
end
context
'callbacks'
do
describe
'.after_create'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
...
...
spec/factories/resource_state_event.rb
0 → 100644
View file @
8d793951
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:resource_state_event
do
issue
{
merge_request
.
nil?
?
create
(
:issue
)
:
nil
}
merge_request
{
nil
}
state
{
:opened
}
user
{
issue
&
.
author
||
merge_request
&
.
author
||
create
(
:user
)
}
end
end
spec/lib/gitlab/import_export/all_models.yml
View file @
8d793951
...
...
@@ -11,6 +11,7 @@ issues:
-
resource_label_events
-
resource_weight_events
-
resource_milestone_events
-
resource_state_events
-
sent_notifications
-
sentry_issue
-
label_links
...
...
@@ -119,6 +120,7 @@ merge_requests:
-
notes
-
resource_label_events
-
resource_milestone_events
-
resource_state_events
-
label_links
-
labels
-
last_edited_by
...
...
spec/models/issue_spec.rb
View file @
8d793951
...
...
@@ -19,6 +19,8 @@ describe Issue do
it
{
is_expected
.
to
have_many
(
:design_versions
)
}
it
{
is_expected
.
to
have_one
(
:sentry_issue
)
}
it
{
is_expected
.
to
have_one
(
:alert_management_alert
)
}
it
{
is_expected
.
to
have_many
(
:resource_milestone_events
)
}
it
{
is_expected
.
to
have_many
(
:resource_state_events
)
}
describe
'versions.most_recent'
do
it
'returns the most recent version'
do
...
...
@@ -38,6 +40,8 @@ describe Issue do
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Sortable
)
}
it
{
is_expected
.
to
include_module
(
Taskable
)
}
it
{
is_expected
.
to
include_module
(
MilestoneEventable
)
}
it
{
is_expected
.
to
include_module
(
StateEventable
)
}
it_behaves_like
'AtomicInternalId'
do
let
(
:internal_id_attribute
)
{
:iid
}
...
...
spec/models/merge_request_spec.rb
View file @
8d793951
...
...
@@ -20,6 +20,8 @@ describe MergeRequest do
it
{
is_expected
.
to
have_many
(
:user_mentions
).
class_name
(
"MergeRequestUserMention"
)
}
it
{
is_expected
.
to
belong_to
(
:milestone
)
}
it
{
is_expected
.
to
belong_to
(
:sprint
)
}
it
{
is_expected
.
to
have_many
(
:resource_milestone_events
)
}
it
{
is_expected
.
to
have_many
(
:resource_state_events
)
}
context
'for forks'
do
let!
(
:project
)
{
create
(
:project
)
}
...
...
@@ -178,6 +180,8 @@ describe MergeRequest do
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Sortable
)
}
it
{
is_expected
.
to
include_module
(
Taskable
)
}
it
{
is_expected
.
to
include_module
(
MilestoneEventable
)
}
it
{
is_expected
.
to
include_module
(
StateEventable
)
}
it_behaves_like
'AtomicInternalId'
do
let
(
:internal_id_attribute
)
{
:iid
}
...
...
spec/models/resource_state_event_spec.rb
0 → 100644
View file @
8d793951
# frozen_string_literal: true
require
'spec_helper'
describe
ResourceStateEvent
,
type: :model
do
subject
{
build
(
:resource_state_event
,
issue:
issue
)
}
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it_behaves_like
'a resource event'
it_behaves_like
'a resource event for issues'
it_behaves_like
'a resource event for merge requests'
end
spec/services/issuable/clone/attributes_rewriter_spec.rb
View file @
8d793951
...
...
@@ -114,5 +114,27 @@ describe Issuable::Clone::AttributesRewriter do
expect
(
event
.
state
).
to
eq
(
expected_attrs
[
:state
])
end
end
context
'with existing state events'
do
let!
(
:event1
)
{
create
(
:resource_state_event
,
issue:
original_issue
,
state:
'opened'
)
}
let!
(
:event2
)
{
create
(
:resource_state_event
,
issue:
original_issue
,
state:
'closed'
)
}
let!
(
:event3
)
{
create
(
:resource_state_event
,
issue:
original_issue
,
state:
'reopened'
)
}
it
'copies existing state events as expected'
do
subject
.
execute
state_events
=
new_issue
.
reload
.
resource_state_events
expect
(
state_events
.
size
).
to
eq
(
3
)
expect_state_event
(
state_events
.
first
,
issue:
new_issue
,
state:
'opened'
)
expect_state_event
(
state_events
.
second
,
issue:
new_issue
,
state:
'closed'
)
expect_state_event
(
state_events
.
third
,
issue:
new_issue
,
state:
'reopened'
)
end
def
expect_state_event
(
event
,
expected_attrs
)
expect
(
event
.
issue_id
).
to
eq
(
expected_attrs
[
:issue
]
&
.
id
)
expect
(
event
.
state
).
to
eq
(
expected_attrs
[
:state
])
end
end
end
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