提交 627f89b1 编写于 作者: K kennyj

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

上级 848276df
......@@ -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
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册