Topic: Rakefile ....where is it in rails 3.0?

Hey Guys,

I can't seem to find the "default" set of rails 3.0 rake files. I'm talking about all the rake tasks that get listed when I do:

rake -D

I've got a bunch of rake files under rails-2.3.5/lib/tasks folder but none of those are duplicated in a "rails-3.0.6/lib/task" folder...

I don't suppose rails 3.0 just re-uses the rakefiles from 2.3.5.. does it?  But if that's the case, why isn't rake throwing deprecation messages like:

DEPRECATION WARNING: RAILS_ENV is deprecated. Please use ::Rails.env. (called from /media/data/home/sonnychee/workspace/gc3/lib/tasks/db.rake:5)
environment is test
DEPRECATION WARNING: RAILS_ROOT is deprecated. Please use ::Rails.root.to_s. (called from /media/data/home/sonnychee/workspace/gc3/lib/tasks/db.rake:13)

Re: Rakefile ....where is it in rails 3.0?

Why do you want to know? Are you just curious, or are you wanting to add your own rake tasks? IF you look in the Rakefile in a rails 3 app is says

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

So if the latter is the case, you could just put whatever rake tasks you want in there as the comment suggests.

Re: Rakefile ....where is it in rails 3.0?

Thanks for your reply, meta.  I'm interested because I want to override some of the tasks *slightly* (I was planning on putting the overrides in the lib/tasks folder as you indicated.)

Re: Rakefile ....where is it in rails 3.0?

Ah - I see.

You might want to look at this post -

It has some information with respect to how to "Redefine" tasks. Although from what it looks like, redefining tasks really amounts to adding on to existing tasks (look at the example he gives). If this works for you, then great.

If you need to dig into the middle of a task a little bit more, then you might want to take a look at this - … ers-oh-my/

Rake tasks are now integrated into the engines structure in a new way for rails 3. So look into second link and see if that helps you in figuring out where you need to go in order to find the tasks that you need to modify. Again, for reasons in the first post, it seems like if you need to dig into the depths of a particular rake tasks (even for just a minor modification), you would probably want to use a different namespace, since using the same one would seem to "append" rather than to "override" the existing one.

What task are you trying to modify anyway?

Hope this helps


I've seen that with the rails 3 architecture

Re: Rakefile ....where is it in rails 3.0?

Thanks for the links Chris.  I'll have a look at those.

In the interim before your posting, I just took the rake task definition from the rails-2.3.5/lib/task folder and just put a modified version in my myapp/lib/task folder.  That *seemed* to work.

At the moment, all I'm trying to do is set the environment that the db:fixture:load task works with.  In the past I was able to do:

> RAILS_ENV=test rake db:fixtures:load

to load fixtures into my test db.  Rails 3.0+ uses the Rails.env variable... which I have no way of setting at the command line... do I?

Re: Rakefile ....where is it in rails 3.0?

Why are you trying to load fixtures in with a rake task? Typically, if you are testing or speccing, you have some sort of helper that does that thing for you before each run. For instance, in rspec, I just have to do

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

I'm sure there is something similar with TestUnit if that is what you are using (I vastly prefer RSpec though). Of course, I also recommend using factories over fixtures. Fixtures can become messy and untethered really quickly as the number of cases you are working with grows. Factories keep things clean by letting you just specify the stuff that is necessary for the specific test at hand (and setting up defaults for any other required fields so that you can avoid instantiation errors). Look into factory girl or machinist (I use the former, but the other is also popular from what I understand).

If there is some minimal set of data (like states and countries) that you need loaded into your application for all of your environments, you can look into using database seeds. There is a way to load these from the spec/test helpers as well.