diff options
Diffstat (limited to 'railties/test/application/configuration_test.rb')
-rw-r--r-- | railties/test/application/configuration_test.rb | 113 |
1 files changed, 95 insertions, 18 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 97ad47ac14..252dd0e31a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,4 +1,5 @@ require "isolation/abstract_unit" +require 'rack/test' class ::MyMailInterceptor def self.delivering_email(email); email; end @@ -13,8 +14,9 @@ end class ::MyOtherMailObserver < ::MyMailObserver; end module ApplicationTests - class ConfigurationTest < Test::Unit::TestCase + class ConfigurationTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def new_app File.expand_path("#{app_path}/../new_app") @@ -39,6 +41,14 @@ module ApplicationTests FileUtils.rm_rf(new_app) if File.directory?(new_app) end + test "multiple queue construction is possible" do + require 'rails' + require "#{app_path}/config/environment" + mail_queue = Rails.application.build_queue + image_processing_queue = Rails.application.build_queue + assert_not_equal mail_queue, image_processing_queue + end + test "Rails.groups returns available groups" do require "rails" @@ -144,7 +154,7 @@ module ApplicationTests test "frameworks are not preloaded by default" do require "#{app_path}/config/environment" - assert ActionController.autoload?(:RecordIdentifier) + assert ActionController.autoload?(:Caching) end test "frameworks are preloaded with config.preload_frameworks is set" do @@ -154,7 +164,7 @@ module ApplicationTests require "#{app_path}/config/environment" - assert !ActionController.autoload?(:RecordIdentifier) + assert !ActionController.autoload?(:Caching) end test "filter_parameters should be able to set via config.filter_parameters" do @@ -181,20 +191,14 @@ module ApplicationTests assert !$prepared require "#{app_path}/config/environment" - require 'rack/test' - extend Rack::Test::Methods get "/" assert $prepared end def assert_utf8 - if RUBY_VERSION < '1.9' - assert_equal "UTF8", $KCODE - else - assert_equal Encoding::UTF_8, Encoding.default_external - assert_equal Encoding::UTF_8, Encoding.default_internal - end + assert_equal Encoding::UTF_8, Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_internal end test "skipping config.encoding still results in 'utf-8' as the default" do @@ -250,6 +254,55 @@ module ApplicationTests assert last_response.body =~ /csrf\-param/ end + test "default method for update can be changed" do + app_file 'app/models/post.rb', <<-RUBY + class Post + extend ActiveModel::Naming + def to_key; [1]; end + def persisted?; true; end + end + RUBY + + app_file 'app/controllers/posts_controller.rb', <<-RUBY + class PostsController < ApplicationController + def show + render :inline => "<%= begin; form_for(Post.new) {}; rescue => e; e.to_s; end %>" + end + + def update + render :text => "update" + end + end + RUBY + + add_to_config <<-RUBY + routes.prepend do + resources :posts + end + RUBY + + require "#{app_path}/config/environment" + + token = "cf50faa3fe97702ca1ae" + PostsController.any_instance.stubs(:form_authenticity_token).returns(token) + params = {:authenticity_token => token} + + get "/posts/1" + assert_match /patch/, last_response.body + + patch "/posts/1", params + assert_match /update/, last_response.body + + patch "/posts/1", params + assert_equal 200, last_response.status + + put "/posts/1", params + assert_match /update/, last_response.body + + put "/posts/1", params + assert_equal 200, last_response.status + end + test "request forgery token param can be changed" do make_basic_app do app.config.action_controller.request_forgery_protection_token = '_xsrf_token_here' @@ -286,6 +339,19 @@ module ApplicationTests assert_equal res, last_response.body # value should be unchanged end + test "sets ActionDispatch.test_app" do + make_basic_app + assert_equal Rails.application, ActionDispatch.test_app + end + + test "sets ActionDispatch::Response.default_charset" do + make_basic_app do |app| + app.config.action_dispatch.default_charset = "utf-16" + end + + assert_equal "utf-16", ActionDispatch::Response.default_charset + end + test "sets all Active Record models to whitelist all attributes by default" do add_to_config <<-RUBY config.active_record.whitelist_attributes = true @@ -474,23 +540,27 @@ module ApplicationTests end RUBY + app_file 'app/controllers/application_controller.rb', <<-RUBY + class ApplicationController < ActionController::Base + protect_from_forgery :with => :reset_session # as we are testing API here + end + RUBY + app_file 'app/controllers/posts_controller.rb', <<-RUBY class PostsController < ApplicationController - def index + def create render :text => params[:post].inspect end end RUBY add_to_config <<-RUBY - routes.append do + routes.prepend do resources :posts end RUBY require "#{app_path}/config/environment" - require "rack/test" - extend Rack::Test::Methods post "/posts.json", '{ "title": "foo", "name": "bar" }', "CONTENT_TYPE" => "application/json" assert_equal '{"title"=>"foo"}', last_response.body @@ -521,9 +591,16 @@ module ApplicationTests make_basic_app assert_respond_to app, :env_config - assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters - assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token - assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions + assert_equal app.env_config['action_dispatch.parameter_filter'], app.config.filter_parameters + assert_equal app.env_config['action_dispatch.secret_token'], app.config.secret_token + assert_equal app.env_config['action_dispatch.show_exceptions'], app.config.action_dispatch.show_exceptions + assert_equal app.env_config['action_dispatch.logger'], Rails.logger + assert_equal app.env_config['action_dispatch.backtrace_cleaner'], Rails.backtrace_cleaner + end + + test "config.colorize_logging default is true" do + make_basic_app + assert app.config.colorize_logging end end end |