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
fe530ef6
Commit
fe530ef6
authored
Mar 29, 2022
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Does not create a dev:copy_db:geo task
parent
9e09dbac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
19 deletions
+33
-19
lib/tasks/dev.rake
lib/tasks/dev.rake
+3
-1
spec/tasks/dev_rake_spec.rb
spec/tasks/dev_rake_spec.rb
+30
-18
No files found.
lib/tasks/dev.rake
View file @
fe530ef6
...
...
@@ -30,8 +30,10 @@ namespace :dev do
databases
=
ActiveRecord
::
Tasks
::
DatabaseTasks
.
setup_initial_database_yaml
namespace
:copy_db
do
ALLOWED_DATABASES
=
%w[ci]
.
freeze
ActiveRecord
::
Tasks
::
DatabaseTasks
.
for_each
(
databases
)
do
|
name
|
next
if
name
==
'main'
next
unless
ALLOWED_DATABASES
.
include?
(
name
)
desc
"Copies the
#{
name
}
database from the main database"
task
name
=>
:environment
do
...
...
spec/tasks/dev_rake_spec.rb
View file @
fe530ef6
...
...
@@ -40,33 +40,45 @@ RSpec.describe 'dev rake tasks' do
end
end
describe
'copy_db:ci
'
do
context
'multiple databases
'
do
before
do
skip_if_multiple_databases_not_setup
configurations
=
instance_double
(
ActiveRecord
::
DatabaseConfigurations
)
allow
(
ActiveRecord
::
Base
).
to
receive
(
:configurations
).
and_return
(
configurations
)
allow
(
configurations
).
to
receive
(
:configs_for
).
with
(
env_name:
Rails
.
env
,
name:
'ci'
).
and_return
(
ci_configuration
)
end
subject
(
:load_task
)
{
run_rake_task
(
'dev:setup_ci_db'
)
}
context
'with a valid database'
do
describe
'copy_db:ci'
do
before
do
configurations
=
instance_double
(
ActiveRecord
::
DatabaseConfigurations
)
allow
(
ActiveRecord
::
Base
).
to
receive
(
:configurations
).
and_return
(
configurations
)
allow
(
configurations
).
to
receive
(
:configs_for
).
with
(
env_name:
Rails
.
env
,
name:
'ci'
).
and_return
(
ci_configuration
)
end
let
(
:ci_configuration
)
{
instance_double
(
ActiveRecord
::
DatabaseConfigurations
::
HashConfig
,
name:
'ci'
,
database:
'__test_db_ci
'
)
}
subject
(
:load_task
)
{
run_rake_task
(
'dev:setup_ci_db
'
)
}
it
'creates the database from main'
do
expect
(
ApplicationRecord
.
connection
).
to
receive
(
:create_database
).
with
(
ci_configuration
.
database
,
template:
ApplicationRecord
.
connection_db_config
.
database
)
let
(
:ci_configuration
)
{
instance_double
(
ActiveRecord
::
DatabaseConfigurations
::
HashConfig
,
name:
'ci'
,
database:
'__test_db_ci'
)
}
run_rake_task
(
'dev:copy_db:ci'
)
end
it
'creates the database from main'
do
expect
(
ApplicationRecord
.
connection
).
to
receive
(
:create_database
).
with
(
ci_configuration
.
database
,
template:
ApplicationRecord
.
connection_db_config
.
database
)
run_rake_task
(
'dev:copy_db:ci'
)
end
context
'when the database already exists'
do
it
'prints out a warning'
do
expect
(
ApplicationRecord
.
connection
).
to
receive
(
:create_database
).
and_raise
(
ActiveRecord
::
DatabaseAlreadyExists
)
context
'when the database already exists'
do
it
'prints out a warning'
do
expect
(
ApplicationRecord
.
connection
).
to
receive
(
:create_database
).
and_raise
(
ActiveRecord
::
DatabaseAlreadyExists
)
expect
{
run_rake_task
(
'dev:copy_db:ci'
)
}.
to
output
(
/Database '
#{
ci_configuration
.
database
}
' already exists/
).
to_stderr
end
end
end
end
expect
{
run_rake_task
(
'dev:copy_db:ci'
)
}.
to
output
(
/Database '
#{
ci_configuration
.
database
}
' already exists/
).
to_stderr
context
'with an invalid database'
do
it
'raises an error'
do
expect
{
run_rake_task
(
'dev:copy_db:foo'
)
}.
to
raise_error
(
RuntimeError
,
/Don't know how to build task/
)
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