Created
October 24, 2012 14:51
-
-
Save mjtko/3946516 to your computer and use it in GitHub Desktop.
Monkey patch for denying TTF files to PhantomJS under test env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/sprockets-server-monkeypatch-deny_phantomjs_ttf.rb | |
# Monkey patch under test environment that prevents PhantomJS on OSX | |
# from crashing when dealing with TTF webfonts. | |
# Note: depending on your setup, it's likely that the RUBY_PLATFORM | |
# is not actually relevant for server - it's the UA that crashes. | |
if Rails.env.test? # && RUBY_PLATFORM =~ /darwin/ | |
module Sprockets::Server | |
def call_with_env_instance_var(env) | |
@env = env | |
call_without_env_instance_var(env) | |
end | |
alias_method_chain :call, :env_instance_var | |
def forbidden_request?(path) | |
if @env['HTTP_USER_AGENT'] =~ /Intel Mac OS X.*PhantomJS/ && path =~ /ttf$/ | |
STDERR.puts "Denying #{path} to #{@env['HTTP_USER_AGENT']}" | |
true | |
else | |
path.include?("..") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment