Namespace
Methods
A
C
P
S
T
Included Modules
Instance Public methods
assert_file_exists(filename)
# File railties/test/application/assets_test.rb, line 34
def assert_file_exists(filename)
  assert Dir[filename].first, "missing #{filename}"
end
assert_no_file_exists(filename)
# File railties/test/application/assets_test.rb, line 38
def assert_no_file_exists(filename)
  assert !File.exist?(filename), "#{filename} does exist"
end
clean_assets!()
# File railties/test/application/assets_test.rb, line 28
def clean_assets!
  quietly do
    assert Dir.chdir(app_path) { system('bundle exec rake assets:clobber') }
  end
end
precompile!(env = nil)
# File railties/test/application/assets_test.rb, line 19
def precompile!(env = nil)
  quietly do
    precompile_task = "bundle exec rake assets:precompile #{env} --trace 2>&1"
    output = Dir.chdir(app_path) { %x[ #{precompile_task} ] }
    assert $?.success?, output
    output
  end
end
setup()
# File railties/test/application/assets_test.rb, line 10
def setup
  build_app(initializers: true)
  boot_rails
end
teardown()
# File railties/test/application/assets_test.rb, line 15
def teardown
  teardown_app
end
test_precompile_does_not_hit_the_database()
# File railties/test/application/assets_test.rb, line 88
def test_precompile_does_not_hit_the_database
  app_file "app/assets/javascripts/application.js", "alert();"
  app_file "app/assets/javascripts/foo/application.js", "alert();"
  app_file "app/controllers/users_controller.rb", <<-eoruby
    class UsersController < ApplicationController; end
  eoruby
  app_file "app/models/user.rb", <<-eoruby
    class User < ActiveRecord::Base; raise 'should not be reached'; end
  eoruby

  ENV['RAILS_ENV']  = 'production'
  ENV['DATABASE_URL'] = 'postgresql://baduser:badpass@127.0.0.1/dbname'

  precompile!

  files = Dir["#{app_path}/public/assets/application-*.js"]
  files << Dir["#{app_path}/public/assets/foo/application-*.js"].first
  files.each do |file|
    assert_not_nil file, "Expected application.js asset to be generated, but none found"
    assert_equal "alert();".strip, File.read(file).strip
  end
ensure
  ENV.delete 'RAILS_ENV'
  ENV.delete 'DATABASE_URL'
end