diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/assets_test.rb | 27 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 30 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 4 | ||||
-rw-r--r-- | railties/test/application/rack/logger_test.rb | 40 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 22 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 4 | ||||
-rw-r--r-- | railties/test/application/test_test.rb | 25 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 13 | ||||
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/shared_generator_tests.rb | 3 | ||||
-rw-r--r-- | railties/test/railties/shared_tests.rb | 3 |
11 files changed, 161 insertions, 12 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb new file mode 100644 index 0000000000..b03dc3132b --- /dev/null +++ b/railties/test/application/assets_test.rb @@ -0,0 +1,27 @@ +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class RoutingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app + boot_rails + end + + test "assets routes have higher priority" do + app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '*path', :to => lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] } + end + RUBY + + get "/assets/demo.js" + assert_match "alert()", last_response.body + end + end +end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index b1f7076776..6193e72625 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -12,7 +12,6 @@ end class ::MyOtherMailObserver < ::MyMailObserver; end - module ApplicationTests class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation @@ -437,10 +436,35 @@ module ApplicationTests app_file 'config/initializers/wrap_parameters.rb', <<-RUBY ActionController::Base.wrap_parameters :format => [:json] RUBY + + app_file 'app/models/post.rb', <<-RUBY + class Post + def self.column_names + %w(title) + end + end + RUBY + + app_file 'app/controllers/posts_controller.rb', <<-RUBY + class PostsController < ApplicationController + def index + render :text => params[:post].inspect + end + end + RUBY + + add_to_config <<-RUBY + routes.append do + resources :posts + end + RUBY + require "#{app_path}/config/environment" - require 'action_controller/base' + require "rack/test" + extend Rack::Test::Methods - assert_equal [:json], ActionController::Base._wrapper_options[:format] + post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json" + assert_equal '{"title"=>"foo"}', last_response.body end test "config.action_dispatch.ignore_accept_header" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 01e6c49d9c..fd6dc46271 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -23,7 +23,8 @@ module ApplicationTests "Rack::Lock", "ActiveSupport::Cache::Strategy::LocalCache", "Rack::Runtime", - "Rails::Rack::Logger", + "Rack::MethodOverride", + "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods "ActionDispatch::ShowExceptions", "ActionDispatch::RemoteIp", "Rack::Sendfile", @@ -36,7 +37,6 @@ module ApplicationTests "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ParamsParser", - "Rack::MethodOverride", "ActionDispatch::Head", "Rack::ConditionalGet", "Rack::ETag", diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb new file mode 100644 index 0000000000..a29244357c --- /dev/null +++ b/railties/test/application/rack/logger_test.rb @@ -0,0 +1,40 @@ +require "isolation/abstract_unit" +require "active_support/log_subscriber/test_helper" +require "rack/test" + +module ApplicationTests + module RackTests + class LoggerTest < Test::Unit::TestCase + include ActiveSupport::LogSubscriber::TestHelper + include Rack::Test::Methods + + def setup + build_app + require "#{app_path}/config/environment" + super + end + + def logs + @logs ||= @logger.logged(:info) + end + + test "logger logs proper HTTP verb and path" do + get "/blah" + wait + assert_match /^Started GET "\/blah"/, logs[0] + end + + test "logger logs HTTP verb override" do + post "/", {:_method => 'put'} + wait + assert_match /^Started PUT "\/"/, logs[0] + end + + test "logger logs HEAD requests" do + post "/", {:_method => 'head'} + wait + assert_match /^Started HEAD "\/"/, logs[0] + end + end + end +end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 59e5ef4dee..d77c2d14ab 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -64,6 +64,28 @@ module ApplicationTests assert_match 'cart GET /cart(.:format)', Dir.chdir(app_path){ `rake routes` } end + def test_rake_routes_shows_custom_assets + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do + get '/custom/assets', :to => 'custom_assets#show' + end + RUBY + assert_match 'custom_assets GET /custom/assets(.:format)', Dir.chdir(app_path){ `rake routes` } + end + + def test_logger_is_flushed_when_exiting_production_rake_tasks + add_to_config <<-RUBY + rake_tasks do + task :log_something => :environment do + Rails.logger.error("Sample log message") + end + end + RUBY + + output = Dir.chdir(app_path){ `rake log_something RAILS_ENV=production && cat log/production.log` } + assert_match "Sample log message", output + end + def test_model_and_migration_generator_with_change_syntax Dir.chdir(app_path) do `rails generate model user username:string password:string` diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 62589c998d..e3a7f8a63c 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -1,14 +1,14 @@ require 'isolation/abstract_unit' +require 'rack/test' module ApplicationTests class RoutingTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def setup build_app boot_rails - require 'rack/test' - extend Rack::Test::Methods end test "rails/info/properties in development" do diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb index 1fbbb40132..f96319f472 100644 --- a/railties/test/application/test_test.rb +++ b/railties/test/application/test_test.rb @@ -65,6 +65,31 @@ module ApplicationTests run_test 'integration/posts_test.rb' end + test "performance test" do + controller 'posts', <<-RUBY + class PostsController < ActionController::Base + end + RUBY + + app_file 'app/views/posts/index.html.erb', <<-HTML + Posts#index + HTML + + app_file 'test/performance/posts_test.rb', <<-RUBY + require 'test_helper' + require 'rails/performance_test_help' + + class PostsTest < ActionDispatch::PerformanceTest + def test_index + get '/posts' + assert_response :success + end + end + RUBY + + run_test 'performance/posts_test.rb' + end + private def run_test(name) result = ruby '-Itest', "#{app_path}/test/#{name}" diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 81263a6ce9..cc0bd53639 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -39,6 +39,8 @@ DEFAULT_APP_FILES = %w( class AppGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments [destination_root] + + # brings setup, teardown, and some tests include SharedGeneratorTests def default_files @@ -135,6 +137,7 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator([destination_root, "-d", "jdbcmysql"]) assert_file "config/database.yml", /jdbcmysql/ assert_file "Gemfile", /^gem\s+["']activerecord-jdbcmysql-adapter["']$/ + assert_file "Gemfile", /^gem\s+["']jruby-openssl["']$/ if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6" end def test_config_jdbcsqlite3_database @@ -226,9 +229,13 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_test_unit_is_removed_from_frameworks_if_skip_test_unit_is_given run_generator [destination_root, "--skip-test-unit"] - assert_file "config/application.rb" do |file| - assert_match /config.generators.test_framework = false/, file - end + assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + end + + def test_no_active_record_or_test_unit_if_skips_given + run_generator [destination_root, "--skip-test-unit", "--skip-active-record"] + assert_file "config/application.rb", /#\s+require\s+["']rails\/test_unit\/railtie["']/ + assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end def test_new_hash_style diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 33c8d83f9c..f637a6a17e 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -22,6 +22,8 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper destination File.join(Rails.root, "tmp/bukkits") arguments [destination_root] + + # brings setup, teardown, and some tests include SharedGeneratorTests def default_files diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index c9c5d2fad2..03fd64ca38 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -1,3 +1,6 @@ +# +# Tests, setup, and teardown common to the application and plugin generator suites. +# module SharedGeneratorTests def setup Rails.application = TestApp::Application diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index e975950b85..e5debf29ae 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -15,11 +15,10 @@ module RailtiesTest boot_rails require 'rack/test' - require 'coffee_script' extend Rack::Test::Methods get "/assets/engine.js" - assert_match "alert();", last_response.body + assert_match "alert()", last_response.body end def test_copying_migrations |