diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-15 18:48:10 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-15 18:48:10 +0100 |
commit | 283a08763495a6b3ce0b196259ee1666f2b08cf1 (patch) | |
tree | efd3899d1a822658a7c5c835d6198ea506a71148 /railties/test/application | |
parent | de947c621d8ee18caca574451c722a6e30c4e6d6 (diff) | |
download | rails-283a08763495a6b3ce0b196259ee1666f2b08cf1.tar.gz rails-283a08763495a6b3ce0b196259ee1666f2b08cf1.tar.bz2 rails-283a08763495a6b3ce0b196259ee1666f2b08cf1.zip |
Clean up the cache before the request in case we are running in the reload_classes_only_on_change schema.
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/console_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/loading_test.rb | 54 | ||||
-rw-r--r-- | railties/test/application/rake/migrations_test.rb | 2 |
3 files changed, 52 insertions, 6 deletions
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 6f9d8d57b1..fa2652a6d3 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -62,8 +62,6 @@ class ConsoleTest < Test::Unit::TestCase load_environment assert User.new.respond_to?(:name) - sleep(1) - app_file "app/models/user.rb", <<-MODEL class User attr_accessor :name, :age 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! diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb index fd8a30557e..7982c42d8f 100644 --- a/railties/test/application/rake/migrations_test.rb +++ b/railties/test/application/rake/migrations_test.rb @@ -86,7 +86,7 @@ module ApplicationTests `rails generate migration add_email_to_users email:string` end - Dir.chdir(app_path) { `rake db:migrate`} + Dir.chdir(app_path) { `rake db:migrate` } output = Dir.chdir(app_path) { `rake db:migrate:status` } assert_match(/up\s+\d{14}\s+Create users/, output) |