aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2013-07-10 11:46:17 -0700
committerJosé Valim <jose.valim@plataformatec.com.br>2013-07-10 11:46:17 -0700
commite7e81b4580f46c3d5229fdef3f0749802a9206da (patch)
tree466323b19ec4afdb9cf08bb9b4a3013814776591 /railties
parentddf79ab15b7e47a3ed98c44da7665dbc624fdbf6 (diff)
parent9cac69c602f57e397fe01d866cb24ce1781606d4 (diff)
downloadrails-e7e81b4580f46c3d5229fdef3f0749802a9206da.tar.gz
rails-e7e81b4580f46c3d5229fdef3f0749802a9206da.tar.bz2
rails-e7e81b4580f46c3d5229fdef3f0749802a9206da.zip
Merge pull request #11389 from jetthoughts/11381_fix_hit_database_on_precompile
#11381: Ignore config.eager_load=true for rake
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/application.rb3
-rw-r--r--railties/test/application/assets_test.rb2
-rw-r--r--railties/test/application/rake_test.rb36
4 files changed, 26 insertions, 19 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index cc7fecb28a..13a3301fbd 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Fix `rake environment` to do not eager load modules
+
+ *Paul Nikitochkin*
+
* Fix `rake notes` to look into `*.sass` files
*Yuri Artemev*
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 6fd01ee768..f761bef664 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -291,7 +291,8 @@ module Rails
require "rails/tasks"
config = self.config
task :environment do
- config.eager_load = false
+ ActiveSupport.on_load(:before_initialize) { config.eager_load = false }
+
require_environment!
end
end
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 633d864dac..4de8fcaa38 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -91,7 +91,7 @@ module ApplicationTests
class UsersController < ApplicationController; end
eoruby
app_file "app/models/user.rb", <<-eoruby
- class User < ActiveRecord::Base; end
+ class User < ActiveRecord::Base; raise 'should not be reached'; end
eoruby
ENV['RAILS_ENV'] = 'production'
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index 8e5310afee..c1cb1c1eba 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -9,7 +9,6 @@ module ApplicationTests
def setup
build_app
boot_rails
- FileUtils.rm_rf("#{app_path}/config/environments")
end
def teardown
@@ -56,10 +55,8 @@ module ApplicationTests
assert_match "Doing something...", output
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
- config.eager_load = true
-
rake_tasks do
task do_nothing: :environment do
Hello.new.world
@@ -67,33 +64,38 @@ module ApplicationTests
end
RUBY
- app_file "app/models/hello.rb", <<-RUBY
- class Hello
- def world
- puts "Hello world"
+ app_file 'app/models/hello.rb', <<-RUBY
+ class Hello
+ def world
+ puts 'Hello world'
+ end
end
- end
RUBY
- output = Dir.chdir(app_path){ `rake do_nothing` }
- assert_match "Hello world", output
+ output = Dir.chdir(app_path) { `rake do_nothing` }
+ assert_match 'Hello world', output
end
- def test_should_not_eager_load_model_path_for_rake
+ def test_should_not_eager_load_model_for_rake
add_to_config <<-RUBY
- config.eager_load = true
-
rake_tasks do
task do_nothing: :environment do
end
end
RUBY
- app_file "app/models/hello.rb", <<-RUBY
- raise 'should not be pre-required for rake even `eager_load=true`'
+ add_to_env_config 'production', <<-RUBY
+ config.eager_load = true
+ RUBY
+
+ app_file 'app/models/hello.rb', <<-RUBY
+ raise 'should not be pre-required for rake even eager_load=true'
RUBY
- Dir.chdir(app_path){ `rake do_nothing` }
+ 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
def test_code_statistics_sanity