Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix #3259

  • Loading branch information...
commit fcf7714c53c7ffbb92789c19e3e1c6391ffe33c3 1 parent 9bdf060
@kennyj authored
View
6 actionpack/lib/sprockets/assets.rake
@@ -4,7 +4,8 @@ namespace :assets do
def ruby_rake_task(task)
env = ENV['RAILS_ENV'] || 'production'
groups = ENV['RAILS_GROUPS'] || 'assets'
- args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"]
+ relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT'] || ''
+ args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}","RAILS_RELATIVE_URL_ROOT=#{relative_url_root}"]
args << "--trace" if Rake.application.options.trace
ruby(*args)
end
@@ -13,7 +14,7 @@ namespace :assets do
# and/or no explicit environment - we have to reinvoke rake to
# execute this task.
def invoke_or_reboot_rake_task(task)
- if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty?
+ if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty? || ENV['RAILS_RELATIVE_URL_ROOT'].to_s.empty?
ruby_rake_task task
else
Rake::Task[task].invoke
@@ -40,6 +41,7 @@ namespace :assets do
config.assets.compile = true
config.assets.digest = digest unless digest.nil?
config.assets.digests = {}
+ config.action_controller.relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
env = Rails.application.assets
target = File.join(Rails.public_path, config.assets.prefix)
View
20 railties/test/application/assets_test.rb
@@ -288,6 +288,26 @@ class ::PostsController < ActionController::Base ; end
assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
end
+ test "precompile prepends relative url root if RAILS_RELATIVE_URL_ROOT is specified" do
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile RAILS_RELATIVE_URL_ROOT=/foo` }
+ end
+ file = Dir["#{app_path}/public/assets/application.css"].first
+ assert_match(/\/foo\/assets\/rails\.png/, File.read(file))
+ end
+
+ test "precompile don't prepends relative url root if RAILS_RELATIVE_URL_ROOT isn't specified" do
+ app_file "app/assets/stylesheets/application.css.erb", "<%= asset_path('rails.png') %>"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:precompile` }
+ end
+ file = Dir["#{app_path}/public/assets/application.css"].first
+ assert_match(/[^\/]\/assets\/rails\.png/, File.read(file))
+ end
+
test "precompile should handle utf8 filenames" do
filename = "レイルズ.png"
app_file "app/assets/images/#{filename}", "not a image really"
Please sign in to comment.
Something went wrong with that request. Please try again.