Skip to content

Commit

Permalink
Improve best_standards_support to use only IE=Edge in development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Aug 9, 2010
1 parent 4f7565c commit 6767946
Show file tree
Hide file tree
Showing 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
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application.rb
Expand Up @@ -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

Expand Down
Expand Up @@ -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

96 changes: 65 additions & 31 deletions railties/test/application/routing_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6767946

Please sign in to comment.