fenec
fenec

Reputation: 5806

How can i add a task that will run after rake test:db:prepare in Rails

I am using rails 4.2 and i am trying to run test using the command rake test.I am trying to use plv8 extention so i create it manually from psql console, then when i run the test it seems like it has deleted that extension from postgres. I looked into rails 4.2 project and i noticed that they brought test:db:prepare back. This is what is deleting the plv8 extension every time. how can i add a pice of code that will run after the test:db:prepare or test:db:create?

I am not a big fan of modifying Rakefile solution.

Upvotes: 1

Views: 606

Answers (1)

DiegoSalazar
DiegoSalazar

Reputation: 13521

You can name multiple tasks inline:

rake test:db:create test:db:prepare custom:task

Or when you create a new rake task you can make it dependent on any other task:

desc "the dependent task will run before this one"
task my_task: :other_task do
   # stuff
end

You can also arbitrarily invoke other tasks:

Rake::Task['db:test:prepare'].invoke

More info here: http://jasonseifer.com/2010/04/06/rake-tutorial and here: How to run Rake tasks from within Rake tasks?

Upvotes: 1

Related Questions