From 283a08763495a6b3ce0b196259ee1666f2b08cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 15 Dec 2011 18:48:10 +0100 Subject: Clean up the cache before the request in case we are running in the reload_classes_only_on_change schema. --- railties/test/application/loading_test.rb | 54 +++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'railties/test/application/loading_test.rb') diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index 9c77f6210a..c4c93cce22 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -120,7 +120,6 @@ class LoadingTest < Test::Unit::TestCase extend Rack::Test::Methods require "#{rails_root}/config/environment" - sleep(1) get "/c" assert_equal "1", last_response.body @@ -160,7 +159,6 @@ class LoadingTest < Test::Unit::TestCase extend Rack::Test::Methods require "#{rails_root}/config/environment" - sleep(1) get "/c" assert_equal "1", last_response.body @@ -175,7 +173,7 @@ class LoadingTest < Test::Unit::TestCase assert_equal "1", last_response.body end - test "added files also trigger reloading" do + test "added files (like db/schema.rb) also trigger reloading" do add_to_config <<-RUBY config.cache_classes = false RUBY @@ -207,6 +205,56 @@ class LoadingTest < Test::Unit::TestCase assert_equal "2", last_response.body end + test "columns migrations also trigger reloading" do + add_to_config <<-RUBY + config.cache_classes = false + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '/title', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.title]] } + match '/body', :to => lambda { |env| [200, {"Content-Type" => "text/plain"}, [Post.new.body]] } + end + RUBY + + app_file "app/models/post.rb", <<-MODEL + class Post < ActiveRecord::Base + end + MODEL + + require 'rack/test' + extend Rack::Test::Methods + + app_file "db/migrate/1_create_posts.rb", <<-MIGRATION + class CreatePosts < ActiveRecord::Migration + def change + create_table :posts do |t| + t.string :title, :default => "TITLE" + end + end + end + MIGRATION + + Dir.chdir(app_path) { `rake db:migrate`} + require "#{rails_root}/config/environment" + + get "/title" + assert_equal "TITLE", last_response.body + + app_file "db/migrate/2_add_body_to_posts.rb", <<-MIGRATION + class AddBodyToPosts < ActiveRecord::Migration + def change + add_column :posts, :body, :text, :default => "BODY" + end + end + MIGRATION + + Dir.chdir(app_path) { `rake db:migrate` } + + get "/body" + assert_equal "BODY", last_response.body + end + protected def setup_ar! -- cgit v1.2.3