Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Unit test showing escape_javascript is being called on request.url
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jan 27, 2011
1 parent ca1f4bd commit 1cb5267
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/templates/javascript_notifier.erb
Expand Up @@ -2,12 +2,12 @@
var notifierJsScheme = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + notifierJsScheme + "#{host}/javascripts/notifier.js' type='text/javascript'%3E%3C/script%3E"));
}
-%>
%>
<%= javascript_tag %Q{
Hoptoad.setKey('#{api_key}');
Hoptoad.setHost('#{host}');
Hoptoad.setEnvironment('#{environment}');
Hoptoad.setErrorDefaults({ url: "#{escape_javascript url}", component: "#{controller_name}", action: "#{action_name}" });
}
-%>
%>
52 changes: 52 additions & 0 deletions test/javascript_notifier_test.rb
@@ -0,0 +1,52 @@
require File.dirname(__FILE__) + '/helper'
require 'hoptoad_notifier/rails/javascript_notifier'
require 'ostruct'

class JavascriptNotifierTest < Test::Unit::TestCase
module FakeRenderer
def javascript_tag(text)
"<script>#{text}</script>"
end
def escape_javascript(text)
"ESC#{text}ESC"
end
end

class FakeController
def self.helper_method(*args)
end

include HoptoadNotifier::Rails::JavascriptNotifier

def action_name
"action"
end

def controller_name
"controller"
end

def request
@request ||= OpenStruct.new
end

def render_to_string(options)
context = OpenStruct.new(options[:locals])
context.extend(FakeRenderer)
context.instance_eval do
erb = ERB.new(IO.read(options[:file]))
erb.result(binding)
end
end
end

should "make sure escape_javacript is called on the request.url" do
HoptoadNotifier.configure do
end
controller = FakeController.new
controller.request.url = "bad_javascript"
assert controller.send(:hoptoad_javascript_notifier)['"ESCbad_javascriptESC"']
assert ! controller.send(:hoptoad_javascript_notifier)['"bad_javascript"']
end
end

0 comments on commit 1cb5267

Please sign in to comment.