class ApplicationTests::AssetsTest
Public Instance Methods
assert_file_exists(filename)
click to toggle source
# File railties/test/application/assets_test.rb, line 44 def assert_file_exists(filename) globbed = Dir[filename] assert globbed.one?, "Found #{globbed.size} files matching #{filename}. All files in the directory: #{Dir.entries(File.dirname(filename)).inspect}" end
assert_no_file_exists(filename)
click to toggle source
# File railties/test/application/assets_test.rb, line 49 def assert_no_file_exists(filename) assert !File.exist?(filename), "#{filename} does exist" end
clean_assets!()
click to toggle source
# File railties/test/application/assets_test.rb, line 38 def clean_assets! quietly do assert Dir.chdir(app_path) { system("bin/quails assets:clobber") } end end
precompile!(env = nil)
click to toggle source
# File railties/test/application/assets_test.rb, line 20 def precompile!(env = nil) with_env env.to_h do quietly do precompile_task = "bin/quails assets:precompile --trace 2>&1" output = Dir.chdir(app_path) { %x[ #{precompile_task} ] } assert $?.success?, output output end end end
setup()
click to toggle source
# File railties/test/application/assets_test.rb, line 12 def setup build_app(initializers: true) end
teardown()
click to toggle source
# File railties/test/application/assets_test.rb, line 16 def teardown teardown_app end
test_precompile_does_not_hit_the_database()
click to toggle source
# File railties/test/application/assets_test.rb, line 103 def test_precompile_does_not_hit_the_database app_file "app/assets/config/manifest.js", "//= link_tree ../javascripts" 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 precompile! \ RAILS_ENV: "production", DATABASE_URL: "postgresql://baduser:badpass@127.0.0.1/dbname" 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 end
with_env(env) { || ... }
click to toggle source
# File railties/test/application/assets_test.rb, line 31 def with_env(env) env.each { |k, v| ENV[k.to_s] = v } yield ensure env.each_key { |k| ENV.delete k.to_s } end
Private Instance Methods
app_with_assets_in_view()
click to toggle source
# File railties/test/application/assets_test.rb, line 512 def app_with_assets_in_view 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 Quails.application.routes.draw do get '/posts', :to => "posts#index" end RUBY end