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
f5f52da8
Commit
f5f52da8
authored
Jan 02, 2019
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for Releases::Source and Link models
Releases::Source and Releases::Link are covered by tests
parent
8a75453e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
3 deletions
+136
-3
app/models/release.rb
app/models/release.rb
+1
-1
app/models/releases/source.rb
app/models/releases/source.rb
+2
-2
spec/fixtures/api/schemas/release.json
spec/fixtures/api/schemas/release.json
+1
-0
spec/models/release_spec.rb
spec/models/release_spec.rb
+25
-0
spec/models/releases/link_spec.rb
spec/models/releases/link_spec.rb
+68
-0
spec/models/releases/source_spec.rb
spec/models/releases/source_spec.rb
+39
-0
No files found.
app/models/release.rb
View file @
f5f52da8
...
@@ -31,7 +31,7 @@ class Release < ActiveRecord::Base
...
@@ -31,7 +31,7 @@ class Release < ActiveRecord::Base
end
end
def
assets_count
def
assets_count
links
.
size
+
sources
.
size
links
&
.
size
.
to_i
+
sources
&
.
size
.
to_i
end
end
def
sources
def
sources
...
...
app/models/releases/source.rb
View file @
f5f52da8
...
@@ -21,13 +21,13 @@ module Releases
...
@@ -21,13 +21,13 @@ module Releases
Gitlab
::
Routing
Gitlab
::
Routing
.
url_helpers
.
url_helpers
.
project_archive_url
(
project
,
.
project_archive_url
(
project
,
id:
File
.
join
(
tag_name
,
archive_p
ath
),
id:
File
.
join
(
tag_name
,
archive_p
refix
),
format:
format
)
format:
format
)
end
end
private
private
def
archive_p
ath
def
archive_p
refix
"
#{
project
.
path
}
-
#{
tag_name
.
tr
(
'/'
,
'-'
)
}
"
"
#{
project
.
path
}
-
#{
tag_name
.
tr
(
'/'
,
'-'
)
}
"
end
end
end
end
...
...
spec/fixtures/api/schemas/release.json
View file @
f5f52da8
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
"links"
:
{
"links"
:
{
"type"
:
"array"
,
"type"
:
"array"
,
"items"
:
{
"items"
:
{
"id"
:
"integer"
,
"name"
:
"string"
,
"name"
:
"string"
,
"url"
:
"string"
,
"url"
:
"string"
,
"external"
:
"boolean"
"external"
:
"boolean"
...
...
spec/models/release_spec.rb
View file @
f5f52da8
...
@@ -10,10 +10,35 @@ RSpec.describe Release do
...
@@ -10,10 +10,35 @@ RSpec.describe Release do
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
belong_to
(
:author
).
class_name
(
'User'
)
}
it
{
is_expected
.
to
have_many
(
:links
).
class_name
(
'Releases::Link'
)
}
end
end
describe
'validation'
do
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:description
)
}
it
{
is_expected
.
to
validate_presence_of
(
:description
)
}
end
end
describe
'#assets_count'
do
subject
{
release
.
assets_count
}
it
'returns the number of sources'
do
is_expected
.
to
eq
(
Releases
::
Source
::
FORMATS
.
count
)
end
context
'when a links exists'
do
let!
(
:link
)
{
create
(
:release_link
,
release:
release
)
}
it
'counts the link as an asset'
do
is_expected
.
to
eq
(
1
+
Releases
::
Source
::
FORMATS
.
count
)
end
end
end
describe
'#sources'
do
subject
{
release
.
sources
}
it
'returns sources'
do
is_expected
.
to
all
(
be_a
(
Releases
::
Source
))
end
end
end
end
spec/models/releases/link_spec.rb
0 → 100644
View file @
f5f52da8
require
'rails_helper'
RSpec
.
describe
Releases
::
Link
do
let
(
:release
)
{
create
(
:release
,
project:
project
)
}
let
(
:project
)
{
create
(
:project
)
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:release
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
context
'when url is invalid'
do
let
(
:link
)
{
build
(
:release_link
,
url:
'hoge'
)
}
it
'will be invalid'
do
expect
(
link
).
to
be_invalid
end
end
context
'when duplicate name is added to a release'
do
let!
(
:link
)
{
create
(
:release_link
,
name:
'alpha'
,
release:
release
)
}
it
'raises an error'
do
expect
do
create
(
:release_link
,
name:
'alpha'
,
release:
release
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
end
end
describe
'.sorted'
do
subject
{
described_class
.
sorted
}
let!
(
:link_1
)
{
create
(
:release_link
,
name:
'alpha'
,
release:
release
,
created_at:
1
.
day
.
ago
)
}
let!
(
:link_2
)
{
create
(
:release_link
,
name:
'beta'
,
release:
release
,
created_at:
2
.
days
.
ago
)
}
it
'returns a list of links by created_at order'
do
is_expected
.
to
eq
([
link_1
,
link_2
])
end
end
describe
'#internal?'
do
subject
{
link
.
internal?
}
let
(
:link
)
{
build
(
:release_link
,
release:
release
,
url:
url
)
}
let
(
:url
)
{
"
#{
project
.
web_url
}
/-/jobs/140463678/artifacts/download"
}
it
{
is_expected
.
to
be_truthy
}
context
'when link does not include project web url'
do
let
(
:url
)
{
'https://google.com/-/jobs/140463678/artifacts/download'
}
it
{
is_expected
.
to
be_falsy
}
end
end
describe
'#external?'
do
subject
{
link
.
external?
}
let
(
:link
)
{
build
(
:release_link
,
release:
release
,
url:
url
)
}
let
(
:url
)
{
'https://google.com/-/jobs/140463678/artifacts/download'
}
it
{
is_expected
.
to
be_truthy
}
end
end
spec/models/releases/source_spec.rb
0 → 100644
View file @
f5f52da8
require
'rails_helper'
RSpec
.
describe
Releases
::
Source
do
set
(
:project
)
{
create
(
:project
,
:repository
,
name:
'finance-cal'
)
}
let
(
:tag_name
)
{
'v1.0'
}
describe
'.all'
do
subject
{
described_class
.
all
(
project
,
tag_name
)
}
it
'returns all formats of sources'
do
expect
(
subject
.
map
(
&
:format
))
.
to
match_array
(
described_class
::
FORMATS
)
end
end
describe
'#url'
do
subject
{
source
.
url
}
let
(
:source
)
do
described_class
.
new
(
project:
project
,
tag_name:
tag_name
,
format:
format
)
end
let
(
:format
)
{
'zip'
}
it
'returns zip archived source url'
do
is_expected
.
to
eq
(
"
#{
project
.
web_url
}
/-/archive/v1.0/finance-cal-v1.0.zip"
)
end
context
'when ref is directory structure'
do
let
(
:tag_name
)
{
'beta/v1.0'
}
it
'converts slash to dash'
do
is_expected
.
to
eq
(
"
#{
project
.
web_url
}
/-/archive/beta/v1.0/finance-cal-beta-v1.0.zip"
)
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