Skip to content
Browse files

Fix #5847 and #4045. Load AR::Base before loading an application model.

  • Loading branch information...
1 parent 848276d commit 627f89b189734d7c8915a74f3f57a232d3d4d0d9 @kennyj kennyj committed Apr 26, 2012
Showing with 27 additions and 0 deletions.
  1. +5 −0 activerecord/lib/active_record/railtie.rb
  2. +22 −0 railties/test/application/rake_test.rb
View
5 activerecord/lib/active_record/railtie.rb
@@ -128,5 +128,10 @@ class Railtie < Rails::Railtie
end
end
+
+ config.after_initialize do
+ # We should load ActiveRecord::Base class before loading an application model.
+ require "active_record/base"
+ end
end
end
View
22 railties/test/application/rake_test.rb
@@ -167,5 +167,27 @@ def test_rake_clear_schema_cache
end
assert !File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
end
+
+ def test_load_activerecord_base_when_we_use_observers
+ Dir.chdir(app_path) do
+ `bundle exec rails g model user;
+ bundle exec rake db:migrate;
+ bundle exec rails g observer user;`
+
+ add_to_config "config.active_record.observers = :user_observer"
+
+ assert_equal "0", `bundle exec rails r "puts User.count"`.strip
+
+ app_file "lib/tasks/count_user.rake", <<-RUBY
+ namespace :user do
+ task :count => :environment do
+ puts User.count
+ end
+ end
+ RUBY
+
+ assert_equal "0", `bundle exec rake user:count`.strip
+ end
+ end
end
end

3 comments on commit 627f89b

@sobrinho

@kennyj this means active record is not lazy loaded anymore?

@josevalim
Ruby on Rails member

Yes, it is not lazy loaded anymore. We should likely revert this and find out a better fix.

@rafaelfranca
Ruby on Rails member

Agreed. As we don't have an easy way to opt-out a component, so Active Record will be loaded even when you don't want it.

Please sign in to comment.
Something went wrong with that request. Please try again.