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
Jérome Perrin
gitlab-ce
Commits
40d4d8a4
Commit
40d4d8a4
authored
May 11, 2016
by
DJ Mountney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the gitlab:db:configure rake task
parent
24632d21
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
spec/tasks/gitlab/db_rake_spec.rb
spec/tasks/gitlab/db_rake_spec.rb
+62
-0
No files found.
spec/tasks/gitlab/db_rake_spec.rb
0 → 100644
View file @
40d4d8a4
require
'spec_helper'
require
'rake'
describe
'gitlab:db namespace rake task'
do
before
:all
do
Rake
.
application
.
rake_require
'active_record/railties/databases'
Rake
.
application
.
rake_require
'tasks/seed_fu'
Rake
.
application
.
rake_require
'tasks/gitlab/db'
# empty task as env is already loaded
Rake
::
Task
.
define_task
:environment
end
before
do
# Stub out db tasks
allow
(
Rake
::
Task
[
'db:migrate'
]).
to
receive
(
:invoke
).
and_return
(
true
)
allow
(
Rake
::
Task
[
'db:schema:load'
]).
to
receive
(
:invoke
).
and_return
(
true
)
allow
(
Rake
::
Task
[
'db:seed_fu'
]).
to
receive
(
:invoke
).
and_return
(
true
)
end
describe
'configure'
do
it
'should invoke db:migrate when schema has already been loaded'
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
and_return
(
true
)
expect
(
Rake
::
Task
[
'db:migrate'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:schema:load'
]).
not_to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:seed_fu'
]).
not_to
receive
(
:invoke
)
expect
{
run_rake_task
(
'gitlab:db:configure'
)
}.
not_to
raise_error
end
it
'should invoke db:shema:load and db:seed_fu when schema is not loaded'
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
and_return
(
false
)
expect
(
Rake
::
Task
[
'db:schema:load'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:seed_fu'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:migrate'
]).
not_to
receive
(
:invoke
)
expect
{
run_rake_task
(
'gitlab:db:configure'
)
}.
not_to
raise_error
end
it
'should not invoke any other rake tasks during an error'
do
allow
(
ActiveRecord
::
Base
).
to
receive
(
:connection
).
and_raise
(
RuntimeError
,
'error'
)
expect
(
Rake
::
Task
[
'db:migrate'
]).
not_to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:schema:load'
]).
not_to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:seed_fu'
]).
not_to
receive
(
:invoke
)
expect
{
run_rake_task
(
'gitlab:db:configure'
)
}.
to
raise_error
(
RuntimeError
,
'error'
)
# unstub connection so that the database cleaner still works
allow
(
ActiveRecord
::
Base
).
to
receive
(
:connection
).
and_call_original
end
it
'should not invoke seed after a failed schema_load'
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:table_exists?
).
and_return
(
false
)
allow
(
Rake
::
Task
[
'db:schema:load'
]).
to
receive
(
:invoke
).
and_raise
(
RuntimeError
,
'error'
)
expect
(
Rake
::
Task
[
'db:schema:load'
]).
to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:seed_fu'
]).
not_to
receive
(
:invoke
)
expect
(
Rake
::
Task
[
'db:migrate'
]).
not_to
receive
(
:invoke
)
expect
{
run_rake_task
(
'gitlab:db:configure'
)
}.
to
raise_error
(
RuntimeError
,
'error'
)
end
end
def
run_rake_task
(
task_name
)
Rake
::
Task
[
task_name
].
reenable
Rake
.
application
.
invoke_task
task_name
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