aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/asset_debugging_test.rb
blob: 38e1e21d17931a8e817a918db6f1500a5fffe06e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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

    test "assets are concatenated when debug is off and allow_debugging is off either if debug_assets param is provided" do
      # config.assets.debug and config.assets.allow_debugging are false for production environment
      require "#{app_path}/config/environment"

      # the debug_assets params isn't used if allow_debugging is off
      get '/posts?debug_assets=true'
      assert_match %r{<script src="/assets/application-([0-z]+)\.js" type="text/javascript"></script>}, last_response.body
      assert_no_match %r{<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
      app_file "config/initializers/allow_debugging.rb", "Rails.application.config.assets.allow_debugging = true"

      require "#{app_path}/config/environment"

      get '/posts?debug_assets=true'
      assert_match %r{<script src="/assets/application-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body
      assert_match %r{<script src="/assets/xmlhr-([0-z]+)\.js\?body=1" type="text/javascript"></script>}, last_response.body
    end
  end
end