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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
c8e7d1ed
Commit
c8e7d1ed
authored
Feb 17, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add issue move implementation to controller
parent
11f817b3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
15 deletions
+59
-15
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+5
-0
app/services/issues/move_service.rb
app/services/issues/move_service.rb
+25
-4
spec/services/issues/move_service_spec.rb
spec/services/issues/move_service_spec.rb
+28
-10
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+1
-1
No files found.
app/controllers/projects/issues_controller.rb
View file @
c8e7d1ed
...
@@ -88,6 +88,11 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -88,6 +88,11 @@ class Projects::IssuesController < Projects::ApplicationController
def
update
def
update
@issue
=
Issues
::
UpdateService
.
new
(
project
,
current_user
,
issue_params
).
execute
(
issue
)
@issue
=
Issues
::
UpdateService
.
new
(
project
,
current_user
,
issue_params
).
execute
(
issue
)
move_service
=
Issues
::
MoveService
.
new
(
project
,
current_user
,
params
.
require
(
:issue
).
permit!
,
@issue
)
if
move_service
.
move?
@issue
=
move_service
.
execute
end
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
js
format
.
js
...
...
app/services/issues/move_service.rb
View file @
c8e7d1ed
module
Issues
module
Issues
class
MoveService
<
Issues
::
BaseService
class
MoveService
<
Issues
::
BaseService
def
execute
(
issue_old
,
project_new
)
def
initialize
(
project
,
current_user
,
params
,
issue
)
@issue_old
=
issue_old
super
(
project
,
current_user
,
params
)
@issue_new
=
issue_old
.
dup
@project_new
=
project_new
@issue_old
=
issue
@issue_new
=
@issue_old
.
dup
@project_old
=
@project
@project_old
=
@project
if
params
[
'move_to_project_id'
]
@project_new
=
Project
.
find
(
params
[
'move_to_project_id'
])
end
end
def
execute
return
unless
move?
open_new_issue
open_new_issue
rewrite_notes
rewrite_notes
close_old_issue
close_old_issue
...
@@ -14,8 +23,20 @@ module Issues
...
@@ -14,8 +23,20 @@ module Issues
@issue_new
@issue_new
end
end
def
move?
return
false
unless
@project_new
return
false
unless
@issue_new
return
false
unless
can_move?
true
end
private
private
def
can_move?
true
end
def
open_new_issue
def
open_new_issue
@issue_new
.
project
=
@project_new
@issue_new
.
project
=
@project_new
@issue_new
.
save!
@issue_new
.
save!
...
...
spec/services/issues/move_service_spec.rb
View file @
c8e7d1ed
...
@@ -5,16 +5,22 @@ describe Issues::MoveService, services: true do
...
@@ -5,16 +5,22 @@ describe Issues::MoveService, services: true do
let
(
:issue
)
{
create
(
:issue
,
title:
'Some issue'
,
description:
'Some issue description'
)
}
let
(
:issue
)
{
create
(
:issue
,
title:
'Some issue'
,
description:
'Some issue description'
)
}
let
(
:current_project
)
{
issue
.
project
}
let
(
:current_project
)
{
issue
.
project
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:move_params
)
{
{
'move_to_project_id'
=>
new_project
.
id
}
}
let
(
:move_service
)
{
described_class
.
new
(
current_project
,
user
,
move_params
,
issue
)
}
before
do
before
do
current_project
.
team
<<
[
user
,
:master
]
current_project
.
team
<<
[
user
,
:master
]
end
end
describe
'#execute'
do
context
'issue movable'
do
let!
(
:new_issue
)
do
describe
'#move?'
do
described_class
.
new
(
current_project
,
user
).
execute
(
issue
,
new_project
)
subject
{
move_service
.
move?
}
it
{
is_expected
.
to
be_truthy
}
end
end
describe
'#execute'
do
let!
(
:new_issue
)
{
move_service
.
execute
}
it
'should create a new issue in a new project'
do
it
'should create a new issue in a new project'
do
expect
(
new_issue
.
project
).
to
eq
new_project
expect
(
new_issue
.
project
).
to
eq
new_project
end
end
...
@@ -27,4 +33,16 @@ describe Issues::MoveService, services: true do
...
@@ -27,4 +33,16 @@ describe Issues::MoveService, services: true do
expect
(
new_issue
.
notes
.
last
.
note
).
to
match
/^Moved from/
expect
(
new_issue
.
notes
.
last
.
note
).
to
match
/^Moved from/
end
end
end
end
end
context
'issue not movable'
do
context
'move not requested'
do
let
(
:move_params
)
{
{}
}
describe
'#move?'
do
subject
{
move_service
.
move?
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
end
end
spec/services/system_note_service_spec.rb
View file @
c8e7d1ed
...
@@ -486,7 +486,7 @@ describe SystemNoteService, services: true do
...
@@ -486,7 +486,7 @@ describe SystemNoteService, services: true do
end
end
context
'invalid direction'
do
context
'invalid direction'
do
let
(
:direction
)
{
:invalid
}
let
(
:direction
)
{
:invalid
}
it
'should raise error'
do
it
'should raise error'
do
expect
{
subject
}.
to
raise_error
StandardError
,
/Invalid direction/
expect
{
subject
}.
to
raise_error
StandardError
,
/Invalid direction/
...
...
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