diff options
author | José Valim <jose.valim@gmail.com> | 2010-06-19 17:51:29 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-19 17:51:44 +0200 |
commit | 312f43324159fbcd8749cd331ed7d6500a714a83 (patch) | |
tree | 750659e6006e58f2941c09ffdd3011e904c63b26 /railties/test/application/loading_test.rb | |
parent | d430db9fd407fd6aee25ca13538d8988dc7ee297 (diff) | |
download | rails-312f43324159fbcd8749cd331ed7d6500a714a83.tar.gz rails-312f43324159fbcd8749cd331ed7d6500a714a83.tar.bz2 rails-312f43324159fbcd8749cd331ed7d6500a714a83.zip |
Clear DescendantsTracker on each request.
Diffstat (limited to 'railties/test/application/loading_test.rb')
-rw-r--r-- | railties/test/application/loading_test.rb | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb new file mode 100644 index 0000000000..b337d3fc6e --- /dev/null +++ b/railties/test/application/loading_test.rb @@ -0,0 +1,73 @@ +require 'isolation/abstract_unit' + +class LoadingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + def app + @app ||= Rails.application + end + + def test_load_should_load_constants + app_file "app/models/post.rb", <<-MODEL + class Post < ActiveRecord::Base + validates_acceptance_of :title, :accept => "omg" + end + MODEL + + require "#{rails_root}/config/environment" + setup_ar! + + p = Post.create(:title => 'omg') + assert_equal 1, Post.count + assert_equal 'omg', p.title + p = Post.first + assert_equal 'omg', p.title + end + + def test_descendants_are_cleaned_on_each_request_without_cache_classes + add_to_config <<-RUBY + config.cache_classes = false + RUBY + + app_file "app/models/post.rb", <<-MODEL + class Post < ActiveRecord::Base + end + MODEL + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + match '/load', :to => lambda { |env| [200, {}, Post.all] } + match '/unload', :to => lambda { |env| [200, {}, []] } + end + RUBY + + require 'rack/test' + extend Rack::Test::Methods + + require "#{rails_root}/config/environment" + setup_ar! + + assert_equal [], ActiveRecord::Base.descendants + get "/load" + assert_equal [Post], ActiveRecord::Base.descendants + get "/unload" + assert_equal [], ActiveRecord::Base.descendants + end + + protected + + def setup_ar! + ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") + ActiveRecord::Migration.verbose = false + ActiveRecord::Schema.define(:version => 1) do + create_table :posts do |t| + t.string :title + end + end + end +end |