Skip to content

Commit

Permalink
Fix rails#5847 and rails#4045. Force load AR::Base before loading an …
Browse files Browse the repository at this point in the history
…application model.
  • Loading branch information
kennyj committed Apr 26, 2012
1 parent 006de25 commit 81af288
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/lib/active_record/railtie.rb
Expand Up @@ -121,5 +121,10 @@ class Railtie < Rails::Railtie
end
end
end

config.after_initialize do
# We should load ActiveRecord::Base class before loading an application model.
require "active_record/base"
end
end
end
23 changes: 23 additions & 0 deletions railties/test/application/rake_test.rb
Expand Up @@ -150,5 +150,28 @@ def test_rake_dump_structure_should_be_called_twice_when_migrate_redo
# expect only Invoke db:structure:dump (first_time)
assert_no_match(/^\*\* Invoke db:structure:dump\s+$/, output)
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

0 comments on commit 81af288

Please sign in to comment.