aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application')
-rw-r--r--railties/test/application/configuration_test.rb69
-rw-r--r--railties/test/application/console_test.rb18
-rw-r--r--railties/test/application/rake_test.rb22
-rw-r--r--railties/test/application/test_test.rb25
4 files changed, 131 insertions, 3 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 62697b1bf9..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
@@ -258,6 +257,18 @@ module ApplicationTests
assert_equal res, last_response.body # value should be unchanged
end
+ test "sets all Active Record models to whitelist all attributes by default" do
+ add_to_config <<-RUBY
+ config.active_record.whitelist_attributes = true
+ RUBY
+
+ require "#{app_path}/config/environment"
+
+ assert_equal ActiveModel::MassAssignmentSecurity::WhiteList,
+ ActiveRecord::Base.active_authorizers[:default].class
+ assert_equal [""], ActiveRecord::Base.active_authorizers[:default].to_a
+ end
+
test "registers interceptors with ActionMailer" do
add_to_config <<-RUBY
config.action_mailer.interceptors = MyMailInterceptor
@@ -420,5 +431,61 @@ 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
+
+ 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 "rack/test"
+ extend Rack::Test::Methods
+
+ 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
+ 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..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/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}"