Improve best_standards_support to use only IE=Edge in development mode

This commit is contained in:
wycats 2010-08-09 11:48:31 -07:00
parent 4f7565c4de
commit 6767946374
4 changed files with 81 additions and 34 deletions

@ -1,12 +1,21 @@
module ActionDispatch
class BestStandardsSupport
def initialize(app)
def initialize(app, type = true)
@app = app
@header = case type
when true
"IE=Edge,chrome=1"
when :builtin
"IE=Edge"
when false
nil
end
end
def call(env)
status, headers, body = @app.call(env)
headers["X-UA-Compatible"] = "IE=Edge,chrome=1"
headers["X-UA-Compatible"] = @header
[status, headers, body]
end
end

@ -205,7 +205,7 @@ def default_middleware_stack
middleware.use ::ActionDispatch::ParamsParser
middleware.use ::Rack::MethodOverride
middleware.use ::ActionDispatch::Head
middleware.use ::ActionDispatch::BestStandardsSupport if config.action_dispatch.best_standards_support
middleware.use ::ActionDispatch::BestStandardsSupport, config.action_dispatch.best_standards_support if config.action_dispatch.best_standards_support
end
end

@ -19,4 +19,8 @@
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
end

@ -11,19 +11,19 @@ def setup
extend Rack::Test::Methods
end
def app
def app(env = "production")
old_env = ENV["RAILS_ENV"]
@app ||= begin
ENV["RAILS_ENV"] = env
require "#{app_path}/config/environment"
Rails.application
end
ensure
ENV["RAILS_ENV"] = old_env
end
test "rails/info/properties" do
get "/rails/info/properties"
assert_equal 200, last_response.status
end
test "simple controller" do
def simple_controller
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
@ -37,12 +37,42 @@ def index
match ':controller(/:action)'
end
RUBY
end
test "rails/info/properties in development" do
app("development")
get "/rails/info/properties"
assert_equal 200, last_response.status
end
test "rails/info/properties in production" do
app("production")
get "/rails/info/properties"
assert_equal 404, last_response.status
end
test "simple controller" do
simple_controller
get '/foo'
assert_equal 'foo', last_response.body
end
test "simple controller in production mode returns best standards" do
simple_controller
get '/foo'
assert_equal "IE=Edge,chrome=1", last_response.headers["X-UA-Compatible"]
end
test "simple controller in development mode leaves out Chrome" do
simple_controller
app("development")
get "/foo"
assert_equal "IE=Edge", last_response.headers["X-UA-Compatible"]
end
test "simple controller with helper" do
controller :foo, <<-RUBY
class FooController < ApplicationController
@ -147,38 +177,42 @@ def index
assert_equal 'admin::foo', last_response.body
end
test "reloads routes when configuration is changed" do
controller :foo, <<-RUBY
class FooController < ApplicationController
def bar
render :text => "bar"
{"development" => "baz", "production" => "bar"}.each do |mode, expected|
test "reloads routes when configuration is changed in #{mode}" do
controller :foo, <<-RUBY
class FooController < ApplicationController
def bar
render :text => "bar"
end
def baz
render :text => "baz"
end
end
RUBY
def baz
render :text => "baz"
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#bar'
end
end
RUBY
RUBY
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#bar'
end
RUBY
app(mode)
get '/foo'
assert_equal 'bar', last_response.body
get '/foo'
assert_equal 'bar', last_response.body
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#baz'
end
RUBY
app_file 'config/routes.rb', <<-RUBY
AppTemplate::Application.routes.draw do |map|
match 'foo', :to => 'foo#baz'
end
RUBY
sleep 0.1
sleep 0.1
get '/foo'
assert_equal 'baz', last_response.body
get '/foo'
assert_equal expected, last_response.body
end
end
test 'resource routing with irrigular inflection' do