diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/middleware/cache_test.rb | 16 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 35 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 28 | ||||
-rw-r--r-- | railties/test/application/runner_test.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/model_generator_test.rb | 9 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 1 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 33 |
7 files changed, 107 insertions, 19 deletions
diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index 655f9bcd55..5675cebfd9 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -24,7 +24,7 @@ module ApplicationTests end def simple_controller - controller :foo, <<-RUBY + controller :expires, <<-RUBY class ExpiresController < ApplicationController def expires_header expires_in 10, :public => !params[:private] @@ -55,6 +55,20 @@ module ApplicationTests RUBY end + def test_cache_is_disabled_in_dev_mode + simple_controller + app("development") + + get "/expires/expires_header" + assert_nil last_response.headers['X-Rack-Cache'] + + body = last_response.body + + get "/expires/expires_header" + assert_nil last_response.headers['X-Rack-Cache'] + assert_not_equal body, last_response.body + end + def test_cache_works_with_expires simple_controller diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 0ce6d482a0..f9b594eb33 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -19,6 +19,33 @@ module ApplicationTests boot! assert_equal [ + "ActionDispatch::Static", + "Rack::Lock", + "ActiveSupport::Cache::Strategy::LocalCache", + "Rack::Runtime", + "Rails::Rack::Logger", + "ActionDispatch::ShowExceptions", + "ActionDispatch::RemoteIp", + "Rack::Sendfile", + "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", + "ActiveRecord::QueryCache", + "ActionDispatch::Cookies", + "ActionDispatch::Session::CookieStore", + "ActionDispatch::Flash", + "ActionDispatch::ParamsParser", + "Rack::MethodOverride", + "ActionDispatch::Head", + "ActionDispatch::BestStandardsSupport" + ], middleware + end + + test "Rack::Cache is present when action_controller.perform_caching is set" do + add_to_config "config.action_controller.perform_caching = true" + + boot! + + assert_equal [ "Rack::Cache", "ActionDispatch::Static", "Rack::Lock", @@ -82,24 +109,24 @@ module ApplicationTests test "insert middleware after" do add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config" boot! - assert_equal "Rack::Config", middleware.third + assert_equal "Rack::Config", middleware.second end test "RAILS_CACHE does not respond to middleware" do add_to_config "config.cache_store = :memory_store" boot! - assert_equal "Rack::Runtime", middleware.fourth + assert_equal "Rack::Runtime", middleware.third end test "RAILS_CACHE does respond to middleware" do boot! - assert_equal "Rack::Runtime", middleware.fifth + assert_equal "Rack::Runtime", middleware.fourth end test "insert middleware before" do add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config" boot! - assert_equal "Rack::Config", middleware.second + assert_equal "Rack::Config", middleware.first end # x_sendfile_header middleware diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index bf2af11e9f..416a5de5b0 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -177,6 +177,34 @@ module ApplicationTests assert_equal 'admin::foo', last_response.body end + def test_reloads_appended_route_blocks + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match ':controller#:action' + end + RUBY + + add_to_config <<-R + routes.append do + match '/win' => lambda { |e| [200, {'Content-Type'=>'text/plain'}, ['WIN']] } + end + R + + app 'development' + + get '/win' + assert_equal 'WIN', last_response.body + + app_file 'config/routes.rb', <<-R + AppTemplate::Application.routes.draw do + match 'lol' => 'hello#index' + end + R + + get '/win' + assert_equal 'WIN', last_response.body + end + {"development" => "baz", "production" => "bar"}.each do |mode, expected| test "reloads routes when configuration is changed in #{mode}" do controller :foo, <<-RUBY diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 07a3d94120..292d1e247f 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -18,6 +18,10 @@ module ApplicationTests MODEL end + def test_should_include_runner_in_shebang_line_in_help + assert_match "/rails runner", Dir.chdir(app_path) { `bundle exec rails runner --help` } + end + def test_should_run_ruby_statement assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "puts User.count"` } end diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index f4a9a152c9..52e08cf2dd 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -165,6 +165,15 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_no_migration "db/migrate/create_accounts.rb" end + def test_existing_migration_is_removed_on_force + run_generator + old_migration = Dir["#{destination_root}/db/migrate/*_create_accounts.rb"].first + error = capture(:stderr) { run_generator ["Account", "--force"] } + assert_no_match /Another migration is already named create_foos/, error + assert_no_file old_migration + assert_migration 'db/migrate/create_accounts.rb' + end + def test_invokes_default_test_framework run_generator assert_file "test/unit/account_test.rb", /class AccountTest < ActiveSupport::TestCase/ diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 390c0ab543..79c7735019 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -19,6 +19,7 @@ RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") # to run the tests require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/core_ext/kernel/reporting" module TestHelpers module Paths diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 6b90b32005..a9dd7d4c1b 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -4,19 +4,6 @@ require 'stringio' module RailtiesTest class EngineTest < Test::Unit::TestCase - # TODO: it's copied from generators/test_case, maybe make a module with such helpers? - def capture(stream) - begin - stream = stream.to_s - eval "$#{stream} = StringIO.new" - yield - result = eval("$#{stream}").string - ensure - eval("$#{stream} = #{stream.upcase}") - end - - result - end include ActiveSupport::Testing::Isolation include SharedTests @@ -578,7 +565,6 @@ module RailtiesTest env = Rack::MockRequest.env_for("/bukkits/posts/new") response = AppTemplate::Application.call(env) - p rack_body(response[2]) assert rack_body(response[2]) =~ /name="post\[title\]"/ end @@ -638,5 +624,24 @@ module RailtiesTest assert !File.exist?(File.join(app_path, 'public/bukkits')) end end + + test "loading seed data" do + @plugin.write "db/seeds.rb", <<-RUBY + Bukkits::Engine.config.bukkits_seeds_loaded = true + RUBY + + app_file "db/seeds.rb", <<-RUBY + Rails.application.config.app_seeds_loaded = true + RUBY + + boot_rails + + Rails.application.load_seed + assert Rails.application.config.app_seeds_loaded + assert_raise(NoMethodError) do Bukkits::Engine.config.bukkits_seeds_loaded end + + Bukkits::Engine.load_seed + assert Bukkits::Engine.config.bukkits_seeds_loaded + end end end |