Skip to content

Commit

Permalink
Move asset tests to assets_test file
Browse files Browse the repository at this point in the history
  • Loading branch information
guilleiguaran committed Sep 13, 2011
1 parent f1c3903 commit e767cda
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
31 changes: 31 additions & 0 deletions railties/test/application/assets_test.rb
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
require 'isolation/abstract_unit'
require 'active_support/core_ext/kernel/reporting'
require 'rack/test'
Expand Down Expand Up @@ -268,6 +269,36 @@ class ::PostsController < ActionController::Base ; end
assert_match(/\/assets\/rails-([0-z]+)\.png/, File.read(file))
end

test "precompile ignore asset_host" do
app_file "app/assets/javascripts/application.css.erb", "<%= asset_path 'rails.png' %>"
add_to_config "config.action_controller.asset_host = Proc.new { |source, request| 'http://www.example.com/' }"

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

file = Dir["#{app_path}/public/assets/application.css"].first
content = File.read(file)
assert_match(/\/assets\/rails-([0-z]+)\.png/, content)
assert_no_match(/www\.example\.com/, content)
end

test "precompile should handle utf8 filenames" do
app_file "app/assets/images/レイルズ.png", "not a image really"
add_to_config "config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]"

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

assert File.exists?("#{app_path}/public/assets/レイルズ.png")

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

assets = YAML.load_file(manifest)
assert_equal "レイルズ.png", assets["レイルズ.png"]
end

test "assets are cleaned up properly" do
app_file "public/assets/application.js", "alert();"
app_file "public/assets/application.css", "a { color: green; }"
Expand Down
31 changes: 0 additions & 31 deletions railties/test/application/rake_test.rb
Expand Up @@ -201,36 +201,5 @@ def test_scaffold_tests_pass_by_default

assert_match(/7 tests, 10 assertions, 0 failures, 0 errors/, content)
end

def test_assets_precompile_with_utf8_filename
add_to_config <<-RUBY
config.assets.precompile = [ /\.png$$/, /application.(css|js)$/ ]
RUBY

Dir.chdir(app_path) do
`cp app/assets/images/rails.png app/assets/images/レイルズ.png`
`rake assets:precompile`
open("public/assets/manifest.yml") do |f|
assert_match(/レイルズ.png/, f.read)
end
end
end

def test_assets_precompile_ignore_asset_host
add_to_config <<-RUBY
config.action_controller.asset_host = Proc.new { |source, request| "http://www.example.com/" }
RUBY

app_file "app/assets/javascripts/test.js.erb", <<-RUBY
alert("<%= asset_path "rails.png" %>");
RUBY

Dir.chdir(app_path) do
`rake assets:precompile`
open("public/assets/application.js") do |f|
assert_match(/\"\/assets\/rails.png\"/, f.read)
end
end
end
end
end

0 comments on commit e767cda

Please sign in to comment.