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
Léo-Paul Géneau
gitlab-ce
Commits
dce4a92b
Commit
dce4a92b
authored
Oct 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish refactoring specs.
The goal is to reflect separation of concern also in specs.
parent
e5e4c6b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
56 deletions
+15
-56
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+15
-56
No files found.
spec/lib/gitlab/database/count_spec.rb
View file @
dce4a92b
...
@@ -55,60 +55,6 @@ describe Gitlab::Database::Count do
...
@@ -55,60 +55,6 @@ describe Gitlab::Database::Count do
subject
subject
end
end
end
end
xcontext
'with PostgreSQL'
,
:postgresql
do
let
(
:reltuples_strategy
)
{
double
(
'reltuples_strategy'
,
count:
{})
}
let
(
:exact_strategy
)
{
double
(
'exact_strategy'
,
count:
{})
}
before
do
allow
(
Gitlab
::
Database
::
Count
::
ReltuplesCountStrategy
).
to
receive
(
:new
).
with
(
models
).
and_return
(
reltuples_strategy
)
end
describe
'when reltuples have not been updated'
do
it
'counts all models the normal way'
do
expect
(
Project
).
to
receive
(
:count
).
and_call_original
expect
(
Identity
).
to
receive
(
:count
).
and_call_original
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
describe
'no permission'
do
it
'falls back to standard query'
do
allow
(
ActiveRecord
::
Base
).
to
receive
(
:transaction
).
and_raise
(
PG
::
InsufficientPrivilege
)
expect
(
Project
).
to
receive
(
:count
).
and_call_original
expect
(
Identity
).
to
receive
(
:count
).
and_call_original
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
describe
'when some reltuples have been updated'
do
it
'counts projects in the fast way'
do
expect
(
reltuples_strategy
).
to
receive
(
:count
).
and_return
({
Project
=>
3
})
expect
(
Project
).
not_to
receive
(
:count
).
and_call_original
expect
(
Identity
).
to
receive
(
:count
).
and_call_original
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
# TODO: This covers two parts: reltuple strategy itself and the fallback
# TODO: Add spec that covers strategy details for reltuple strategy
describe
'when all reltuples have been updated'
do
#before do
#ActiveRecord::Base.connection.execute('ANALYZE projects')
#ActiveRecord::Base.connection.execute('ANALYZE identities')
#end
it
'counts models with the standard way'
do
allow
(
reltuples_strategy
).
to
receive
(
:count
).
and_return
({
Project
=>
3
,
Identity
=>
1
})
expect
(
Project
).
not_to
receive
(
:count
)
expect
(
Identity
).
not_to
receive
(
:count
)
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
end
end
end
describe
Gitlab
::
Database
::
Count
::
ExactCountStrategy
do
describe
Gitlab
::
Database
::
Count
::
ExactCountStrategy
do
...
@@ -141,10 +87,23 @@ describe Gitlab::Database::Count do
...
@@ -141,10 +87,23 @@ describe Gitlab::Database::Count do
subject
{
described_class
.
new
(
models
).
count
}
subject
{
described_class
.
new
(
models
).
count
}
describe
'#count'
do
describe
'#count'
do
context
'when reltuples is not up to date'
do
context
'when reltuples is up to date'
do
it
'returns an empty hash'
do
before
do
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE projects'
)
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE identities'
)
end
it
'uses statistics to do the count'
do
models
.
each
{
|
model
|
expect
(
model
).
not_to
receive
(
:count
)
}
models
.
each
{
|
model
|
expect
(
model
).
not_to
receive
(
:count
)
}
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
context
'insufficient permissions'
do
it
'returns an empty hash'
do
allow
(
ActiveRecord
::
Base
).
to
receive
(
:transaction
).
and_raise
(
PG
::
InsufficientPrivilege
)
expect
(
subject
).
to
eq
({})
expect
(
subject
).
to
eq
({})
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