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
Jérome Perrin
gitlab-ce
Commits
34c146a1
Commit
34c146a1
authored
Sep 08, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add #can_reopen? and tests
parent
554baec9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
24 deletions
+48
-24
app/helpers/merge_requests_helper.rb
app/helpers/merge_requests_helper.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-3
app/views/projects/merge_requests/_discussion.html.haml
app/views/projects/merge_requests/_discussion.html.haml
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+45
-19
No files found.
app/helpers/merge_requests_helper.rb
View file @
34c146a1
...
@@ -98,7 +98,7 @@ module MergeRequestsHelper
...
@@ -98,7 +98,7 @@ module MergeRequestsHelper
end
end
def
merge_request_button_visibility
(
merge_request
,
closed
)
def
merge_request_button_visibility
(
merge_request
,
closed
)
return
'hidden'
if
merge_request
.
c
losed?
==
closed
||
(
merge_request
.
merged?
==
closed
&&
!
merge_request
.
closed?
)
||
merge_request
.
closed_without_fork
?
return
'hidden'
if
merge_request
.
c
an_reopen
?
end
end
def
merge_request_version_path
(
project
,
merge_request
,
merge_request_diff
,
start_sha
=
nil
)
def
merge_request_version_path
(
project
,
merge_request
,
merge_request_diff
,
start_sha
=
nil
)
...
...
app/models/merge_request.rb
View file @
34c146a1
...
@@ -328,10 +328,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -328,10 +328,8 @@ class MergeRequest < ActiveRecord::Base
end
end
def
can_reopen?
def
can_reopen?
return
false
if
closed_without_fork?
||
closed_without_source_project?
return
false
if
closed_without_fork?
||
closed_without_source_project?
||
merged?
return
true
if
closed?
return
true
if
closed?
# false
end
end
def
ensure_merge_request_diff
def
ensure_merge_request_diff
...
...
app/views/projects/merge_requests/_discussion.html.haml
View file @
34c146a1
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
-
if
can?
(
current_user
,
:update_merge_request
,
@merge_request
)
-
if
can?
(
current_user
,
:update_merge_request
,
@merge_request
)
-
if
@merge_request
.
open?
-
if
@merge_request
.
open?
=
link_to
'Close merge request'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :close
}),
method: :put
,
class:
"btn btn-nr btn-comment btn-close close-mr-link js-note-target-close"
,
title:
"Close merge request"
,
data:
{
original_text:
"Close merge request"
,
alternative_text:
"Comment & close merge request"
}
=
link_to
'Close merge request'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :close
}),
method: :put
,
class:
"btn btn-nr btn-comment btn-close close-mr-link js-note-target-close"
,
title:
"Close merge request"
,
data:
{
original_text:
"Close merge request"
,
alternative_text:
"Comment & close merge request"
}
-
unless
@merge_request
.
open?
||
@merge_request
.
closed_without_fork
?
-
if
@merge_request
.
can_reopen
?
=
link_to
'Reopen merge request'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :reopen
}),
method: :put
,
class:
"btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen"
,
title:
"Reopen merge request"
,
data:
{
original_text:
"Reopen merge request"
,
alternative_text:
"Comment & reopen merge request"
}
=
link_to
'Reopen merge request'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :reopen
}),
method: :put
,
class:
"btn btn-nr btn-comment btn-reopen reopen-mr-link js-note-target-reopen"
,
title:
"Reopen merge request"
,
data:
{
original_text:
"Reopen merge request"
,
alternative_text:
"Comment & reopen merge request"
}
%comment-and-resolve-btn
{
"inline-template"
=>
true
,
":discussion-id"
=>
""
}
%comment-and-resolve-btn
{
"inline-template"
=>
true
,
":discussion-id"
=>
""
}
%button
.btn.btn-nr.btn-default.append-right-10.js-comment-resolve-button
{
"v-if"
=>
"showButton"
,
type:
"submit"
,
data:
{
namespace_path:
"#{@merge_request.project.namespace.path}"
,
project_path:
"#{@merge_request.project.path}"
}
}
%button
.btn.btn-nr.btn-default.append-right-10.js-comment-resolve-button
{
"v-if"
=>
"showButton"
,
type:
"submit"
,
data:
{
namespace_path:
"#{@merge_request.project.namespace.path}"
,
project_path:
"#{@merge_request.project.path}"
}
}
...
...
spec/models/merge_request_spec.rb
View file @
34c146a1
...
@@ -1039,24 +1039,24 @@ describe MergeRequest, models: true do
...
@@ -1039,24 +1039,24 @@ describe MergeRequest, models: true do
end
end
end
end
describe
"#closed_without_source_project?"
do
describe
'#closed_without_source_project?'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:fork_project
)
{
create
(
:project
,
forked_from_project:
project
)
}
let
(
:fork_project
)
{
create
(
:project
,
forked_from_project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:destroy_project
)
{
Projects
::
DestroyService
.
new
(
fork_project
,
user
,
{})
}
let
(
:destroy_project
)
{
Projects
::
DestroyService
.
new
(
fork_project
,
user
,
{})
}
context
"when the merge request is closed"
do
context
'when the merge request is closed'
do
let
(
:closed_merge_request
)
do
let
(
:closed_merge_request
)
do
create
(
:closed_merge_request
,
create
(
:closed_merge_request
,
source_project:
fork_project
,
source_project:
fork_project
,
target_project:
project
)
target_project:
project
)
end
end
it
"returns false if the source project exist"
do
it
'returns false if the source project exists'
do
expect
(
closed_merge_request
.
closed_without_source_project?
).
to
be_falsey
expect
(
closed_merge_request
.
closed_without_source_project?
).
to
be_falsey
end
end
it
"returns true if the source project does not exist"
do
it
'returns true if the source project does not exist'
do
destroy_project
.
async_execute
destroy_project
.
async_execute
closed_merge_request
.
reload
closed_merge_request
.
reload
...
@@ -1064,29 +1064,55 @@ describe MergeRequest, models: true do
...
@@ -1064,29 +1064,55 @@ describe MergeRequest, models: true do
end
end
end
end
context
"when the merge request is open"
do
context
'when the merge request is open'
do
let
(
:open_merge_request
)
do
it
'returns false'
do
create
(
:merge_request
,
expect
(
subject
.
closed_without_source_project?
).
to
be_falsey
source_project:
fork_project
,
target_project:
project
)
end
it
"returns false"
do
expect
(
open_merge_request
.
closed_without_source_project?
).
to
be_falsey
end
end
end
end
end
end
describe
'#can_reopen?'
do
describe
'#can_reopen?'
do
it
"returns true"
do
context
'when the merge request is closed'
do
subject
.
close
it
'returns true'
do
binding
.
pry
subject
.
close
expect
(
subject
.
can_reopen?
).
to
be_truthy
expect
(
subject
.
can_reopen?
).
to
be_truthy
end
context
'forked project'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:fork_project
)
{
create
(
:project
,
forked_from_project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:merge_request
)
do
create
(
:closed_merge_request
,
source_project:
fork_project
,
target_project:
project
)
end
it
'returns false if unforked'
do
Projects
::
UnlinkForkService
.
new
(
fork_project
,
user
).
execute
expect
(
merge_request
.
reload
.
can_reopen?
).
to
be_falsey
end
it
'returns false if the source project is deleted'
do
Projects
::
DestroyService
.
new
(
fork_project
,
user
,
{}).
async_execute
expect
(
merge_request
.
reload
.
can_reopen?
).
to
be_falsey
end
it
'returnes false if the merge request is merged'
do
merge_request
.
update_attributes
(
state:
'merged'
)
expect
(
merge_request
.
reload
.
can_reopen?
).
to
be_falsey
end
end
end
end
it
"returns false"
do
context
'when merge request is opened'
do
expect
(
subject
.
can_reopen?
).
to
be_falsey
it
'returns false'
do
expect
(
subject
.
can_reopen?
).
to
be_falsey
end
end
end
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