2011-08-25 05:40:10 -04:00
|
|
|
require 'isolation/abstract_unit'
|
|
|
|
require 'rack/test'
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class AssetDebuggingTest < Test::Unit::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app(:initializers => true)
|
|
|
|
|
|
|
|
app_file "app/assets/javascripts/application.js", "//= require_tree ."
|
|
|
|
app_file "app/assets/javascripts/xmlhr.js", "function f1() { alert(); }"
|
|
|
|
app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'application' %>"
|
|
|
|
|
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
AppTemplate::Application.routes.draw do
|
|
|
|
match '/posts', :to => "posts#index"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
app_file "app/controllers/posts_controller.rb", <<-RUBY
|
|
|
|
class PostsController < ActionController::Base
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
ENV["RAILS_ENV"] = "production"
|
|
|
|
|
|
|
|
boot_rails
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2011-08-31 14:09:35 -04:00
|
|
|
test "assets are concatenated when debug is off and compile is off either if debug_assets param is provided" do
|
|
|
|
# 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
|
2011-08-25 05:40:10 -04:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
|
2011-08-31 14:09:35 -04:00
|
|
|
class ::PostsController < ActionController::Base ; end
|
|
|
|
|
|
|
|
# the debug_assets params isn't used if compile is off
|
2011-08-25 05:40:10 -04:00
|
|
|
get '/posts?debug_assets=true'
|
2011-09-03 22:53:13 -04:00
|
|
|
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)
|
2011-08-25 05:40:10 -04:00
|
|
|
end
|
|
|
|
|
2011-08-31 14:09:35 -04:00
|
|
|
test "assets aren't concatened when compile is true is on and debug_assets params is true" do
|
|
|
|
app_file "config/initializers/compile.rb", "Rails.application.config.assets.compile = true"
|
2011-08-25 05:40:10 -04:00
|
|
|
|
2011-08-31 14:09:35 -04:00
|
|
|
ENV["RAILS_ENV"] = "production"
|
2011-08-25 05:40:10 -04:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
|
2011-08-31 14:09:35 -04:00
|
|
|
class ::PostsController < ActionController::Base ; end
|
|
|
|
|
2011-08-25 05:40:10 -04:00
|
|
|
get '/posts?debug_assets=true'
|
2011-09-03 22:53:13 -04:00
|
|
|
assert_match(/<script src="\/assets\/application-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
|
|
|
assert_match(/<script src="\/assets\/xmlhr-([0-z]+)\.js\?body=1" type="text\/javascript"><\/script>/, last_response.body)
|
2011-08-25 05:40:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|