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
68b7f99f
Commit
68b7f99f
authored
Feb 26, 2019
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce differences in spec/support/db_cleaner.rb
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
12e2c3aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
45 deletions
+61
-45
spec/support/database_cleaner.rb
spec/support/database_cleaner.rb
+56
-0
spec/support/db_cleaner.rb
spec/support/db_cleaner.rb
+5
-45
No files found.
spec/support/database_cleaner.rb
0 → 100644
View file @
68b7f99f
# frozen_string_literal: true
require
'database_cleaner/active_record/deletion'
require_relative
'db_cleaner'
module
FakeInformationSchema
# Work around a bug in DatabaseCleaner when using the deletion strategy:
# https://github.com/DatabaseCleaner/database_cleaner/issues/347
#
# On MySQL, if the information schema is said to exist, we use an inaccurate
# row count leading to some tables not being cleaned when they should
def
information_schema_exists?
(
_connection
)
false
end
end
DatabaseCleaner
::
ActiveRecord
::
Deletion
.
prepend
(
FakeInformationSchema
)
RSpec
.
configure
do
|
config
|
include
DbCleaner
# Ensure all sequences are reset at the start of the suite run
config
.
before
(
:suite
)
do
setup_database_cleaner
DatabaseCleaner
.
clean_with
(
:truncation
)
end
config
.
append_after
(
:context
)
do
DatabaseCleaner
.
clean_with
(
:deletion
,
cache_tables:
false
)
end
config
.
before
do
setup_database_cleaner
DatabaseCleaner
.
strategy
=
:transaction
end
config
.
before
(
:each
,
:js
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
except:
deletion_except_tables
,
cache_tables:
false
}
end
config
.
before
(
:each
,
:delete
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
except:
deletion_except_tables
,
cache_tables:
false
}
end
config
.
before
(
:each
,
:migration
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
cache_tables:
false
}
end
config
.
before
do
DatabaseCleaner
.
start
end
config
.
append_after
do
DatabaseCleaner
.
clean
end
end
spec/support/db_cleaner.rb
View file @
68b7f99f
require
'database_cleaner/active_record/deletion'
module
DbCleaner
def
deletion_except_tables
module
FakeInformationSchema
[]
# Work around a bug in DatabaseCleaner when using the deletion strategy:
# https://github.com/DatabaseCleaner/database_cleaner/issues/347
#
# On MySQL, if the information schema is said to exist, we use an inaccurate
# row count leading to some tables not being cleaned when they should
def
information_schema_exists?
(
_connection
)
false
end
end
DatabaseCleaner
::
ActiveRecord
::
Deletion
.
prepend
(
FakeInformationSchema
)
RSpec
.
configure
do
|
config
|
# Ensure all sequences are reset at the start of the suite run
config
.
before
(
:suite
)
do
DatabaseCleaner
.
clean_with
(
:truncation
)
end
config
.
append_after
(
:context
)
do
DatabaseCleaner
.
clean_with
(
:deletion
,
cache_tables:
false
)
end
config
.
before
do
DatabaseCleaner
.
strategy
=
:transaction
end
config
.
before
(
:each
,
:js
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
cache_tables:
false
}
end
config
.
before
(
:each
,
:delete
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
cache_tables:
false
}
end
config
.
before
(
:each
,
:migration
)
do
DatabaseCleaner
.
strategy
=
:deletion
,
{
cache_tables:
false
}
end
config
.
before
do
DatabaseCleaner
.
start
end
end
config
.
append_after
do
def
setup_database_cleaner
DatabaseCleaner
.
clean
DatabaseCleaner
[
:active_record
,
{
connection:
ActiveRecord
::
Base
}]
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