1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #11389 from jetthoughts/11381_fix_hit_database_on_precompile

#11381: Ignore config.eager_load=true for rake
This commit is contained in:
José Valim 2013-07-10 11:46:17 -07:00
commit e7e81b4580
4 changed files with 26 additions and 19 deletions

View file

@ -1,3 +1,7 @@
* Fix `rake environment` to do not eager load modules
*Paul Nikitochkin*
* Fix `rake notes` to look into `*.sass` files * Fix `rake notes` to look into `*.sass` files
*Yuri Artemev* *Yuri Artemev*

View file

@ -291,7 +291,8 @@ module Rails
require "rails/tasks" require "rails/tasks"
config = self.config config = self.config
task :environment do task :environment do
config.eager_load = false ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
require_environment! require_environment!
end end
end end

View file

@ -91,7 +91,7 @@ module ApplicationTests
class UsersController < ApplicationController; end class UsersController < ApplicationController; end
eoruby eoruby
app_file "app/models/user.rb", <<-eoruby app_file "app/models/user.rb", <<-eoruby
class User < ActiveRecord::Base; end class User < ActiveRecord::Base; raise 'should not be reached'; end
eoruby eoruby
ENV['RAILS_ENV'] = 'production' ENV['RAILS_ENV'] = 'production'

View file

@ -9,7 +9,6 @@ module ApplicationTests
def setup def setup
build_app build_app
boot_rails boot_rails
FileUtils.rm_rf("#{app_path}/config/environments")
end end
def teardown def teardown
@ -56,10 +55,8 @@ module ApplicationTests
assert_match "Doing something...", output assert_match "Doing something...", output
end end
def test_does_not_explode_when_accessing_a_model_with_eager_load def test_does_not_explode_when_accessing_a_model
add_to_config <<-RUBY add_to_config <<-RUBY
config.eager_load = true
rake_tasks do rake_tasks do
task do_nothing: :environment do task do_nothing: :environment do
Hello.new.world Hello.new.world
@ -67,33 +64,38 @@ module ApplicationTests
end end
RUBY RUBY
app_file "app/models/hello.rb", <<-RUBY app_file 'app/models/hello.rb', <<-RUBY
class Hello class Hello
def world def world
puts "Hello world" puts 'Hello world'
end end
end end
RUBY RUBY
output = Dir.chdir(app_path){ `rake do_nothing` } output = Dir.chdir(app_path) { `rake do_nothing` }
assert_match "Hello world", output assert_match 'Hello world', output
end end
def test_should_not_eager_load_model_path_for_rake def test_should_not_eager_load_model_for_rake
add_to_config <<-RUBY add_to_config <<-RUBY
config.eager_load = true
rake_tasks do rake_tasks do
task do_nothing: :environment do task do_nothing: :environment do
end end
end end
RUBY RUBY
app_file "app/models/hello.rb", <<-RUBY add_to_env_config 'production', <<-RUBY
raise 'should not be pre-required for rake even `eager_load=true`' config.eager_load = true
RUBY RUBY
Dir.chdir(app_path){ `rake do_nothing` } app_file 'app/models/hello.rb', <<-RUBY
raise 'should not be pre-required for rake even eager_load=true'
RUBY
Dir.chdir(app_path) do
assert system('rake do_nothing RAILS_ENV=production'),
'should not be pre-required for rake even eager_load=true'
end
end end
def test_code_statistics_sanity def test_code_statistics_sanity