Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 627f89b189734d7c8915a74f3f57a232d3d4d0d9 1 parent 848276d
Toshinori Kajihara authored
5 activerecord/lib/active_record/railtie.rb
@@ -128,5 +128,10 @@ class Railtie < Rails::Railtie
128 128 end
129 129
130 130 end
  131 +
  132 + config.after_initialize do
  133 + # We should load ActiveRecord::Base class before loading an application model.
  134 + require "active_record/base"
  135 + end
131 136 end
132 137 end
22 railties/test/application/rake_test.rb
@@ -167,5 +167,27 @@ def test_rake_clear_schema_cache
167 167 end
168 168 assert !File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
169 169 end
  170 +
  171 + def test_load_activerecord_base_when_we_use_observers
  172 + Dir.chdir(app_path) do
  173 + `bundle exec rails g model user;
  174 + bundle exec rake db:migrate;
  175 + bundle exec rails g observer user;`
  176 +
  177 + add_to_config "config.active_record.observers = :user_observer"
  178 +
  179 + assert_equal "0", `bundle exec rails r "puts User.count"`.strip
  180 +
  181 + app_file "lib/tasks/count_user.rake", <<-RUBY
  182 + namespace :user do
  183 + task :count => :environment do
  184 + puts User.count
  185 + end
  186 + end
  187 + RUBY
  188 +
  189 + assert_equal "0", `bundle exec rake user:count`.strip
  190 + end
  191 + end
170 192 end
171 193 end

0 comments on commit 627f89b

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