Sha256: 52a695c8926f446d6a673aa72ab4568cc259dacabdbcdb091ed566914247691e

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

require File.dirname(__FILE__) + '/helper'
require 'airbrake/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 Airbrake::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
    Airbrake.configure do
    end
    controller = FakeController.new
    controller.request.url = "bad_javascript"
    assert controller.send(:airbrake_javascript_notifier)['"ESCbad_javascriptESC"']
    assert ! controller.send(:airbrake_javascript_notifier)['"bad_javascript"']
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
airbrake-3.1.2 test/javascript_notifier_test.rb
airbrake-3.1.1 test/javascript_notifier_test.rb
airbrake-3.1.0 test/javascript_notifier_test.rb
airbrake-3.0.9 test/javascript_notifier_test.rb
airbrake-3.0.8 test/javascript_notifier_test.rb
airbrake-3.0.7 test/javascript_notifier_test.rb
airbrake-3.0.6 test/javascript_notifier_test.rb
airbrake-3.0.5 test/javascript_notifier_test.rb
airbrake-3.0.4 test/javascript_notifier_test.rb
airbrake-3.0.3 test/javascript_notifier_test.rb
airbrake-3.0.2 test/javascript_notifier_test.rb
airbrake-3.0.1 test/javascript_notifier_test.rb
airbrake-3.0 test/javascript_notifier_test.rb
airbrake-3.0.rc2 test/javascript_notifier_test.rb
airbrake-3.0.rc1 test/javascript_notifier_test.rb