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
ab8ef17f
Commit
ab8ef17f
authored
Oct 17, 2016
by
Grzegorz Bizon
Committed by
Annabel Dunstone Gray
Oct 18, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend merge request tests for all commits method
parent
d5b1d0ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
20 deletions
+45
-20
app/models/merge_request.rb
app/models/merge_request.rb
+4
-3
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+41
-17
No files found.
app/models/merge_request.rb
View file @
ab8ef17f
...
@@ -788,8 +788,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -788,8 +788,8 @@ class MergeRequest < ActiveRecord::Base
return
unless
source_project
return
unless
source_project
@all_pipelines
||=
source_project
.
pipelines
@all_pipelines
||=
source_project
.
pipelines
.
where
(
sha:
all_commits_sha
,
ref:
source_branch
)
.
where
(
sha:
all_commits_sha
,
ref:
source_branch
)
.
order
(
id: :desc
)
.
order
(
id: :desc
)
end
end
# Note that this could also return SHA from now dangling commits
# Note that this could also return SHA from now dangling commits
...
@@ -798,7 +798,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -798,7 +798,8 @@ class MergeRequest < ActiveRecord::Base
if
persisted?
if
persisted?
merge_request_diffs
.
flat_map
(
&
:commits_sha
).
uniq
merge_request_diffs
.
flat_map
(
&
:commits_sha
).
uniq
else
else
compare_commits
.
reverse
.
map
(
&
:id
)
cached_commits
=
compare_commits
.
to_a
.
reverse
.
map
(
&
:id
)
cached_commits
.
any?
?
cached_commits
:
[
diff_head_sha
]
end
end
end
end
...
...
spec/models/merge_request_spec.rb
View file @
ab8ef17f
...
@@ -640,32 +640,56 @@ describe MergeRequest, models: true do
...
@@ -640,32 +640,56 @@ describe MergeRequest, models: true do
end
end
describe
'#all_commits_sha'
do
describe
'#all_commits_sha'
do
let
(
:all_commits_sha
)
do
context
'when merge request is persisted'
do
subject
.
merge_request_diffs
.
flat_map
(
&
:commits
).
map
(
&
:sha
).
uniq
let
(
:all_commits_sha
)
do
end
subject
.
merge_request_diffs
.
flat_map
(
&
:commits
).
map
(
&
:sha
).
uniq
end
shared_examples
'returning all SHA'
do
shared_examples
'returning all SHA'
do
it
'returns all SHA from all merge_request_diffs'
do
it
'returns all SHA from all merge_request_diffs'
do
expect
(
subject
.
merge_request_diffs
.
size
).
to
eq
(
2
)
expect
(
subject
.
merge_request_diffs
.
size
).
to
eq
(
2
)
expect
(
subject
.
all_commits_sha
).
to
eq
(
all_commits_sha
)
expect
(
subject
.
all_commits_sha
).
to
eq
(
all_commits_sha
)
end
end
end
end
context
'with a completely different branch'
do
context
'with a completely different branch'
do
before
do
before
do
subject
.
update
(
target_branch:
'v1.0.0'
)
subject
.
update
(
target_branch:
'v1.0.0'
)
end
it_behaves_like
'returning all SHA'
end
end
it_behaves_like
'returning all SHA'
context
'with a branch having no difference'
do
before
do
subject
.
update
(
target_branch:
'v1.1.0'
)
subject
.
reload
# make sure commits were not cached
end
it_behaves_like
'returning all SHA'
end
end
end
context
'with a branch having no difference'
do
context
'when merge request is not persisted'
do
before
do
context
'when compare commits are set in the service'
do
subject
.
update
(
target_branch:
'v1.1.0'
)
let
(
:commit
)
{
spy
(
'commit'
)
}
subject
.
reload
# make sure commits were not cached
subject
do
build
(
:merge_request
,
compare_commits:
[
commit
,
commit
])
end
it
'returns commits from compare commits temporary data'
do
expect
(
subject
.
all_commits_sha
).
to
eq
[
commit
,
commit
]
end
end
end
it_behaves_like
'returning all SHA'
context
'when compare commits are not set in the service'
do
subject
{
build
(
:merge_request
)
}
it
'returns array with diff head sha element only'
do
expect
(
subject
.
all_commits_sha
).
to
eq
[
subject
.
diff_head_sha
]
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