Skip to content

Commit

Permalink
Merge branch '3-1-0' into 3-1-stable
Browse files Browse the repository at this point in the history
* 3-1-0:
  Configuration changes for asset pipeline: remove config.assets.allow_debugging, add config.assets.compile and config.assets.digest
  Read digests of assets from manifest.yml if config.assets.manifest is on
  let SDoc add a link to the source code in GitHub for each method
  Documentation fixes
  bumping to 3.1.0.rc8
  bumping to 3.1.0.rc7
  Update Rails 3.1 CHANGELOGs
  Bump rack-cache, rack-test, rack-mount and sprockets up
  clear and disable query cache when an exception is raised from called middleware
  assert_no_match
  deletes spurious arrow
  use sdoc to generate the API
  Don't modify params in place - fixes #2624
  the command line guide is good to go
  `load` should also return the value from `super`
  require needs to return true or false. thank you Ryan "zenspider" Davis
  bumping bcrypt-ruby requirement
  Make ActionController::TestCase#recycle! set @protocol to nil
  Add failing test case for #2654

Conflicts:
	activerecord/test/cases/query_cache_test.rb
  • Loading branch information
tenderlove committed Aug 30, 2011
2 parents c96788a + 94e3059 commit 602a3c2
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 36 deletions.
2 changes: 1 addition & 1 deletion RAILS_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0.rc6
3.1.0.rc8
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_pack/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
8 changes: 7 additions & 1 deletion actionpack/lib/sprockets/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace :assets do

config = Rails.application.config
env = Rails.application.assets
target = Rails.root.join("public#{config.assets.prefix}")
target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
manifest = {}

if env.respond_to?(:each_logical_path)
config.assets.precompile.each do |path|
Expand All @@ -30,6 +31,7 @@ namespace :assets do
end

if asset = env.find_asset(logical_path)
manifest[logical_path] = asset.digest_path
filename = target.join(asset.digest_path)
mkdir_p filename.dirname
asset.write_to(filename)
Expand All @@ -43,6 +45,10 @@ namespace :assets do
assets << {:to => target}
env.precompile(*assets)
end

File.open("#{target}/manifest.yml", 'w') do |f|
YAML.dump(manifest, f)
end
end
end

Expand Down
31 changes: 20 additions & 11 deletions actionpack/lib/sprockets/helpers/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def asset_paths
paths = RailsHelper::AssetPaths.new(config, controller)
paths.asset_environment = asset_environment
paths.asset_prefix = asset_prefix
paths.asset_digests = asset_digests
paths
end
end
Expand Down Expand Up @@ -58,7 +59,7 @@ def asset_path(source, default_ext = nil, body = false, protocol = nil)

private
def debug_assets?
Rails.application.config.assets.allow_debugging &&
Rails.application.config.assets.compile &&
(Rails.application.config.assets.debug ||
params[:debug_assets] == '1' ||
params[:debug_assets] == 'true')
Expand All @@ -74,6 +75,10 @@ def asset_prefix
Rails.application.config.assets.prefix
end

def asset_digests
Rails.application.config.assets.digests
end

# Override to specify an alternative asset environment for asset
# path generation. The environment should already have been mounted
# at the prefix returned by +asset_prefix+.
Expand All @@ -82,7 +87,9 @@ def asset_environment
end

class AssetPaths < ::ActionView::AssetPaths #:nodoc:
attr_accessor :asset_environment, :asset_prefix
attr_accessor :asset_environment, :asset_prefix, :asset_digests

class AssetNotPrecompiledError < StandardError; end

def compute_public_path(source, dir, ext=nil, include_host=true, protocol=nil)
super(source, asset_prefix, ext, include_host, protocol)
Expand All @@ -101,18 +108,25 @@ def asset_for(source, ext)
end

def digest_for(logical_path)
if asset = asset_environment[logical_path]
return asset.digest_path
if asset_digests && (digest = asset_digests[logical_path])
return digest
end

logical_path
if Rails.application.config.assets.compile
if asset = asset_environment[logical_path]
return asset.digest_path
end
return logical_path
else
raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")
end
end

def rewrite_asset_path(source, dir)
if source[0] == ?/
source
else
source = digest_for(source) if performing_caching?
source = digest_for(source) if Rails.application.config.assets.digest
source = File.join(dir, source)
source = "/#{source}" unless source =~ /^\//
source
Expand All @@ -126,11 +140,6 @@ def rewrite_extension(source, dir, ext)
source
end
end

# When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
def performing_caching?
config.action_controller.present? ? config.action_controller.perform_caching : config.perform_caching
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions actionpack/lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Railtie < ::Rails::Railtie
end
end

if File.exist?(path = File.join(Rails.public_path, config.assets.prefix, "manifest.yml"))
config.assets.digests = YAML.load_file(path)
end

ActiveSupport.on_load(:action_view) do
include ::Sprockets::Helpers::RailsHelper

Expand Down
6 changes: 4 additions & 2 deletions actionpack/test/template/sprockets_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def host_with_port() 'localhost' end
@config = config
@config.action_controller ||= ActiveSupport::InheritableOptions.new
@config.perform_caching = true
@config.assets.digest = true
@config.assets.compile = true
end

def url_for(*args)
Expand Down Expand Up @@ -160,7 +162,7 @@ def url_for(*args)
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application, :debug => true)

@config.assets.allow_debugging = true
@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<script src="/assets/xmlhr-[0-9a-f]+.js\?body=1" type="text/javascript"></script>\n<script src="/assets/application-[0-9a-f]+.js\?body=1" type="text/javascript"></script>},
javascript_include_tag(:application)
Expand Down Expand Up @@ -201,7 +203,7 @@ def url_for(*args)
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application, :debug => true)

@config.assets.allow_debugging = true
@config.assets.compile = true
@config.assets.debug = true
assert_match %r{<link href="/assets/style-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />\n<link href="/assets/application-[0-9a-f]+.css\?body=1" media="screen" rel="stylesheet" type="text/css" />},
stylesheet_link_tag(:application)
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
2 changes: 1 addition & 1 deletion activeresource/lib/active_resource/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
10 changes: 5 additions & 5 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def initialize(*)
@assets.prefix = "/assets"
@assets.version = ''
@assets.debug = false
@assets.allow_debugging = false

@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
@assets.compile = true
@assets.digest = false
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
end

def compiled_asset_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# Do not compress assets
config.assets.compress = false

# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true

# Expands the lines which load the assets
config.assets.debug = true
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
78 changes: 73 additions & 5 deletions railties/test/application/assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def app

test "assets do not require compressors until it is used" do
app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();"
app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"

ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"

Expand All @@ -62,8 +64,70 @@ def app
end
end

test "precompile creates a manifest file with all the assets listed" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
app_file "app/assets/javascripts/application.js", "alert();"

capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end

manifest = "#{app_path}/public/assets/manifest.yml"

assets = YAML.load_file(manifest)
assert_match /application-([0-z]+)\.js/, assets["application.js"]
assert_match /application-([0-z]+)\.css/, assets["application.css"]
end

test "assets do not require any assets group gem when manifest file is present" do
app_file "app/assets/javascripts/application.js", "alert();"

ENV["RAILS_ENV"] = "production"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end
manifest = "#{app_path}/public/assets/manifest.yml"
assets = YAML.load_file(manifest)
asset_path = assets["application.js"]

require "#{app_path}/config/environment"

# Checking if Uglifier is defined we can know if Sprockets was reached or not
assert !defined?(Uglifier)
get "/assets/#{asset_path}"
assert_match "alert()", last_response.body
assert !defined?(Uglifier)
end

test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled" do
app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"

app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
match '/posts', :to => "posts#index"
end
RUBY

ENV["RAILS_ENV"] = "production"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end

# Create file after of precompile
app_file "app/assets/javascripts/app.js", "alert();"

require "#{app_path}/config/environment"
class ::PostsController < ActionController::Base ; end

get '/posts'
assert_match /AssetNotPrecompiledError/, last_response.body
assert_match /app.js isn't precompiled/, last_response.body
end

test "precompile appends the md5 hash to files referenced with asset_path and run in the provided RAILS_ENV" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
# digest is default in false, we must enable it for test environment
app_file "config/initializers/compile.rb", "Rails.application.config.assets.digest = true"

# capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_ENV=test` }
Expand All @@ -74,6 +138,7 @@ def app

test "precompile appends the md5 hash to files referenced with asset_path and run in production as default even using RAILS_GROUPS=assets" do
app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"

ENV["RAILS_ENV"] = nil
capture(:stdout) do
Expand Down Expand Up @@ -136,24 +201,27 @@ def index
assert_equal 200, last_response.status
end

test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do
test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do
app_with_assets_in_view

# config.assets.debug and config.assets.allow_debugging are false for production environment
# config.assets.debug and config.assets.compile are false for production environment
ENV["RAILS_ENV"] = "production"
capture(:stdout) do
Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
end
require "#{app_path}/config/environment"

class ::PostsController < ActionController::Base ; end

# the debug_assets params isn't used if allow_debugging is off
# the debug_assets params isn't used if compile is off
get '/posts?debug_assets=true'
assert_match /<script src="\/assets\/application-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body
assert_no_match /<script src="\/assets\/xmlhr-([0-z]+)\.js" type="text\/javascript"><\/script>/, last_response.body
end

test "assets aren't concatened when allow_debugging is on and debug_assets params is true" do
test "assets aren't concatened when compile is true is on and debug_assets params is true" do
app_with_assets_in_view
app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true"
app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"

ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
Expand Down
2 changes: 1 addition & 1 deletion version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module VERSION #:nodoc:
MAJOR = 3
MINOR = 1
TINY = 0
PRE = "rc6"
PRE = "rc8"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down

0 comments on commit 602a3c2

Please sign in to comment.