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
iv
gitlab-ce
Commits
1aa82dc4
Commit
1aa82dc4
authored
Jan 20, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prioritize previewable over plain README files
parent
0f139331
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
4 deletions
+76
-4
app/models/tree.rb
app/models/tree.rb
+12
-4
spec/models/tree_spec.rb
spec/models/tree_spec.rb
+64
-0
No files found.
app/models/tree.rb
View file @
1aa82dc4
...
...
@@ -17,12 +17,20 @@ class Tree
def
readme
return
@readme
if
defined?
(
@readme
)
# Take the first previewable readme, or return nil if none is available or
# we can't preview any of them
readme_tree
=
blobs
.
find
do
|
blob
|
blob
.
readme?
&&
(
previewable?
(
blob
.
name
)
||
plain?
(
blob
.
name
))
available_readmes
=
blobs
.
select
(
&
:readme?
)
previewable_readmes
=
available_readmes
.
select
do
|
blob
|
previewable?
(
blob
.
name
)
end
plain_readmes
=
available_readmes
.
select
do
|
blob
|
plain?
(
blob
.
name
)
end
# Prioritize previewable over plain readmes
readme_tree
=
previewable_readmes
.
first
||
plain_readmes
.
first
# Return if we can't preview any of them
if
readme_tree
.
nil?
return
@readme
=
nil
end
...
...
spec/models/tree_spec.rb
0 → 100644
View file @
1aa82dc4
require
'spec_helper'
describe
Tree
,
models:
true
do
let
(
:repository
)
{
create
(
:project
).
repository
}
let
(
:sha
)
{
repository
.
root_ref
}
subject
{
described_class
.
new
(
repository
,
'54fcc214'
)
}
describe
'#readme'
do
class
FakeBlob
attr_reader
:name
def
initialize
(
name
)
@name
=
name
end
def
readme?
name
=~
/^readme/i
end
end
it
'returns nil when repository does not contains a README file'
do
files
=
[
FakeBlob
.
new
(
'file'
),
FakeBlob
.
new
(
'license'
),
FakeBlob
.
new
(
'copying'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
).
to
eq
nil
end
it
'returns nil when repository does not contains a previewable README file'
do
files
=
[
FakeBlob
.
new
(
'file'
),
FakeBlob
.
new
(
'README.pages'
),
FakeBlob
.
new
(
'README.png'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
).
to
eq
nil
end
it
'returns README when repository contains a previewable README file'
do
files
=
[
FakeBlob
.
new
(
'README.png'
),
FakeBlob
.
new
(
'README'
),
FakeBlob
.
new
(
'file'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
.
name
).
to
eq
'README'
end
it
'returns first previewable README when repository contains more than one'
do
files
=
[
FakeBlob
.
new
(
'file'
),
FakeBlob
.
new
(
'README.md'
),
FakeBlob
.
new
(
'README.asciidoc'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
.
name
).
to
eq
'README.md'
end
it
'returns first plain text README when repository contains more than one'
do
files
=
[
FakeBlob
.
new
(
'file'
),
FakeBlob
.
new
(
'README'
),
FakeBlob
.
new
(
'README.txt'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
.
name
).
to
eq
'README'
end
it
'prioritizes previewable README file over one in plain text'
do
files
=
[
FakeBlob
.
new
(
'file'
),
FakeBlob
.
new
(
'README'
),
FakeBlob
.
new
(
'README.md'
)]
expect
(
subject
).
to
receive
(
:blobs
).
and_return
(
files
)
expect
(
subject
.
readme
.
name
).
to
eq
'README.md'
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