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
e5e4c6b7
Commit
e5e4c6b7
authored
Oct 28, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move things to their right scope in specs.
parent
72347448
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
44 deletions
+45
-44
spec/lib/gitlab/database/count_spec.rb
spec/lib/gitlab/database/count_spec.rb
+45
-44
No files found.
spec/lib/gitlab/database/count_spec.rb
View file @
e5e4c6b7
...
...
@@ -7,12 +7,6 @@ describe Gitlab::Database::Count do
end
let
(
:models
)
{
[
Project
,
Identity
]
}
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
context
'.approximate_counts'
do
context
'selecting strategies'
do
...
...
@@ -62,7 +56,14 @@ describe Gitlab::Database::Count do
end
end
context
'with PostgreSQL'
,
:postgresql
do
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
...
...
@@ -107,59 +108,59 @@ describe Gitlab::Database::Count do
expect
(
described_class
.
approximate_counts
(
models
)).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
end
end
describe
Gitlab
::
Database
::
Count
::
ExactCountStrategy
do
subject
{
described_class
.
new
(
models
).
count
}
describe
Gitlab
::
Database
::
Count
::
ExactCountStrategy
do
subject
{
described_class
.
new
(
models
).
count
}
describe
'#count'
do
it
'counts all models'
do
models
.
each
{
|
model
|
expect
(
model
).
to
receive
(
:count
).
and_call_original
}
describe
'#count'
do
it
'counts all models'
do
models
.
each
{
|
model
|
expect
(
model
).
to
receive
(
:count
).
and_call_original
}
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
expect
(
subject
).
to
eq
({
Project
=>
3
,
Identity
=>
1
})
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is enabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
it
'is enabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
end
expect
(
described_class
.
enabled?
).
to
be_truthy
end
end
end
describe
Gitlab
::
Database
::
Count
::
ReltuplesCountStrategy
do
subject
{
described_class
.
new
(
models
).
count
}
describe
Gitlab
::
Database
::
Count
::
ReltuplesCountStrategy
do
subject
{
described_class
.
new
(
models
).
count
}
describe
'#count'
do
context
'when reltuples is not up to date'
do
it
'returns an empty hash'
do
models
.
each
{
|
model
|
expect
(
model
).
not_to
receive
(
:count
)
}
describe
'#count'
do
context
'when reltuples is not up to date'
do
it
'returns an empty hash'
do
models
.
each
{
|
model
|
expect
(
model
).
not_to
receive
(
:count
)
}
expect
(
subject
).
to
eq
({})
end
end
expect
(
subject
).
to
eq
({})
end
end
end
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
describe
'.enabled?'
do
it
'is enabled for PostgreSQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enabled?
).
to
be_truthy
end
expect
(
described_class
.
enabled?
).
to
be_truthy
end
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
it
'is disabled for MySQL'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
enabled?
).
to
be_falsey
end
end
expect
(
described_class
.
enabled?
).
to
be_falsey
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