This project is archived and is in readonly mode.
Rake Tasks completely screwed up
-
Jeremy Kemper
- Milestone cleared.
- State changed from new to open
- Assigned user set to José Valim
-
José Valim
Ok, we have two issues here.
The first one is about rake tasks in gems being loaded after, point taken. This should be fixed.
The second one is about the output being development needs further investigation. Is rake spec:models setting the environment to test? When? Maybe your rake task is being executed before rspec has the chance to set the environment to test?
So could you please investigate the second issue and give more information? I will provide a patch for the former.
-
Matt Jones
Some notes on the second point:
-
the
enhancemethod adds functionality that runs after the specified task. See this for more details. -
there's a certain amount of setup done in development mode before the test stuff can be loaded, for instance to handle loading the schema from dev into test.
-
the connection is in a somewhat mixed state; I'm guessing the
myproject_testDB is in the test environment...
-
-
José Valim
Thanks Matt. A few more questions: how does the current behavior compares with Rails 2.3? Do you have any fix in mind?
-
Repository
- State changed from open to resolved
(from [e461e1bc0ec0a5c365840031309b83143e12955a]) Ensure application rake tasks and generators are loaded after the ones specified in railties/engines/rails. [#4471 Rake Tasks completely screwed up state:resolved] http://github.com/rails/rails/commit/e461e1bc0ec0a5c365840031309b83...
-
Kane
So regarding the second issue:
I assumed if i run rake db:test:prepare everything would be run in evironment test.
I didnt looked how deep this goes and how many and which rake tasks are affected.So Matt, im not sure if i get you right, but i dont think Rails.env should be dev in any point in the process. Im aware that the process involves loading the dev database, but the env should be definitely test right?
-
José Valim
- State changed from resolved to open
-
Nicolas Alejandro Santa
New Bug:
running rake db:seed executes the db/seeds.rb script twice times:
puts "Creating Basic Admin" u = User.create(:email => 'admin@yeti-media.com' , :password => 'admin123', :password_confirmation => 'admin123') u.admin = true u.confirmation_sent_at = u.confirmed_at = Time.now.to_s u.confirmation_token = nil u.save puts "Basic Admin Created"Got this output:
rake db:seed
Creating Basic Admin
Basic Admin Created
Creating Basic Admin
Basic Admin Created -
José Valim
Which rails version? This happens in rails master? It happens with this task only or all others?
-
José Valim
Nicolas, I just create a new application from Rails source and put the following in my db/seeds.rb
puts "OMG"I invoked "rake db:seed" and it printed "OMG" just once, as expected.
Kane, regarding the other bug, can you please create a failing test case here:
http://github.com/rails/rails/blob/master/railties/test/application...
Please let me know if you have any doubts.
-
Gavin Stark
Unable to reproduce in 3.0.0beta3
-
Rizwan Reza
- Tag cleared.
- State changed from open to invalid
-
Kane
Hey José
i attached the requested failing test case -
Rizwan Reza
- Tag set to rake, tasks
- State changed from invalid to open
-
José Valim
- Milestone cleared.
-
José Valim
Could someone please check what is the behavior in Rails 2.3? I'm almost sure that db:test:prepare needs to run in development as Matt pointed out. In other words, you should not be enhancing it to add custom behavior.
-
José Valim
- Milestone cleared.
-
José Valim
- State changed from open to wontfix
- Importance changed from to Low
Yes, I confirmed this one. When you call rake test, it is actually in development, because you did not pass RAILS_ENV=test. Then it does all setup in development and finally invoke the test command, by shelling out with the proper env configured. There is not much we can do here.
-
Jeff Rafter
I was able to reproduce Nicolas' duplication bug in Rails 3.0.3. Entering puts "OMG!" in db/seeds.rb and calling rake db:seed shows the message twice (meaning the rake task is called twice). I spent some time digging around and found that my rake tasks in my application were being loaded twice (duplicating the task). This was caused by the annotate-models gem and associated tasks. Removing those and the behavior was fine. Ultimately instead of
ENV['position'] ||= 'after' require 'annotate_models/tasks'
I now have
ENV['position'] ||= 'after' desc "Add schema information (as comments) to model and fixture files" task :annotate_models => :environment do
require 'annotate_models' options={} options[:position_in_class] = ENV['position_in_class'] || ENV['position'] options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] AnnotateModels.do_annotations(options)end
desc "Remove schema information from model and fixture files" task :remove_annotation => :environment do
require 'annotate_models' AnnotateModels.remove_annotationsend
And everything works as expected.
Cheers,
Jeff
