diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/configuration_test.rb | 31 | ||||
-rw-r--r-- | railties/test/application/console_test.rb | 18 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 9 | ||||
-rw-r--r-- | railties/test/application/test_test.rb | 25 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 39 | ||||
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 2 |
6 files changed, 111 insertions, 13 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index ab3eb4c9e7..b1f7076776 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -432,5 +432,36 @@ module ApplicationTests get "/" assert_equal 'true', last_response.body end + + test "config.action_controller.wrap_parameters is set in ActionController::Base" do + app_file 'config/initializers/wrap_parameters.rb', <<-RUBY + ActionController::Base.wrap_parameters :format => [:json] + RUBY + require "#{app_path}/config/environment" + require 'action_controller/base' + + assert_equal [:json], ActionController::Base._wrapper_options[:format] + end + + test "config.action_dispatch.ignore_accept_header" do + make_basic_app do |app| + app.config.action_dispatch.ignore_accept_header = true + end + + class ::OmgController < ActionController::Base + def index + respond_to do |format| + format.html { render :text => "HTML" } + format.xml { render :text => "XML" } + end + end + end + + get "/", {}, "HTTP_ACCEPT" => "application/xml" + assert_equal 'HTML', last_response.body + + get "/", { :format => :xml }, "HTTP_ACCEPT" => "application/xml" + assert_equal 'XML', last_response.body + end end end diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 793e73556c..5ae6323345 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -8,9 +8,9 @@ class ConsoleTest < Test::Unit::TestCase boot_rails end - def load_environment + def load_environment(sandbox = false) require "#{rails_root}/config/environment" - Rails.application.load_console + Rails.application.load_console(sandbox) end def test_app_method_should_return_integration_session @@ -73,6 +73,20 @@ class ConsoleTest < Test::Unit::TestCase helper.truncate('Once upon a time in a world far far away') end + def test_with_sandbox + require 'rails/all' + value = false + + Class.new(Rails::Railtie) do + console do |sandbox| + value = sandbox + end + end + + load_environment(true) + assert value + end + def test_active_record_does_not_panic_when_referencing_an_observed_constant add_to_config "config.active_record.observers = :user_observer" diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 59e5ef4dee..a8bcf7beaf 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -64,6 +64,15 @@ 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_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/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 3cf92aed07..e271095636 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -135,6 +135,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 @@ -163,21 +164,41 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end - def test_jquery_and_test_unit_are_added_by_default + def test_creation_of_a_test_directory run_generator - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ - assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/jquery.js" - assert_file "vendor/assets/javascripts/jquery_ujs.js" - assert_file "test" + assert_file 'test' + end + + def test_jquery_is_the_default_javascript_library + run_generator + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ + assert_file "app/assets/javascripts/application.js" do |contents| + assert_match %r{^//= require jquery}, contents + assert_match %r{^//= require jquery_ujs}, contents + end + assert_file 'Gemfile' do |contents| + assert_match /^gem 'jquery-rails'/, contents + end + end + + def test_other_javascript_libraries + run_generator [destination_root, '-j', 'prototype'] + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ + assert_file "app/assets/javascripts/application.js" do |contents| + assert_match %r{^//= require prototype}, contents + assert_match %r{^//= require prototype_ujs}, contents + end + assert_file 'Gemfile' do |contents| + assert_match /^gem 'prototype-rails'/, contents + end end def test_javascript_is_skipped_if_required run_generator [destination_root, "--skip-javascript"] assert_file "config/application.rb", /^\s+# config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ - assert_file "app/assets/javascripts/application.js" - assert_no_file "vendor/assets/javascripts/jquery.js" - assert_no_file "vendor/assets/javascripts/jquery_ujs.js" + assert_file "app/assets/javascripts/application.js" do |contents| + assert_no_match %r{^//=\s+require\s}, contents + end end def test_template_from_dir_pwd diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index ae4fa6e596..33c8d83f9c 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -103,8 +103,6 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_javascripts_generation run_generator [destination_root, "--mountable"] assert_file "app/assets/javascripts/application.js" - assert_file "vendor/assets/javascripts/jquery.js" - assert_file "vendor/assets/javascripts/jquery_ujs.js" end def test_skip_javascripts |