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
95b92ddc
Commit
95b92ddc
authored
Feb 27, 2020
by
Giorgenes Gelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for Package.sort_by_attribute
parent
a195c841
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
ee/spec/models/packages/package_spec.rb
ee/spec/models/packages/package_spec.rb
+55
-0
No files found.
ee/spec/models/packages/package_spec.rb
View file @
95b92ddc
...
...
@@ -13,6 +13,61 @@ RSpec.describe Packages::Package, type: :model do
it
{
is_expected
.
to
have_one
(
:maven_metadatum
).
inverse_of
(
:package
)
}
end
describe
'.sort_by_attribute'
do
let_it_be
(
:group
)
{
create
(
:group
,
:public
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
namespace:
group
,
name:
'project A'
)
}
let!
(
:package1
)
{
create
(
:npm_package
,
project:
project
,
version:
'3.1.0'
,
name:
"@
#{
project
.
root_namespace
.
path
}
/foo1"
)
}
let!
(
:package2
)
{
create
(
:nuget_package
,
project:
project
,
version:
'2.0.4'
)
}
let
(
:package3
)
{
create
(
:maven_package
,
project:
project
,
version:
'1.1.1'
,
name:
'zzz'
)
}
before
do
travel_to
(
1
.
day
.
ago
)
do
package3
end
end
RSpec
.
shared_examples
'package sorting by attribute'
do
|
order_by
|
subject
{
described_class
.
where
(
id:
packages
.
map
(
&
:id
)).
sort_by_attribute
(
"
#{
order_by
}
_
#{
sort
}
"
).
to_a
}
context
"sorting by
#{
order_by
}
"
do
context
'ascending order'
do
let
(
:sort
)
{
'asc'
}
it
{
is_expected
.
to
eq
packages
}
end
context
'descending order'
do
let
(
:sort
)
{
'desc'
}
it
{
is_expected
.
to
eq
packages
.
reverse
}
end
end
end
it_behaves_like
'package sorting by attribute'
,
'name'
do
let
(
:packages
)
{
[
package1
,
package2
,
package3
]
}
end
it_behaves_like
'package sorting by attribute'
,
'created_at'
do
let
(
:packages
)
{
[
package3
,
package1
,
package2
]
}
end
it_behaves_like
'package sorting by attribute'
,
'version'
do
let
(
:packages
)
{
[
package3
,
package2
,
package1
]
}
end
it_behaves_like
'package sorting by attribute'
,
'type'
do
let
(
:packages
)
{
[
package3
,
package1
,
package2
]
}
end
it_behaves_like
'package sorting by attribute'
,
'project_path'
do
let
(
:another_project
)
{
create
(
:project
,
:public
,
namespace:
group
,
name:
'project B'
)
}
let!
(
:package4
)
{
create
(
:npm_package
,
project:
another_project
,
version:
'3.1.0'
,
name:
"@
#{
project
.
root_namespace
.
path
}
/bar"
)
}
let
(
:packages
)
{
[
package1
,
package2
,
package3
,
package4
]
}
end
end
describe
'validations'
do
subject
{
create
(
:package
)
}
...
...
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