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
1ee101fc
Commit
1ee101fc
authored
Mar 25, 2019
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve CE/EE differences in MergeRequestPresenter spec
The rebase_path specs were duplicated in the same file.
parent
eaba1acc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
92 deletions
+52
-92
spec/presenters/merge_request_presenter_spec.rb
spec/presenters/merge_request_presenter_spec.rb
+52
-92
No files found.
spec/presenters/merge_request_presenter_spec.rb
View file @
1ee101fc
require
'spec_helper'
describe
MergeRequestPresenter
do
let
(
:resource
)
{
create
:merge_request
,
source_project:
project
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
'#ci_status'
do
...
...
@@ -416,45 +416,48 @@ describe MergeRequestPresenter do
end
end
describe
'#can_push_to_source_branch'
do
before
do
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
source_branch_exists
}
allow_any_instance_of
(
Gitlab
::
UserAccess
::
RequestCacheExtension
)
.
to
receive
(
:can_push_to_branch?
)
.
with
(
resource
.
source_branch
)
.
and_return
(
can_push_to_branch
)
end
describe
'#target_branch_path'
do
subject
do
described_class
.
new
(
resource
,
current_user:
user
).
can_push_to_source_branch?
described_class
.
new
(
resource
,
current_user:
user
).
target_branch_path
end
context
'when
source branch exists AND user can push to source branch
'
do
let
(
:source_branch_exists
)
{
true
}
let
(
:can_push_to_branch
)
{
true
}
context
'when
target branch exists
'
do
it
'returns path'
do
allow
(
resource
).
to
receive
(
:target_branch_exists?
)
{
true
}
it
'returns true'
do
is_expected
.
to
eq
(
true
)
is_expected
.
to
eq
(
"/
#{
resource
.
source_project
.
full_path
}
/branches/
#{
resource
.
target_branch
}
"
)
end
end
context
'when
source branch does not exists
'
do
let
(
:source_branch_exists
)
{
false
}
let
(
:can_push_to_branch
)
{
tru
e
}
context
'when
target branch does not exist
'
do
it
'returns nil'
do
allow
(
resource
).
to
receive
(
:target_branch_exists?
)
{
fals
e
}
it
'returns false'
do
is_expected
.
to
eq
(
false
)
is_expected
.
to
be_nil
end
end
end
context
'when user cannot push to source branch'
do
let
(
:source_branch_exists
)
{
true
}
let
(
:can_push_to_branch
)
{
false
}
describe
'#source_branch_with_namespace_link'
do
subject
do
described_class
.
new
(
resource
,
current_user:
user
).
source_branch_with_namespace_link
end
it
'returns false'
do
is_expected
.
to
eq
(
false
)
end
it
'returns link'
do
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
true
}
is_expected
.
to
eq
(
"<a href=
\"
/
#{
resource
.
source_project
.
full_path
}
/tree/
#{
resource
.
source_branch
}
\"
>
#{
resource
.
source_branch
}
</a>"
)
end
it
'escapes html, when source_branch does not exist'
do
xss_attempt
=
"<img src='x' onerror=alert('bad stuff') />"
allow
(
resource
).
to
receive
(
:source_branch
)
{
xss_attempt
}
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
false
}
is_expected
.
to
eq
(
ERB
::
Util
.
html_escape
(
xss_attempt
))
end
end
...
...
@@ -521,87 +524,44 @@ describe MergeRequestPresenter do
end
end
describe
'#source_branch_with_namespace_link'
do
subject
do
described_class
.
new
(
resource
,
current_user:
user
).
source_branch_with_namespace_link
end
it
'returns link'
do
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
true
}
is_expected
.
to
eq
(
"<a href=
\"
/
#{
resource
.
source_project
.
full_path
}
/tree/
#{
resource
.
source_branch
}
\"
>
#{
resource
.
source_branch
}
</a>"
)
end
it
'escapes html, when source_branch does not exist'
do
xss_attempt
=
"<img src='x' onerror=alert('bad stuff') />"
allow
(
resource
).
to
receive
(
:source_branch
)
{
xss_attempt
}
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
false
}
is_expected
.
to
eq
(
ERB
::
Util
.
html_escape
(
xss_attempt
))
end
end
describe
'#rebase_path'
do
describe
'#can_push_to_source_branch'
do
before
do
allow
(
resource
).
to
receive
(
:rebase_in_progress?
)
{
rebase_in_progress
}
allow
(
resource
).
to
receive
(
:should_be_rebased?
)
{
should_be_rebased
}
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
source_branch_exists
}
allow_any_instance_of
(
Gitlab
::
UserAccess
::
RequestCacheExtension
)
.
to
receive
(
:can_push_to_branch?
)
.
with
(
resource
.
source_branch
)
.
and_return
(
can_push_to_branch
)
.
with
(
resource
.
source_branch
)
.
and_return
(
can_push_to_branch
)
end
subject
do
described_class
.
new
(
resource
,
current_user:
user
).
rebase_path
described_class
.
new
(
resource
,
current_user:
user
).
can_push_to_source_branch?
end
context
'when
can rebase
'
do
let
(
:
rebase_in_progress
)
{
fals
e
}
context
'when
source branch exists AND user can push to source branch
'
do
let
(
:
source_branch_exists
)
{
tru
e
}
let
(
:can_push_to_branch
)
{
true
}
let
(
:should_be_rebased
)
{
true
}
before
do
allow
(
resource
).
to
receive
(
:source_branch_exists?
)
{
true
}
end
it
'returns path'
do
is_expected
.
to
eq
(
"/
#{
project
.
full_path
}
/merge_requests/
#{
resource
.
iid
}
/rebase"
)
it
'returns true'
do
is_expected
.
to
eq
(
true
)
end
end
context
'when cannot rebase'
do
context
'when rebase in progress'
do
let
(
:rebase_in_progress
)
{
true
}
let
(
:can_push_to_branch
)
{
true
}
let
(
:should_be_rebased
)
{
true
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
end
context
'when user cannot merge'
do
let
(
:rebase_in_progress
)
{
false
}
let
(
:can_push_to_branch
)
{
false
}
let
(
:should_be_rebased
)
{
true
}
context
'when source branch does not exists'
do
let
(
:source_branch_exists
)
{
false
}
let
(
:can_push_to_branch
)
{
true
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
it
'returns false'
do
is_expected
.
to
eq
(
false
)
end
end
context
'should not be rebased'
do
let
(
:rebase_in_progress
)
{
false
}
let
(
:can_push_to_branch
)
{
true
}
let
(
:should_be_rebased
)
{
false
}
context
'when user cannot push to source branch'
do
let
(
:source_branch_exists
)
{
true
}
let
(
:can_push_to_branch
)
{
false
}
it
'returns nil'
do
is_expected
.
to
be_nil
end
it
'returns false'
do
is_expected
.
to
eq
(
false
)
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