aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPaul Nikitochkin <paul.nikitochkin@gmail.com>2013-07-09 23:36:50 +0300
committerPaul Nikitochkin <paul.nikitochkin@gmail.com>2013-07-10 21:43:15 +0300
commit9cac69c602f57e397fe01d866cb24ce1781606d4 (patch)
tree29168cb1c28326da961037435874a1af2b2509b3 /railties
parent4b6886a1403613022152a7196f87934765a930c6 (diff)
downloadrails-9cac69c602f57e397fe01d866cb24ce1781606d4.tar.gz
rails-9cac69c602f57e397fe01d866cb24ce1781606d4.tar.bz2
rails-9cac69c602f57e397fe01d866cb24ce1781606d4.zip
#11381: Ignore config.eager_load=true for rake
Closes #11381
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